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