@core-pilot/client-vue 0.0.10 → 0.0.11
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/dist/cjs/client-vue.css +1 -1
- package/dist/cjs/components/x-markdown/composables/useFormHandler.js +2 -0
- package/dist/cjs/components/x-markdown/composables/useFormHandler.js.map +1 -0
- package/dist/cjs/components/x-markdown/composables/useImageLoader.js +2 -0
- package/dist/cjs/components/x-markdown/composables/useImageLoader.js.map +1 -0
- package/dist/cjs/components/x-markdown/composables/useMarkdownProcessor.js +2 -0
- package/dist/cjs/components/x-markdown/composables/useMarkdownProcessor.js.map +1 -0
- package/dist/cjs/components/x-markdown/composables/useRefHandler.js +2 -0
- package/dist/cjs/components/x-markdown/composables/useRefHandler.js.map +1 -0
- package/dist/cjs/components/x-markdown/composables/useStreamHandler.js +2 -0
- package/dist/cjs/components/x-markdown/composables/useStreamHandler.js.map +1 -0
- package/dist/cjs/components/x-markdown/index.js +1 -1
- package/dist/cjs/components/x-markdown/index.js.map +1 -1
- package/dist/cjs/components/x-markdown/renderers/hastRenderer.js +2 -0
- package/dist/cjs/components/x-markdown/renderers/hastRenderer.js.map +1 -0
- package/dist/cjs/components/x-markdown/utils/disabledUtils.js +2 -0
- package/dist/cjs/components/x-markdown/utils/disabledUtils.js.map +1 -0
- package/dist/cjs/components/x-markdown/utils/formUtils.js +2 -0
- package/dist/cjs/components/x-markdown/utils/formUtils.js.map +1 -0
- package/dist/cjs/components/x-markdown/utils/jsonUtils.js +2 -0
- package/dist/cjs/components/x-markdown/utils/jsonUtils.js.map +1 -0
- package/dist/cjs/components/x-markdown/utils/refUtils.js +2 -0
- package/dist/cjs/components/x-markdown/utils/refUtils.js.map +1 -0
- package/dist/cjs/components/x-markdown/utils/textFormatUtils.js +2 -0
- package/dist/cjs/components/x-markdown/utils/textFormatUtils.js.map +1 -0
- package/dist/es/client-vue.css +1 -1
- package/dist/es/components/x-markdown/composables/useFormHandler.js +66 -0
- package/dist/es/components/x-markdown/composables/useFormHandler.js.map +1 -0
- package/dist/es/components/x-markdown/composables/useImageLoader.js +58 -0
- package/dist/es/components/x-markdown/composables/useImageLoader.js.map +1 -0
- package/dist/es/components/x-markdown/composables/useMarkdownProcessor.js +48 -0
- package/dist/es/components/x-markdown/composables/useMarkdownProcessor.js.map +1 -0
- package/dist/es/components/x-markdown/composables/useRefHandler.js +80 -0
- package/dist/es/components/x-markdown/composables/useRefHandler.js.map +1 -0
- package/dist/es/components/x-markdown/composables/useStreamHandler.js +45 -0
- package/dist/es/components/x-markdown/composables/useStreamHandler.js.map +1 -0
- package/dist/es/components/x-markdown/index.js +73 -681
- package/dist/es/components/x-markdown/index.js.map +1 -1
- package/dist/es/components/x-markdown/renderers/hastRenderer.js +427 -0
- package/dist/es/components/x-markdown/renderers/hastRenderer.js.map +1 -0
- package/dist/es/components/x-markdown/utils/disabledUtils.js +15 -0
- package/dist/es/components/x-markdown/utils/disabledUtils.js.map +1 -0
- package/dist/es/components/x-markdown/utils/formUtils.js +82 -0
- package/dist/es/components/x-markdown/utils/formUtils.js.map +1 -0
- package/dist/es/components/x-markdown/utils/jsonUtils.js +20 -0
- package/dist/es/components/x-markdown/utils/jsonUtils.js.map +1 -0
- package/dist/es/components/x-markdown/utils/refUtils.js +18 -0
- package/dist/es/components/x-markdown/utils/refUtils.js.map +1 -0
- package/dist/es/components/x-markdown/utils/textFormatUtils.js +46 -0
- package/dist/es/components/x-markdown/utils/textFormatUtils.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,85 +1,20 @@
|
|
|
1
|
-
import { defineComponent, createVNode, useTemplateRef, ref, computed, watch, onMounted, onBeforeUnmount,
|
|
1
|
+
import { defineComponent, createVNode, useTemplateRef, ref, computed, watch, nextTick, onMounted, onBeforeUnmount, onUpdated } from "vue";
|
|
2
2
|
import debounce from "../../_virtual/debounce.js";
|
|
3
|
-
import {
|
|
4
|
-
import { ElTimeline, ElRow, ElCol, ElCard, ElForm, ElFormItem, ElButton, ElSelect, ElDatePicker, ElInput, ElRadioGroup, ElRadio, ElTableColumn, ElConfigProvider, ElMessage } from "element-plus";
|
|
3
|
+
import { ElMessage } from "element-plus";
|
|
5
4
|
/* empty css */
|
|
6
5
|
/* empty css */
|
|
7
6
|
/* empty css */
|
|
8
|
-
/* empty css */
|
|
9
|
-
import "../../node_modules/.pnpm/element-plus@2.11.8_vue@3.5.24_typescript@5.6.3_/node_modules/element-plus/theme-chalk/src/form-item.scss.js";
|
|
10
|
-
/* empty css */
|
|
11
|
-
/* empty css */
|
|
12
|
-
/* empty css */
|
|
13
|
-
/* empty css */
|
|
14
|
-
/* empty css */
|
|
15
|
-
/* empty css */
|
|
16
|
-
/* empty css */
|
|
17
|
-
/* empty css */
|
|
18
|
-
/* empty css */
|
|
19
|
-
import "../../node_modules/.pnpm/element-plus@2.11.8_vue@3.5.24_typescript@5.6.3_/node_modules/element-plus/theme-chalk/src/date-picker.scss.js";
|
|
20
|
-
/* empty css */
|
|
21
|
-
/* empty css */
|
|
22
|
-
/* empty css */
|
|
23
|
-
/* empty css */
|
|
24
|
-
/* empty css */
|
|
25
|
-
/* empty css */
|
|
26
|
-
/* empty css */
|
|
27
|
-
/* empty css */
|
|
28
|
-
import "../../node_modules/.pnpm/element-plus@2.11.8_vue@3.5.24_typescript@5.6.3_/node_modules/element-plus/theme-chalk/src/config-provider.scss.js";
|
|
29
7
|
/* empty css */
|
|
30
8
|
/* empty css */
|
|
31
|
-
import { createStreamGenerator } from "./utils/mockStream.js";
|
|
32
|
-
import { parseCorePilot } from "./utils/parseCorePilotSchema.js";
|
|
33
|
-
import { Accordion } from "./utils/animation.js";
|
|
34
|
-
import CoreText from "../core-text/index.js";
|
|
35
|
-
import CoreTips from "../core-tips/index.js";
|
|
36
|
-
import CoreResult from "../core-result/index.js";
|
|
37
|
-
import CoreTable from "../core-table/index.js";
|
|
38
|
-
import CoreChart from "../core-chart/index.js";
|
|
39
|
-
import CoreCard from "../core-card/index.js";
|
|
40
|
-
import CoreUpload from "../core-upload/index.js";
|
|
41
9
|
/* empty css */
|
|
42
|
-
import
|
|
43
|
-
import {
|
|
44
|
-
import
|
|
45
|
-
import
|
|
46
|
-
import
|
|
47
|
-
import
|
|
48
|
-
import
|
|
49
|
-
import
|
|
50
|
-
import rehypeRaw from "../../node_modules/.pnpm/rehype-raw@7.0.0/node_modules/rehype-raw/lib/index.js";
|
|
51
|
-
import rehypeKatex from "../../node_modules/.pnpm/rehype-katex@7.0.1/node_modules/rehype-katex/lib/index.js";
|
|
52
|
-
import rehypeStringify from "../../node_modules/.pnpm/rehype-stringify@10.0.1/node_modules/rehype-stringify/lib/index.js";
|
|
53
|
-
const checkAndReturnRefList = (text) => {
|
|
54
|
-
const reg = /<div hidden>([\s\S]*?)<\/div>/g;
|
|
55
|
-
const match = reg.exec(text);
|
|
56
|
-
if (!match) {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
const refListStr = match[1];
|
|
60
|
-
try {
|
|
61
|
-
const refList = JSON.parse(refListStr);
|
|
62
|
-
return refList;
|
|
63
|
-
} catch (error) {
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const isCompleteJSON = (jsonStr) => {
|
|
68
|
-
if (!jsonStr || jsonStr.trim().length === 0) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
const trimmed = jsonStr.trim();
|
|
72
|
-
const firstChar = trimmed[0];
|
|
73
|
-
if (firstChar !== "{" && firstChar !== "[") {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
JSON.parse(trimmed);
|
|
78
|
-
return true;
|
|
79
|
-
} catch (error) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
10
|
+
import { Accordion } from "./utils/animation.js";
|
|
11
|
+
import { formatMarkdownText } from "./utils/textFormatUtils.js";
|
|
12
|
+
import { useImageLoader } from "./composables/useImageLoader.js";
|
|
13
|
+
import { useRefHandler } from "./composables/useRefHandler.js";
|
|
14
|
+
import { useStreamHandler } from "./composables/useStreamHandler.js";
|
|
15
|
+
import { useMarkdownProcessor } from "./composables/useMarkdownProcessor.js";
|
|
16
|
+
import { useFormHandler } from "./composables/useFormHandler.js";
|
|
17
|
+
import { hastToVNode } from "./renderers/hastRenderer.js";
|
|
83
18
|
const XMarkdown = /* @__PURE__ */ defineComponent({
|
|
84
19
|
name: "XMarkdown",
|
|
85
20
|
props: {
|
|
@@ -128,159 +63,43 @@ const XMarkdown = /* @__PURE__ */ defineComponent({
|
|
|
128
63
|
const container = useTemplateRef("x-markdown-container");
|
|
129
64
|
const startTime = ref(Date.now());
|
|
130
65
|
const endTime = ref(-Infinity);
|
|
131
|
-
const context = ref("");
|
|
132
|
-
const pendingImages = /* @__PURE__ */ new Set();
|
|
133
66
|
const isInitAnimation = ref(false);
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const curIndex = ref(0);
|
|
138
|
-
let curInit = 0;
|
|
139
|
-
const ast = ref(null);
|
|
140
|
-
const isRewrite = ref(false);
|
|
141
|
-
const streamCall = (stream) => {
|
|
142
|
-
context.value = context.value + stream;
|
|
143
|
-
};
|
|
144
|
-
const uploadHeaders = computed(() => {
|
|
145
|
-
return {
|
|
146
|
-
Authorization: `Bearer ${props.authToken}`,
|
|
147
|
-
appId: props.appId
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
const uploadExtendData = computed(() => {
|
|
151
|
-
return {
|
|
152
|
-
user: props.user
|
|
153
|
-
};
|
|
154
|
-
});
|
|
155
|
-
const streamGener = ref(createStreamGenerator(streamCall, props.speed));
|
|
156
|
-
const updateSummaryClasses = (mdText) => {
|
|
157
|
-
const summaryDivReg = /(<summary[^>]*>[\s\S]*?<\/summary>)\s*(<div>[\s\S]*?)(<\/div>|$)/g;
|
|
158
|
-
let isFirstSummary = true;
|
|
159
|
-
return mdText.replace(summaryDivReg, (match, summaryTag, divContent, divEnd) => {
|
|
160
|
-
const isDivComplete = divEnd === "</div>";
|
|
161
|
-
const updatedSummary = summaryTag.replace(/(<summary)/g, (match2) => {
|
|
162
|
-
if (isFirstSummary) {
|
|
163
|
-
isFirstSummary = false;
|
|
164
|
-
return match2;
|
|
165
|
-
}
|
|
166
|
-
return `<summary class="${isDivComplete ? "loaded" : "loading"}"`;
|
|
167
|
-
});
|
|
168
|
-
return `${updatedSummary}
|
|
169
|
-
${divContent}${divEnd}`;
|
|
170
|
-
});
|
|
171
|
-
};
|
|
67
|
+
const {
|
|
68
|
+
context
|
|
69
|
+
} = useStreamHandler(computed(() => props.text), computed(() => props.typing), computed(() => props.speed));
|
|
172
70
|
const formatText = computed(() => {
|
|
173
|
-
if (
|
|
174
|
-
|
|
175
|
-
content = updateSummaryClasses(content);
|
|
176
|
-
content = content.replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, " ");
|
|
177
|
-
if (content.includes("</details>")) {
|
|
178
|
-
if (endTime.value === -Infinity) {
|
|
179
|
-
endTime.value = Date.now();
|
|
180
|
-
}
|
|
181
|
-
const res = checkAndReturnRefList(content);
|
|
182
|
-
let text = content.replace(/<details open>([\s\S]*?)<\/details>/g, (match, content2) => {
|
|
183
|
-
content2 = content2.replace(/<summary>([\s\S]*?)<\/summary>/, (match2, content3) => {
|
|
184
|
-
const duration = ((endTime.value - startTime.value) / 1e3).toFixed(0);
|
|
185
|
-
return `<summary style="color: #8D90A0;font-weight: 300; font-size: 16px;">
|
|
186
|
-
已完成思考 ${duration > "0" ? duration + "s" : ""} ${res.length ? `<span style="display: inline-block;margin: 0 8px;border-left: 1px solid #CDCFD7;width: 1px;height: 16px;"></span> 引用文档:${res == null ? void 0 : res.length} 个` : ""}
|
|
187
|
-
</summary>`;
|
|
188
|
-
});
|
|
189
|
-
content2 = content2.replace(/<summary>完成<\/summary>/, '<summary class="loaded">完成</summary>');
|
|
190
|
-
return `<details>${content2}</details>`;
|
|
191
|
-
});
|
|
192
|
-
return text;
|
|
71
|
+
if (context.value.includes("</details>") && endTime.value === -Infinity) {
|
|
72
|
+
endTime.value = Date.now();
|
|
193
73
|
}
|
|
194
|
-
return
|
|
195
|
-
});
|
|
196
|
-
const checkDisabled = (node) => {
|
|
197
|
-
const {
|
|
198
|
-
properties = {},
|
|
199
|
-
parentScope
|
|
200
|
-
} = node;
|
|
201
|
-
const {
|
|
202
|
-
disabled
|
|
203
|
-
} = properties;
|
|
204
|
-
if (disabled) {
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
if (parentScope === "form") {
|
|
208
|
-
return props.isHistoryMessage && !isRewrite.value;
|
|
209
|
-
}
|
|
210
|
-
return false;
|
|
211
|
-
};
|
|
212
|
-
watch(() => [props.text, props.typing], (v, o) => {
|
|
213
|
-
var _a, _b, _c, _d;
|
|
214
|
-
const [text, typing] = v;
|
|
215
|
-
const [oldText] = o || [];
|
|
216
|
-
if (!text.startsWith(oldText)) {
|
|
217
|
-
(_a = streamGener.value) == null ? void 0 : _a.reset();
|
|
218
|
-
context.value = "";
|
|
219
|
-
}
|
|
220
|
-
if (text) {
|
|
221
|
-
(_b = streamGener.value) == null ? void 0 : _b.update(text);
|
|
222
|
-
if (!typing) {
|
|
223
|
-
(_c = streamGener.value) == null ? void 0 : _c.stop();
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
const checkReg = /<summary>资料整合<\/summary>\r?\n(.|\s)+?/;
|
|
227
|
-
if (!tagComplete.value && checkReg.test(text)) {
|
|
228
|
-
tagComplete.value = true;
|
|
229
|
-
(_d = streamGener.value) == null ? void 0 : _d.setSpeed(500);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}, {
|
|
234
|
-
immediate: true
|
|
74
|
+
return formatMarkdownText(context.value, props.autoHideThinking, startTime.value, endTime.value === -Infinity ? Date.now() : endTime.value);
|
|
235
75
|
});
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
76
|
+
const historyInputsRef = computed(() => props.historyInputs);
|
|
77
|
+
const {
|
|
78
|
+
ast,
|
|
79
|
+
hitlData
|
|
80
|
+
} = useMarkdownProcessor(formatText, historyInputsRef);
|
|
81
|
+
const {
|
|
82
|
+
formRefs,
|
|
83
|
+
curIndex,
|
|
84
|
+
isRewrite,
|
|
85
|
+
btnClick,
|
|
86
|
+
resetCurInit,
|
|
87
|
+
getCurInit
|
|
88
|
+
} = useFormHandler(hitlData, emit);
|
|
89
|
+
const {
|
|
90
|
+
processNewImages
|
|
91
|
+
} = useImageLoader(container);
|
|
92
|
+
const {
|
|
93
|
+
getRefConfig,
|
|
94
|
+
handleMouseOver,
|
|
95
|
+
handleClick: handleRefClick
|
|
96
|
+
} = useRefHandler(container, emit);
|
|
243
97
|
const renderComplete = debounce(() => {
|
|
244
98
|
getRefConfig();
|
|
245
99
|
}, 100);
|
|
246
|
-
const activeRef = ref(null);
|
|
247
100
|
watch(() => context.value, renderComplete, {
|
|
248
101
|
immediate: true
|
|
249
102
|
});
|
|
250
|
-
watch(activeRef, (newVal, oldVal) => {
|
|
251
|
-
if (newVal !== oldVal) {
|
|
252
|
-
if (newVal) {
|
|
253
|
-
const text = newVal.getAttribute("dataherf");
|
|
254
|
-
const target = refConfig.value.find((item) => {
|
|
255
|
-
return item.link === text;
|
|
256
|
-
});
|
|
257
|
-
emit("hoverActiveRefTrigger", target);
|
|
258
|
-
} else {
|
|
259
|
-
emit("hoverActiveRefTrigger", "");
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
const getTargeElement = (e) => {
|
|
264
|
-
const target = e.target;
|
|
265
|
-
if (target.tagName === "SPAN") {
|
|
266
|
-
const isInRefContainer = target.classList.contains("x-markdown-split");
|
|
267
|
-
const isRefContainer = target.classList.contains("x-markdown-sub");
|
|
268
|
-
if (isInRefContainer || isRefContainer) {
|
|
269
|
-
if (!isRefContainer) {
|
|
270
|
-
return target.parentElement;
|
|
271
|
-
}
|
|
272
|
-
return target;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
const handleMouseOver = (e) => {
|
|
277
|
-
const target = getTargeElement(e);
|
|
278
|
-
if (target) {
|
|
279
|
-
activeRef.value = target;
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
activeRef.value = null;
|
|
283
|
-
};
|
|
284
103
|
const handleAClick = async (e) => {
|
|
285
104
|
e.stopPropagation();
|
|
286
105
|
e.preventDefault();
|
|
@@ -303,184 +122,47 @@ ${divContent}${divEnd}`;
|
|
|
303
122
|
ext,
|
|
304
123
|
href
|
|
305
124
|
});
|
|
306
|
-
return;
|
|
307
|
-
};
|
|
308
|
-
const btnClick = async (index, action, payload, parentScope) => {
|
|
309
|
-
var _a;
|
|
310
|
-
if (action === "inner_next") {
|
|
311
|
-
curIndex.value += 1;
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (action === "inner_prev") {
|
|
315
|
-
curIndex.value -= 1;
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
if (action === "inner_rewrite") {
|
|
319
|
-
isRewrite.value = true;
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
let res = {
|
|
323
|
-
action,
|
|
324
|
-
payload: {}
|
|
325
|
-
};
|
|
326
|
-
if (payload && parentScope !== "form") {
|
|
327
|
-
res = {
|
|
328
|
-
action,
|
|
329
|
-
payload
|
|
330
|
-
};
|
|
331
|
-
} else {
|
|
332
|
-
await ((_a = formRefs.value[index]) == null ? void 0 : _a.validate());
|
|
333
|
-
res = {
|
|
334
|
-
action,
|
|
335
|
-
payload: {
|
|
336
|
-
...hitlData.value[index],
|
|
337
|
-
...payload
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
if (isRewrite.value && action.startsWith("core_")) {
|
|
342
|
-
isRewrite.value = false;
|
|
343
|
-
}
|
|
344
|
-
emit("coreSubmit", res);
|
|
345
125
|
};
|
|
346
126
|
const handleClick = (e) => {
|
|
347
127
|
if (e.target.tagName === "A") {
|
|
348
128
|
handleAClick(e);
|
|
349
129
|
return;
|
|
350
130
|
}
|
|
351
|
-
|
|
352
|
-
if (target) {
|
|
353
|
-
const text = target.getAttribute("dataherf");
|
|
354
|
-
const highlight = JSON.parse(target.getAttribute("datahighlight") || "[]");
|
|
355
|
-
const page = Number(target.getAttribute("datanumber"));
|
|
356
|
-
const id = target.getAttribute("id");
|
|
357
|
-
const source = refConfig.value.find((item) => {
|
|
358
|
-
return item.link === text;
|
|
359
|
-
});
|
|
360
|
-
const data = {
|
|
361
|
-
...source,
|
|
362
|
-
highlight,
|
|
363
|
-
page,
|
|
364
|
-
id
|
|
365
|
-
};
|
|
366
|
-
emit("clickActiveRefTrigger", data);
|
|
367
|
-
}
|
|
131
|
+
handleRefClick(e);
|
|
368
132
|
};
|
|
369
133
|
const getContentText = () => {
|
|
370
134
|
var _a;
|
|
371
135
|
return (_a = container.value) == null ? void 0 : _a.innerText;
|
|
372
136
|
};
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
137
|
+
const uploadHeaders = computed(() => {
|
|
138
|
+
return {
|
|
139
|
+
Authorization: `Bearer ${props.authToken}`,
|
|
140
|
+
appId: props.appId
|
|
141
|
+
};
|
|
376
142
|
});
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
143
|
+
const uploadExtendData = computed(() => {
|
|
144
|
+
return {
|
|
145
|
+
user: props.user
|
|
146
|
+
};
|
|
380
147
|
});
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
};
|
|
396
|
-
const setPlaceholderDimensions = (img) => {
|
|
397
|
-
const containerWidth = img.parentElement.offsetWidth;
|
|
398
|
-
if (img.naturalWidth > containerWidth) {
|
|
399
|
-
img.style.maxWidth = "100%";
|
|
400
|
-
}
|
|
401
|
-
if (img.naturalWidth && img.naturalHeight) {
|
|
402
|
-
const ratio = img.naturalHeight / img.naturalWidth;
|
|
403
|
-
img.style.maxHeight = `${Math.min(500, containerWidth * ratio)}px`;
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
const handleImageLoad = (img) => {
|
|
407
|
-
pendingImages.delete(img);
|
|
408
|
-
img.setAttribute("data-processed", "true");
|
|
409
|
-
img.classList.add("loaded");
|
|
410
|
-
img.style.opacity = "1";
|
|
411
|
-
img.removeEventListener("load", handleImageLoad);
|
|
412
|
-
img.removeEventListener("error", handleImageError);
|
|
413
|
-
};
|
|
414
|
-
const handleImageError = (img) => {
|
|
415
|
-
pendingImages.delete(img);
|
|
416
|
-
img.setAttribute("data-processed", "true");
|
|
417
|
-
img.classList.add("load-error");
|
|
418
|
-
img.style.maxHeight = "200px";
|
|
419
|
-
img.removeEventListener("load", handleImageLoad);
|
|
420
|
-
img.removeEventListener("error", handleImageError);
|
|
421
|
-
};
|
|
422
|
-
const md = unified().use(remarkParse).use(remarkBreaks).use(remarkGfm, {
|
|
423
|
-
singleTilde: false
|
|
424
|
-
}).use(remarkMath).use(remarkGemoji).use(remarkRehype, {
|
|
425
|
-
allowDangerousHtml: true
|
|
426
|
-
}).use(rehypeRaw).use(rehypeKatex).use(rehypeStringify);
|
|
427
|
-
const collectFormsFromSchema = (schema, formDataList) => {
|
|
428
|
-
var _a;
|
|
429
|
-
if (!schema || typeof schema !== "object") return;
|
|
430
|
-
if (schema.type === "form") {
|
|
431
|
-
const formData = {
|
|
432
|
-
...((_a = schema.properties) == null ? void 0 : _a.data) || {},
|
|
433
|
-
// FIXME 目前只有卡片里面仅有可能出现单个表单,需要需要支持多表单场景
|
|
434
|
-
...props.historyInputs || {}
|
|
435
|
-
};
|
|
436
|
-
formDataList.push(formData);
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
if (Array.isArray(schema.children)) {
|
|
440
|
-
schema.children.forEach((child) => {
|
|
441
|
-
collectFormsFromSchema(child, formDataList);
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
const computedForm = (mdAst) => {
|
|
446
|
-
const formDataList = [];
|
|
447
|
-
const preNodes = [];
|
|
448
|
-
const findPreNodes = (node) => {
|
|
449
|
-
if (!node) return;
|
|
450
|
-
if (node.tagName === "pre") {
|
|
451
|
-
preNodes.push(node);
|
|
452
|
-
}
|
|
453
|
-
if (Array.isArray(node.children)) {
|
|
454
|
-
node.children.forEach(findPreNodes);
|
|
148
|
+
const createRendererConfig = () => {
|
|
149
|
+
return {
|
|
150
|
+
hitlData: hitlData.value,
|
|
151
|
+
formRefs: formRefs.value,
|
|
152
|
+
curIndex: curIndex.value,
|
|
153
|
+
getCurInit,
|
|
154
|
+
btnClick,
|
|
155
|
+
uploadHeaders: uploadHeaders.value,
|
|
156
|
+
uploadExtendData: uploadExtendData.value,
|
|
157
|
+
disabledContext: {
|
|
158
|
+
isHistoryMessage: props.isHistoryMessage,
|
|
159
|
+
isRewrite: isRewrite.value
|
|
455
160
|
}
|
|
456
161
|
};
|
|
457
|
-
if (Array.isArray(mdAst.children)) {
|
|
458
|
-
mdAst.children.forEach(findPreNodes);
|
|
459
|
-
}
|
|
460
|
-
preNodes.forEach((preNode) => {
|
|
461
|
-
var _a, _b, _c, _d, _e;
|
|
462
|
-
const codeNode = (_a = preNode.children) == null ? void 0 : _a.find((child) => child.tagName === "code");
|
|
463
|
-
if ((_c = (_b = codeNode == null ? void 0 : codeNode.properties) == null ? void 0 : _b.className) == null ? void 0 : _c.includes("language-CorePilot")) {
|
|
464
|
-
try {
|
|
465
|
-
const code = ((_e = (_d = codeNode.children) == null ? void 0 : _d[0]) == null ? void 0 : _e.value) || "";
|
|
466
|
-
if (code) {
|
|
467
|
-
const schema = JSON.parse(code);
|
|
468
|
-
collectFormsFromSchema(schema, formDataList);
|
|
469
|
-
}
|
|
470
|
-
} catch (error) {
|
|
471
|
-
console.error("Failed to parse CorePilot schema:", error);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
return formDataList;
|
|
476
162
|
};
|
|
477
|
-
watch(() =>
|
|
478
|
-
|
|
479
|
-
const mdAst = await md.run(md.parse(text));
|
|
480
|
-
const formDataList = computedForm(mdAst);
|
|
481
|
-
hitlData.value = formDataList;
|
|
163
|
+
watch(() => ast.value, async () => {
|
|
164
|
+
if (!ast.value) return;
|
|
482
165
|
await nextTick();
|
|
483
|
-
ast.value = mdAst;
|
|
484
166
|
nextTick(processNewImages);
|
|
485
167
|
nextTick(() => {
|
|
486
168
|
var _a;
|
|
@@ -494,313 +176,23 @@ ${divContent}${divEnd}`;
|
|
|
494
176
|
}, {
|
|
495
177
|
immediate: true
|
|
496
178
|
});
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
// 头部骨架
|
|
502
|
-
h("div", {
|
|
503
|
-
class: "skeleton-header"
|
|
504
|
-
}, [h("div", {
|
|
505
|
-
class: "skeleton-avatar"
|
|
506
|
-
}), h("div", {
|
|
507
|
-
class: "skeleton-title"
|
|
508
|
-
})]),
|
|
509
|
-
// 内容骨架
|
|
510
|
-
h("div", {
|
|
511
|
-
class: "skeleton-item skeleton-item-long"
|
|
512
|
-
}),
|
|
513
|
-
h("div", {
|
|
514
|
-
class: "skeleton-item skeleton-item-medium"
|
|
515
|
-
}),
|
|
516
|
-
h("div", {
|
|
517
|
-
class: "skeleton-item skeleton-item-short"
|
|
518
|
-
}),
|
|
519
|
-
h("div", {
|
|
520
|
-
class: "skeleton-item skeleton-item-long"
|
|
521
|
-
}),
|
|
522
|
-
h("div", {
|
|
523
|
-
class: "skeleton-item skeleton-item-medium"
|
|
524
|
-
})
|
|
525
|
-
]);
|
|
526
|
-
};
|
|
527
|
-
const hastToVNode = (node, index, row) => {
|
|
528
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
529
|
-
if (!node) return null;
|
|
530
|
-
let children = [];
|
|
531
|
-
const blackTagNames = ["sub", "pre", "text", "ElForm"];
|
|
532
|
-
if (!blackTagNames.includes(node.tagName)) {
|
|
533
|
-
children = ((_b = (_a = node.children) == null ? void 0 : _a.map) == null ? void 0 : _b.call(_a, (child) => hastToVNode(child, index))) || [];
|
|
179
|
+
onMounted(() => {
|
|
180
|
+
if (container.value) {
|
|
181
|
+
container.value.addEventListener("mouseover", handleMouseOver);
|
|
182
|
+
container.value.addEventListener("click", handleClick);
|
|
534
183
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
locale: zhCn
|
|
541
|
-
}, children));
|
|
542
|
-
case "element":
|
|
543
|
-
if (node.tagName === "sub") {
|
|
544
|
-
const formatChildren = [{
|
|
545
|
-
type: "element",
|
|
546
|
-
tagName: "span",
|
|
547
|
-
properties: {
|
|
548
|
-
class: "x-markdown-split"
|
|
549
|
-
}
|
|
550
|
-
}, ...node.children];
|
|
551
|
-
const children2 = formatChildren == null ? void 0 : formatChildren.map((child) => hastToVNode(child, index));
|
|
552
|
-
return h("span", {
|
|
553
|
-
...node.properties,
|
|
554
|
-
class: "x-markdown-sub"
|
|
555
|
-
}, children2);
|
|
556
|
-
}
|
|
557
|
-
if (node.tagName === "span") {
|
|
558
|
-
return h("span", {
|
|
559
|
-
...node.properties
|
|
560
|
-
}, children);
|
|
561
|
-
}
|
|
562
|
-
if (node.tagName === "img") {
|
|
563
|
-
return h("img", {
|
|
564
|
-
...node.properties,
|
|
565
|
-
class: "markdown-image",
|
|
566
|
-
"data-processed": "false"
|
|
567
|
-
// 标记未处理图片
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
if (node.tagName === "a") {
|
|
571
|
-
const href = ((_c = node.properties) == null ? void 0 : _c.href) || "";
|
|
572
|
-
const fileType = href ? href.split(".").pop() : null;
|
|
573
|
-
return h("a", {
|
|
574
|
-
...node.properties,
|
|
575
|
-
class: "file-link",
|
|
576
|
-
"data-file-type": fileType
|
|
577
|
-
}, children);
|
|
578
|
-
}
|
|
579
|
-
if (node.tagName === "ElTimeline") {
|
|
580
|
-
return h(ElTimeline, {
|
|
581
|
-
...node.properties
|
|
582
|
-
}, children);
|
|
583
|
-
}
|
|
584
|
-
if (node.tagName === "table") {
|
|
585
|
-
return h("div", {
|
|
586
|
-
class: "custom-table-container"
|
|
587
|
-
}, [h("table", children)]);
|
|
588
|
-
}
|
|
589
|
-
if (node.tagName === "view") {
|
|
590
|
-
return h("div", {
|
|
591
|
-
class: "custom-view-container"
|
|
592
|
-
}, [children[curIndex.value]]);
|
|
593
|
-
}
|
|
594
|
-
if (node.tagName === "ElRow") {
|
|
595
|
-
return h(ElRow, {
|
|
596
|
-
...node.properties
|
|
597
|
-
}, children);
|
|
598
|
-
}
|
|
599
|
-
if (node.tagName === "ElCol") {
|
|
600
|
-
return h(ElCol, {
|
|
601
|
-
...node.properties
|
|
602
|
-
}, children);
|
|
603
|
-
}
|
|
604
|
-
if (node.tagName === "ElCard") {
|
|
605
|
-
return h(ElCard, {
|
|
606
|
-
...node.properties
|
|
607
|
-
}, children);
|
|
608
|
-
}
|
|
609
|
-
if (node.tagName === "CoreCard") {
|
|
610
|
-
const slots = {};
|
|
611
|
-
if ((_d = node.slots) == null ? void 0 : _d.header) {
|
|
612
|
-
slots.header = () => {
|
|
613
|
-
return node.slots.header.map((slotItem) => {
|
|
614
|
-
return hastToVNode(slotItem, index);
|
|
615
|
-
});
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
|
-
if (children && children.length > 0) {
|
|
619
|
-
slots.default = () => children;
|
|
620
|
-
}
|
|
621
|
-
return h(CoreCard, {
|
|
622
|
-
...node.properties
|
|
623
|
-
}, slots);
|
|
624
|
-
}
|
|
625
|
-
if (node.tagName === "ElForm") {
|
|
626
|
-
const children2 = (_e = node.children) == null ? void 0 : _e.map((child) => hastToVNode(child, curInit));
|
|
627
|
-
curInit++;
|
|
628
|
-
return h(ElForm, {
|
|
629
|
-
ref: formRefs.value.set,
|
|
630
|
-
model: hitlData.value[index],
|
|
631
|
-
...node.properties,
|
|
632
|
-
disabled: checkDisabled(node)
|
|
633
|
-
}, children2);
|
|
634
|
-
}
|
|
635
|
-
if (node.tagName === "ElFormItem") {
|
|
636
|
-
return h(ElFormItem, {
|
|
637
|
-
...node.properties
|
|
638
|
-
}, children);
|
|
639
|
-
}
|
|
640
|
-
if (node.tagName === "ElButton") {
|
|
641
|
-
let payload = (_f = node.properties) == null ? void 0 : _f.payload;
|
|
642
|
-
if (node.parentScope === "table") {
|
|
643
|
-
payload = row;
|
|
644
|
-
}
|
|
645
|
-
return h(ElButton, {
|
|
646
|
-
...node.properties,
|
|
647
|
-
disabled: checkDisabled(node),
|
|
648
|
-
onClick: () => {
|
|
649
|
-
var _a2;
|
|
650
|
-
btnClick(index, (_a2 = node.properties) == null ? void 0 : _a2.action, payload, node.parentScope);
|
|
651
|
-
}
|
|
652
|
-
}, children);
|
|
653
|
-
}
|
|
654
|
-
if (node.tagName === "ElSelect") {
|
|
655
|
-
return h(ElSelect, {
|
|
656
|
-
...node.properties,
|
|
657
|
-
disabled: checkDisabled(node),
|
|
658
|
-
modelValue: hitlData.value[index][(_g = node.properties) == null ? void 0 : _g.formProp],
|
|
659
|
-
"onUpdate:modelValue": (value) => {
|
|
660
|
-
var _a2;
|
|
661
|
-
hitlData.value[index][(_a2 = node.properties) == null ? void 0 : _a2.formProp] = value;
|
|
662
|
-
}
|
|
663
|
-
}, children);
|
|
664
|
-
}
|
|
665
|
-
if (node.tagName === "ElDatePicker") {
|
|
666
|
-
return h(ElDatePicker, {
|
|
667
|
-
...node.properties,
|
|
668
|
-
disabled: checkDisabled(node),
|
|
669
|
-
modelValue: hitlData.value[index][(_h = node.properties) == null ? void 0 : _h.formProp],
|
|
670
|
-
"onUpdate:modelValue": (value) => {
|
|
671
|
-
var _a2;
|
|
672
|
-
hitlData.value[index][(_a2 = node.properties) == null ? void 0 : _a2.formProp] = value;
|
|
673
|
-
}
|
|
674
|
-
}, children);
|
|
675
|
-
}
|
|
676
|
-
if (node.tagName === "ElInput") {
|
|
677
|
-
return h(ElInput, {
|
|
678
|
-
...node.properties,
|
|
679
|
-
disabled: checkDisabled(node),
|
|
680
|
-
modelValue: hitlData.value[index][(_i = node.properties) == null ? void 0 : _i.formProp],
|
|
681
|
-
"onUpdate:modelValue": (value) => {
|
|
682
|
-
var _a2;
|
|
683
|
-
hitlData.value[index][(_a2 = node.properties) == null ? void 0 : _a2.formProp] = value;
|
|
684
|
-
}
|
|
685
|
-
}, children);
|
|
686
|
-
}
|
|
687
|
-
if (node.tagName === "ElRadioGroup") {
|
|
688
|
-
return h(ElRadioGroup, {
|
|
689
|
-
...node.properties,
|
|
690
|
-
disabled: checkDisabled(node),
|
|
691
|
-
modelValue: hitlData.value[index][(_j = node.properties) == null ? void 0 : _j.formProp],
|
|
692
|
-
"onUpdate:modelValue": (value) => {
|
|
693
|
-
var _a2;
|
|
694
|
-
hitlData.value[index][(_a2 = node.properties) == null ? void 0 : _a2.formProp] = value;
|
|
695
|
-
}
|
|
696
|
-
}, children);
|
|
697
|
-
}
|
|
698
|
-
if (node.tagName === "ElRadio") {
|
|
699
|
-
return h(ElRadio, {
|
|
700
|
-
...node.properties,
|
|
701
|
-
disabled: checkDisabled(node)
|
|
702
|
-
}, children);
|
|
703
|
-
}
|
|
704
|
-
if (node.tagName === "ElTable") {
|
|
705
|
-
return h(CoreTable, {
|
|
706
|
-
...node.properties
|
|
707
|
-
}, children);
|
|
708
|
-
}
|
|
709
|
-
if (node.tagName === "ElTableColumn") {
|
|
710
|
-
return h(ElTableColumn, {
|
|
711
|
-
...node.properties
|
|
712
|
-
}, {
|
|
713
|
-
default: (scope) => {
|
|
714
|
-
var _a2, _b2;
|
|
715
|
-
const children2 = (_a2 = node.children) == null ? void 0 : _a2.map((child) => hastToVNode(child, curInit, scope.row));
|
|
716
|
-
console.log("children", children2, node.children);
|
|
717
|
-
const index2 = (_b2 = node.children) == null ? void 0 : _b2.findIndex((child) => {
|
|
718
|
-
var _a3;
|
|
719
|
-
return child.value === scope.row[(_a3 = node.properties) == null ? void 0 : _a3.prop] && child.value !== void 0;
|
|
720
|
-
});
|
|
721
|
-
return index2 === -1 ? children2 : children2 == null ? void 0 : children2[index2];
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
if (node.tagName === "CoreText") {
|
|
726
|
-
return h(CoreText, {
|
|
727
|
-
...node.properties
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
if (node.tagName === "CoreTips") {
|
|
731
|
-
return h(CoreTips, {
|
|
732
|
-
...node.properties
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
if (node.tagName === "CoreResult") {
|
|
736
|
-
return h(CoreResult, {
|
|
737
|
-
...node.properties
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
if (node.tagName === "CoreChart") {
|
|
741
|
-
return h(CoreChart, {
|
|
742
|
-
...node.properties
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
if (node.tagName === "CoreUpload") {
|
|
746
|
-
if (node.parentScope === "form" && ((_k = node.properties) == null ? void 0 : _k.formProp)) {
|
|
747
|
-
const formProp = node.properties.formProp;
|
|
748
|
-
return h(CoreUpload, {
|
|
749
|
-
headers: uploadHeaders.value,
|
|
750
|
-
extendData: uploadExtendData.value,
|
|
751
|
-
...node.properties,
|
|
752
|
-
disabled: checkDisabled(node),
|
|
753
|
-
fileList: ((_l = hitlData.value[index]) == null ? void 0 : _l[formProp]) || [],
|
|
754
|
-
"onUpdate:fileList": (value) => {
|
|
755
|
-
if (!hitlData.value[index]) {
|
|
756
|
-
hitlData.value[index] = {};
|
|
757
|
-
}
|
|
758
|
-
if (!hitlData.value[index].__files__) {
|
|
759
|
-
hitlData.value[index].__files__ = {};
|
|
760
|
-
}
|
|
761
|
-
hitlData.value[index].__files__[formProp] = value;
|
|
762
|
-
hitlData.value[index][formProp] = value;
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
return h(CoreUpload, {
|
|
767
|
-
...node.properties,
|
|
768
|
-
disabled: checkDisabled(node)
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
if (node.tagName === "pre") {
|
|
772
|
-
const codeNode = (_m = node.children) == null ? void 0 : _m.find((child) => child.tagName === "code");
|
|
773
|
-
if (codeNode) {
|
|
774
|
-
if ((_o = (_n = codeNode.properties) == null ? void 0 : _n.className) == null ? void 0 : _o.includes("language-CorePilot")) {
|
|
775
|
-
const code = ((_q = (_p = codeNode.children) == null ? void 0 : _p[0]) == null ? void 0 : _q.value) || "";
|
|
776
|
-
if (!isCompleteJSON(code)) {
|
|
777
|
-
return renderSkeleton();
|
|
778
|
-
}
|
|
779
|
-
try {
|
|
780
|
-
const schema = JSON.parse(code);
|
|
781
|
-
const viewTree = parseCorePilot(schema);
|
|
782
|
-
const children2 = hastToVNode(viewTree, curInit);
|
|
783
|
-
return h("div", {
|
|
784
|
-
class: "hitl-wrapper"
|
|
785
|
-
}, [children2]);
|
|
786
|
-
} catch (error) {
|
|
787
|
-
return renderSkeleton();
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
return h(node.tagName, node.properties, children);
|
|
793
|
-
case "text":
|
|
794
|
-
return node.value.trim();
|
|
795
|
-
default:
|
|
796
|
-
return null;
|
|
184
|
+
});
|
|
185
|
+
onBeforeUnmount(() => {
|
|
186
|
+
if (container.value) {
|
|
187
|
+
container.value.removeEventListener("mouseover", handleMouseOver);
|
|
188
|
+
container.value.removeEventListener("click", handleClick);
|
|
797
189
|
}
|
|
798
|
-
};
|
|
190
|
+
});
|
|
799
191
|
onUpdated(() => {
|
|
800
|
-
|
|
192
|
+
resetCurInit();
|
|
801
193
|
});
|
|
802
194
|
return {
|
|
803
|
-
hastToVNode,
|
|
195
|
+
hastToVNode: (node) => hastToVNode(node, createRendererConfig()),
|
|
804
196
|
ast,
|
|
805
197
|
container,
|
|
806
198
|
renderComplete,
|