@blueking/ai-ui-sdk 0.1.12-beta.36 → 0.1.12-beta.37

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 (97) hide show
  1. package/dist/components/render-aside/index.vue.css +9 -9
  2. package/dist/components/render-aside/index.vue.js +1 -1
  3. package/dist/components/render-auth/auth-dialog.script.vue.js.js +2 -8
  4. package/dist/components/render-auto-height-textarea/index.vue.css +11 -11
  5. package/dist/components/render-auto-height-textarea/index.vue.js +1 -1
  6. package/dist/components/render-auto-refresh/index.vue.css +8 -8
  7. package/dist/components/render-auto-refresh/index.vue.js +1 -1
  8. package/dist/components/render-checkbox/index.vue.css +9 -9
  9. package/dist/components/render-checkbox/index.vue.js +1 -1
  10. package/dist/components/render-choose-tag/index.vue.css +7 -7
  11. package/dist/components/render-choose-tag/index.vue.js +1 -1
  12. package/dist/components/render-collapse/index.vue.css +2 -2
  13. package/dist/components/render-collapse/index.vue.js +1 -1
  14. package/dist/components/render-dataset/components/batch-review-dataset-data/index.script.vue.js.js +6 -24
  15. package/dist/components/render-dataset/components/dataset-data-tool-icons/index.script.vue.js +1 -1
  16. package/dist/components/render-dataset/components/edit-dataset-data/index.script.vue.js.js +3 -13
  17. package/dist/components/render-dataset/components/edit-dataset-data/index.vue.css +3 -3
  18. package/dist/components/render-dataset/components/edit-dataset-data/index.vue.js +1 -1
  19. package/dist/components/render-dataset/components/operation-record/index.vue.css +4 -4
  20. package/dist/components/render-dataset/components/operation-record/index.vue.js +1 -1
  21. package/dist/components/render-dataset/components/operation-record/table/index.script.vue.js.js +1 -4
  22. package/dist/components/render-dataset/components/operation-record/table/index.vue.css +1 -1
  23. package/dist/components/render-dataset/components/operation-record/table/index.vue.js +1 -1
  24. package/dist/components/render-dataset/components/operation-record/view-op-result/index.vue.css +2 -2
  25. package/dist/components/render-dataset/components/operation-record/view-op-result/index.vue.js +1 -1
  26. package/dist/components/render-dataset/components/plus-dataset/dataset-footer.script.vue.js.js +2 -8
  27. package/dist/components/render-dataset/components/plus-dataset/index.vue.css +2 -2
  28. package/dist/components/render-dataset/components/plus-dataset/index.vue.js +1 -1
  29. package/dist/components/render-dataset/components/plus-dataset-data/form/category.script.vue.js.js +1 -10
  30. package/dist/components/render-dataset/components/plus-dataset-data/form/category.vue.d.ts +0 -1
  31. package/dist/components/render-dataset/components/plus-dataset-data/form/file.script.vue.js.js +3 -12
  32. package/dist/components/render-dataset/components/plus-dataset-data/form/footer.script.vue.js.js +2 -8
  33. package/dist/components/render-dataset/components/plus-dataset-data/form/footer.vue.css +1 -1
  34. package/dist/components/render-dataset/components/plus-dataset-data/form/footer.vue.js +1 -1
  35. package/dist/components/render-dataset/components/plus-dataset-data/form/index.script.vue.js.js +14 -27
  36. package/dist/components/render-dataset/components/plus-dataset-data/form/index.vue.css +2 -2
  37. package/dist/components/render-dataset/components/plus-dataset-data/form/index.vue.js +1 -1
  38. package/dist/components/render-dataset/components/plus-dataset-data/form/manual.script.vue.js.js +3 -9
  39. package/dist/components/render-dataset/components/plus-dataset-data/index.script.vue.js.js +1 -4
  40. package/dist/components/render-dataset/components/review-dataset-data/index.script.vue.js.js +5 -21
  41. package/dist/components/render-dataset/components/review-dataset-data/index.vue.css +10 -10
  42. package/dist/components/render-dataset/components/review-dataset-data/index.vue.js +1 -1
  43. package/dist/components/render-dataset/components/source-type-icon/index.script.vue.js.js +0 -3
  44. package/dist/components/render-dataset/index.vue.css +1 -1
  45. package/dist/components/render-dataset/index.vue.js +1 -1
  46. package/dist/components/render-dataset-detail/components/header.script.vue.js.js +1 -5
  47. package/dist/components/render-dataset-detail-origin-data/components/batch-operation/index.script.vue.js.js +1 -4
  48. package/dist/components/render-dataset-detail-origin-data/components/table/index.script.vue.js +5 -20
  49. package/dist/components/render-dataset-detail-origin-data/index.script.vue.js.js +2 -8
  50. package/dist/components/render-dataset-detail-origin-data/index.vue.css +3 -3
  51. package/dist/components/render-dataset-detail-origin-data/index.vue.js +1 -1
  52. package/dist/components/render-dataset-list/components/main.script.vue.js.js +1 -4
  53. package/dist/components/render-dataset-list/components/main.vue.css +3 -3
  54. package/dist/components/render-dataset-list/components/main.vue.js +1 -1
  55. package/dist/components/render-dataset-list/components/table.script.vue.js.js +19 -19
  56. package/dist/components/render-expand-collapse/index.vue.css +3 -3
  57. package/dist/components/render-expand-collapse/index.vue.js +1 -1
  58. package/dist/components/render-file-card/index.vue.css +11 -11
  59. package/dist/components/render-file-card/index.vue.js +1 -1
  60. package/dist/components/render-file-type-icon/index.vue.css +5 -5
  61. package/dist/components/render-file-type-icon/index.vue.js +1 -1
  62. package/dist/components/render-header/index.vue.css +5 -5
  63. package/dist/components/render-header/index.vue.js +1 -1
  64. package/dist/components/render-router-tab/index.vue.css +3 -3
  65. package/dist/components/render-router-tab/index.vue.js +1 -1
  66. package/dist/components.d.ts +1 -2
  67. package/dist/components.ts.js +1 -2
  68. package/dist/css/fonts/iconcool.eot +0 -0
  69. package/dist/css/fonts/iconcool.svg +0 -3
  70. package/dist/css/fonts/iconcool.ttf +0 -0
  71. package/dist/css/fonts/iconcool.woff +0 -0
  72. package/dist/css/iconcool.js +2 -2
  73. package/dist/css/style.css +0 -3
  74. package/dist/hooks/use-chat.d.ts +0 -4
  75. package/dist/hooks/use-dataset-http.d.ts +0 -1
  76. package/dist/hooks/use-dataset-http.ts.js +1 -8
  77. package/dist/http/helper/agent.ts.js +27 -3
  78. package/dist/http/helper/dataset.d.ts +1 -7
  79. package/dist/http/helper/dataset.ts.js +0 -16
  80. package/dist/http/helper/knowledge.ts.js +0 -2
  81. package/dist/types/agent.d.ts +52 -0
  82. package/dist/types/dataset.d.ts +0 -20
  83. package/dist/types/enum.d.ts +0 -4
  84. package/dist/types/enum.ts.js +0 -5
  85. package/dist/types/knowledge.d.ts +1 -3
  86. package/package.json +2 -4
  87. package/dist/components/render-dataset/components/plus-dataset-data/form/api.script.vue.js.js +0 -137
  88. package/dist/components/render-dataset/components/plus-dataset-data/form/api.vue.css +0 -10
  89. package/dist/components/render-dataset/components/plus-dataset-data/form/api.vue.d.ts +0 -8
  90. package/dist/components/render-dataset/components/plus-dataset-data/form/api.vue.js +0 -5
  91. package/dist/components/render-markdown/mark-down-code.d.ts +0 -2
  92. package/dist/components/render-markdown/mark-down-code.ts.js +0 -171
  93. package/dist/components/render-markdown/mark-down-emoji.d.ts +0 -2
  94. package/dist/components/render-markdown/mark-down-emoji.ts.js +0 -4
  95. package/dist/components/render-markdown/mark-down.d.ts +0 -49
  96. package/dist/components/render-markdown/mark-down.postcss.css +0 -148
  97. package/dist/components/render-markdown/mark-down.ts.js +0 -145
@@ -142,26 +142,10 @@ import { transferResourcePermission } from './permission.ts.js';
142
142
  datasetName: data.dataset_name,
143
143
  datasetCode: data.dataset_code,
144
144
  type: data.type,
145
- typeName: data.type_name,
146
145
  description: data.description,
147
146
  permission: transferResourcePermission(data.permission)
148
147
  };
149
148
  };
150
- /**
151
- * 接口转换为ui使用
152
- * @param data IDatasetApiGuideApi
153
- * @returns IDatasetApiGuide
154
- */ export const transferDatasetApiGuideApi2DatasetApiGuide = (data)=>{
155
- return {
156
- apiEndpoint: data.api_endpoint,
157
- apiDemo: data.api_demo,
158
- apiContent: data.api_content.map((param)=>({
159
- paramType: param.param_type,
160
- paramName: param.param_name,
161
- paramDesc: param.param_desc
162
- }))
163
- };
164
- };
165
149
  /**
166
150
  * ui转换为接口使用
167
151
  * @param data IDatasetListParam
@@ -179,7 +179,6 @@ import { transferResourcePermission } from './permission.ts.js';
179
179
  },
180
180
  id: data.id,
181
181
  name: data.name,
182
- type: data.type,
183
182
  knowledgebase_code: data.knowledgebaseCode,
184
183
  description: data.description,
185
184
  generate_type: data.generateType,
@@ -217,7 +216,6 @@ import { transferResourcePermission } from './permission.ts.js';
217
216
  filePath: '',
218
217
  handleType: (_data_config = data.config) === null || _data_config === void 0 ? void 0 : _data_config.handle_type,
219
218
  name: data.name,
220
- type: data.type,
221
219
  knowledgebaseCode: data.knowledgebase_code,
222
220
  status: data.status,
223
221
  generateType: data.generate_type,
@@ -1,19 +1,71 @@
1
1
  import type { ISessionPrompt } from '@/types/session';
2
+ export interface IAgentCommandComponentApi {
3
+ type: string;
4
+ name: string;
5
+ key: string;
6
+ placeholder: string | null;
7
+ default: string | null;
8
+ required: boolean;
9
+ fill_back: boolean;
10
+ fill_regx: string | null;
11
+ rows: number | null;
12
+ min: number | null;
13
+ max: number | null;
14
+ options: any;
15
+ }
16
+ export interface IAgentCommandApi {
17
+ id: string;
18
+ name: string;
19
+ icon: string;
20
+ components: IAgentCommandComponentApi[];
21
+ content: string | null;
22
+ agent_id: number;
23
+ status: string;
24
+ }
2
25
  export interface IAgentInfoApi {
3
26
  conversation_settings?: {
4
27
  opening_remark?: string;
5
28
  predefined_questions?: string[];
29
+ commands?: IAgentCommandApi[];
30
+ enable_chat_session?: boolean;
6
31
  };
7
32
  prompt_setting?: {
8
33
  content?: ISessionPrompt[];
9
34
  };
35
+ agent_name: string;
36
+ }
37
+ export interface IAgentCommandComponent {
38
+ type: string;
39
+ name: string;
40
+ key: string;
41
+ placeholder: string | null;
42
+ default: string | null;
43
+ required: boolean;
44
+ fillBack: boolean;
45
+ fillRegx: string | null;
46
+ rows: number | null;
47
+ min: number | null;
48
+ max: number | null;
49
+ options: any;
50
+ }
51
+ export interface IAgentCommand {
52
+ id: string;
53
+ name: string;
54
+ icon: string;
55
+ components: IAgentCommandComponent[];
56
+ content: string | null;
57
+ agentId: number;
58
+ status: string;
10
59
  }
11
60
  export interface IAgentInfo {
12
61
  conversationSettings?: {
13
62
  openingRemark?: string;
14
63
  predefinedQuestions?: string[];
64
+ commands?: IAgentCommand[];
65
+ enableChatSession?: boolean;
15
66
  };
16
67
  promptSetting?: {
17
68
  content?: ISessionPrompt[];
18
69
  };
70
+ agentName?: string;
19
71
  }
@@ -27,7 +27,6 @@ export interface IDatasetForm {
27
27
  export interface IDatasetApi extends IDatasetFormApi {
28
28
  component_names: string[];
29
29
  company_name: string;
30
- type_name: string;
31
30
  dataset_item_count: number;
32
31
  updated_at: string;
33
32
  updated_by: string;
@@ -39,7 +38,6 @@ export interface IDatasetApi extends IDatasetFormApi {
39
38
  export interface IDataset extends IDatasetForm {
40
39
  componentNames: string[];
41
40
  companyName: string;
42
- typeName: string;
43
41
  datasetItemCount: number;
44
42
  updatedAt: string;
45
43
  updatedBy: string;
@@ -74,24 +72,6 @@ export interface IDatasetListParamApi extends IPage, ISort {
74
72
  tag_name?: string;
75
73
  generate_type?: EnumCharacter;
76
74
  }
77
- export interface IDatasetApiGuideApi {
78
- api_endpoint: string;
79
- api_content: {
80
- param_name: string;
81
- param_type: string;
82
- param_desc: string;
83
- }[];
84
- api_demo: string;
85
- }
86
- export interface IDatasetApiGuide {
87
- apiEndpoint: string;
88
- apiContent: {
89
- paramName: string;
90
- paramType: string;
91
- paramDesc: string;
92
- }[];
93
- apiDemo: string;
94
- }
95
75
  export interface IDatasetDataFileApi extends IFileInfoApi {
96
76
  id: string;
97
77
  }
@@ -210,7 +210,3 @@ export declare enum CrdentialLocation {
210
210
  Body = "body",
211
211
  Query = "query"
212
212
  }
213
- export declare enum KnowledgebaseType {
214
- Default = "default",
215
- IntentRecog = "intent_recog"
216
- }
@@ -237,8 +237,3 @@ export var CrdentialLocation;
237
237
  CrdentialLocation["Body"] = "body";
238
238
  CrdentialLocation["Query"] = "query";
239
239
  })(CrdentialLocation || (CrdentialLocation = {}));
240
- export var KnowledgebaseType;
241
- (function(KnowledgebaseType) {
242
- KnowledgebaseType["Default"] = "default";
243
- KnowledgebaseType["IntentRecog"] = "intent_recog";
244
- })(KnowledgebaseType || (KnowledgebaseType = {}));
@@ -1,4 +1,4 @@
1
- import { EnumCharacter, FileStatus, KnowledgebaseType, KnowledgePathType, KnowledgeType, ResourceStatus } from './enum';
1
+ import { EnumCharacter, FileStatus, KnowledgePathType, KnowledgeType, ResourceStatus } from './enum';
2
2
  import type { ILinkFile } from './file';
3
3
  import type { IResourcePermission, IResourcePermissionApi } from './permission';
4
4
  export interface IKnowledgeLinkFile extends ILinkFile {
@@ -101,7 +101,6 @@ export interface IKnowledgebaseApi {
101
101
  handle_type?: string[];
102
102
  };
103
103
  name: string;
104
- type?: KnowledgebaseType;
105
104
  status?: ResourceStatus;
106
105
  description?: string;
107
106
  generate_type?: EnumCharacter;
@@ -125,7 +124,6 @@ export interface IKnowledgebase {
125
124
  handleType?: string[];
126
125
  updateFrequency?: number;
127
126
  name: string;
128
- type?: KnowledgebaseType;
129
127
  status?: ResourceStatus;
130
128
  generateType?: EnumCharacter;
131
129
  pathType?: KnowledgePathType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/ai-ui-sdk",
3
- "version": "0.1.12-beta.36",
3
+ "version": "0.1.12-beta.37",
4
4
  "description": "蓝鲸AI UI SDK",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -84,10 +84,8 @@
84
84
  "@blueking/cli-service": "0.1.0-beta.24",
85
85
  "@blueking/eslint-config-bk": "2.1.0",
86
86
  "@blueking/stylelint-config-bk": "2.1.0-beta.10",
87
- "@types/markdown-it": "^14.1.2",
88
87
  "eslint-plugin-simple-import-sort": "^10.0.0",
89
88
  "typescript": "^5.5.4",
90
- "vue-tsc": "^2.2.10",
91
- "x-mavon-editor": "0.0.19-beta.1"
89
+ "vue-tsc": "^2.2.10"
92
90
  }
93
91
  }
@@ -1,137 +0,0 @@
1
- import { defineComponent as _defineComponent } from 'vue';
2
- import { unref as _unref, toDisplayString as _toDisplayString, createElementVNode as _createElementVNode, createTextVNode as _createTextVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, createBlock as _createBlock } from "vue";
3
- const _hoisted_1 = {
4
- class: "dataset-data-api-endpoint g-mt-12"
5
- };
6
- const _hoisted_2 = [
7
- "data-clipboard-text"
8
- ];
9
- import { ref, toRef, watch } from 'vue';
10
- import RenderMarkdown from '../../../../render-markdown/mark-down.ts.js';
11
- import { useDatasetHttp } from '../../../../../hooks/use-dataset-http.ts.js';
12
- import { DatasetDataSourceType } from '../../../../../types/enum.ts.js';
13
- export default /*@__PURE__*/ _defineComponent({
14
- props: {
15
- modelValue: {},
16
- apiPrefix: {},
17
- spaceId: {}
18
- },
19
- setup (__props) {
20
- const props = __props;
21
- // 接口 hook
22
- const { getDatasetApiGuide } = useDatasetHttp(props.apiPrefix, toRef(props, 'spaceId'));
23
- // 状态
24
- const loading = ref(false);
25
- const datasetApiGuide = ref();
26
- // 获取数据集 API 指引
27
- const handleGetDatasetApiGuide = ()=>{
28
- // 如果不是 API 上报或者没有数据集 ID,则不请求
29
- if (!props.modelValue.datasetId || props.modelValue.sourceType !== DatasetDataSourceType.ApiReport) return;
30
- // 发起请求
31
- loading.value = true;
32
- getDatasetApiGuide(props.modelValue.datasetId).then((data)=>{
33
- datasetApiGuide.value = data;
34
- }).finally(()=>{
35
- loading.value = false;
36
- });
37
- };
38
- // 触发获取数据集 API 指引
39
- watch([
40
- ()=>props.modelValue.datasetId,
41
- ()=>props.modelValue.sourceType
42
- ], handleGetDatasetApiGuide, {
43
- immediate: true
44
- });
45
- return (_ctx, _cache)=>{
46
- const _component_bk_form_item = _resolveComponent("bk-form-item");
47
- const _component_bk_table_column = _resolveComponent("bk-table-column");
48
- const _component_bk_table = _resolveComponent("bk-table");
49
- const _component_bk_loading = _resolveComponent("bk-loading");
50
- const _component_bk_form = _resolveComponent("bk-form");
51
- return _ctx.modelValue.sourceType === _unref(DatasetDataSourceType).ApiReport ? (_openBlock(), _createBlock(_component_bk_form, {
52
- key: 0,
53
- class: "g-small-form",
54
- "form-type": "vertical"
55
- }, {
56
- default: _withCtx(()=>[
57
- _createVNode(_component_bk_loading, {
58
- loading: loading.value,
59
- "z-index": 1502
60
- }, {
61
- default: _withCtx(()=>[
62
- _ctx.modelValue.datasetId && datasetApiGuide.value ? (_openBlock(), _createElementBlock(_Fragment, {
63
- key: 0
64
- }, [
65
- _createVNode(_component_bk_form_item, null, {
66
- default: _withCtx(()=>[
67
- _createElementVNode("section", _hoisted_1, [
68
- _createTextVNode(" 上报 API 地址:" + _toDisplayString(datasetApiGuide.value.apiEndpoint) + " ", 1 /* TEXT */ ),
69
- _createElementVNode("i", {
70
- class: "ai-ui-sdk-icon ai-ui-sdk-copy click-copy g-cursor-pointer g-ml-6",
71
- "data-clipboard-text": datasetApiGuide.value.apiEndpoint
72
- }, null, 8 /* PROPS */ , _hoisted_2)
73
- ])
74
- ]),
75
- _: 1 /* STABLE */
76
- }),
77
- _createVNode(_component_bk_form_item, {
78
- label: "上报参数"
79
- }, {
80
- default: _withCtx(()=>[
81
- _createVNode(_component_bk_table, {
82
- "show-overflow-tooltip": "",
83
- "empty-cell-text": "--",
84
- border: [
85
- 'row',
86
- 'col',
87
- 'outer'
88
- ],
89
- data: datasetApiGuide.value.apiContent
90
- }, {
91
- default: _withCtx(()=>[
92
- _createVNode(_component_bk_table_column, {
93
- label: "参数名",
94
- field: "paramName"
95
- }),
96
- _createVNode(_component_bk_table_column, {
97
- label: "参数类型",
98
- field: "paramType"
99
- }),
100
- _createVNode(_component_bk_table_column, {
101
- label: "描述",
102
- field: "paramDesc"
103
- })
104
- ]),
105
- _: 1 /* STABLE */
106
- }, 8 /* PROPS */ , [
107
- "data"
108
- ])
109
- ]),
110
- _: 1 /* STABLE */
111
- }),
112
- _createVNode(_component_bk_form_item, {
113
- label: "上报示例",
114
- class: "g-last-form-item"
115
- }, {
116
- default: _withCtx(()=>[
117
- _createVNode(_unref(RenderMarkdown), {
118
- class: "dataset-data-api-demo",
119
- value: datasetApiGuide.value.apiDemo
120
- }, null, 8 /* PROPS */ , [
121
- "value"
122
- ])
123
- ]),
124
- _: 1 /* STABLE */
125
- })
126
- ], 64 /* STABLE_FRAGMENT */ )) : _createCommentVNode("v-if", true)
127
- ]),
128
- _: 1 /* STABLE */
129
- }, 8 /* PROPS */ , [
130
- "loading"
131
- ])
132
- ]),
133
- _: 1 /* STABLE */
134
- })) : _createCommentVNode("v-if", true);
135
- };
136
- }
137
- });
@@ -1,10 +0,0 @@
1
-
2
- .dataset-data-api-endpoint[data-v-dkam4g7l] {
3
- line-height: 44px;
4
- background: #F5F7FA;
5
- border-radius: 2px;
6
- padding: 0 12px;
7
- }
8
- [data-v-dkam4g7l] .dataset-data-api-demo .v-show-content {
9
- padding: 0 !important;
10
- }
@@ -1,8 +0,0 @@
1
- import type { IDatasetDataForm } from '@/types/dataset';
2
- interface IProps {
3
- modelValue: IDatasetDataForm;
4
- apiPrefix: string;
5
- spaceId?: string;
6
- }
7
- declare const _default: import("vue").DefineComponent<IProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<IProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
8
- export default _default;
@@ -1,5 +0,0 @@
1
- import script from './api.script.vue.js.js';
2
- script.__scopeId = "data-v-dkam4g7l";
3
- script.__file = "./src/components/render-dataset/components/plus-dataset-data/form/api.vue";
4
- import './api.vue.css';
5
- export default script;
@@ -1,2 +0,0 @@
1
- import type MarkdownIt from 'markdown-it';
2
- export declare const MarkDownCodePlugin: (markdownIt: MarkdownIt) => void;
@@ -1,171 +0,0 @@
1
- const languageSuffixMap = {
2
- c: '.c',
3
- 'c++': '.cpp',
4
- java: '.java',
5
- python: '.py',
6
- html: '.html',
7
- css: '.css',
8
- javascript: '.js',
9
- js: '.js',
10
- php: '.php',
11
- ruby: '.rb',
12
- swift: '.swift',
13
- go: '.go',
14
- perl: '.pl',
15
- sql: '.sql',
16
- xml: '.xml',
17
- json: '.json',
18
- vue: '.vue',
19
- rust: '.rs',
20
- jsx: '.jsx',
21
- tsx: '.tsx',
22
- typescript: '.ts',
23
- ts: '.ts',
24
- bash: '.sh'
25
- };
26
- const getLanguageSuffix = (name)=>languageSuffixMap[name.toLowerCase()] || '.txt';
27
- let originalFence;
28
- // 自定义代码块
29
- export const MarkDownCodePlugin = (markdownIt)=>{
30
- // 如果 originalFence 不存在,则获取原始的 fence 函数,防止嵌套调用
31
- if (!originalFence) {
32
- originalFence = markdownIt.renderer.rules.fence;
33
- }
34
- // 重写 fence 规则
35
- markdownIt.block.ruler.at('fence', (state, startLine, endLine, silent)=>{
36
- let pos = state.bMarks[startLine] + state.tShift[startLine];
37
- let max = state.eMarks[startLine];
38
- // 检查是否缩进过多
39
- if (state.sCount[startLine] - state.blkIndent >= 4) {
40
- return false;
41
- }
42
- // 检查是否有足够的字符
43
- if (pos + 3 > max) {
44
- return false;
45
- }
46
- const marker = state.src.charCodeAt(pos);
47
- // 检查是否是有效的标记字符
48
- if (marker !== 0x7E /* ~ */ && marker !== 0x60 /* ` */ ) {
49
- return false;
50
- }
51
- // 获取标记的长度
52
- let mem = pos;
53
- pos = state.skipChars(pos, marker);
54
- const len = pos - mem;
55
- if (len < 3) {
56
- return false;
57
- }
58
- const markup = state.src.slice(mem, pos);
59
- const params = state.src.slice(pos, max);
60
- // 检查参数中是否包含标记字符
61
- if (marker === 0x60 /* ` */ ) {
62
- if (params.indexOf(String.fromCharCode(marker)) >= 0) {
63
- return false;
64
- }
65
- }
66
- // 验证模式直接返回
67
- if (silent) {
68
- return true;
69
- }
70
- // 寻找结束标记
71
- let nextLine = startLine;
72
- let haveEndMarker = false;
73
- for(;;){
74
- nextLine += 1;
75
- if (nextLine >= endLine) {
76
- break;
77
- }
78
- pos = state.bMarks[nextLine] + state.tShift[nextLine];
79
- mem = pos;
80
- max = state.eMarks[nextLine];
81
- if (pos < max && state.sCount[nextLine] < state.blkIndent) {
82
- break;
83
- }
84
- // 如果不是标记字符,继续
85
- if (state.src.charCodeAt(pos) !== marker) {
86
- continue;
87
- }
88
- // 检查标记长度
89
- if (state.sCount[nextLine] - state.blkIndent >= 4) {
90
- continue;
91
- }
92
- pos = state.skipChars(pos, marker);
93
- // 结束标记必须至少和开始标记一样长
94
- if (pos - mem < len) {
95
- continue;
96
- }
97
- // 检查标记后是否只有空格
98
- pos = state.skipSpaces(pos);
99
- if (pos < max) {
100
- continue;
101
- }
102
- haveEndMarker = true;
103
- break;
104
- }
105
- // 设置结束行
106
- state.line = nextLine + (haveEndMarker ? 1 : 0);
107
- // 创建 token
108
- const token = state.push('fence', 'code', 0);
109
- token.info = params;
110
- token.content = state.getLines(startLine + 1, nextLine, state.sCount[startLine], true);
111
- token.markup = markup;
112
- token.map = [
113
- startLine,
114
- state.line
115
- ];
116
- token.haveEndMarker = haveEndMarker;
117
- return true;
118
- }, {
119
- alt: [
120
- 'paragraph',
121
- 'reference',
122
- 'blockquote',
123
- 'list'
124
- ]
125
- });
126
- // 自定义代码块渲染
127
- markdownIt.renderer.rules.fence = (tokens, idx, options, env, self)=>{
128
- const token = tokens[idx];
129
- const hasEndBlock = token.haveEndMarker;
130
- let language = token.info.trim();
131
- let code = token.content;
132
- // 原始渲染
133
- const originalCode = originalFence(tokens, idx, options, env, self);
134
- // 1. 如果代码块和语言不为空,则渲染代码块
135
- if (code.trim() && language && hasEndBlock) {
136
- const encodeCode = encodeURIComponent(code);
137
- return `<section class="full-screen-wrap markdown-body" style="background-color: #2e2e2e;">
138
- <section class="code-header g-flex-row">
139
- <span>${language}</span>
140
- <span class="g-flex-row">
141
- <i class="ai-ui-sdk-icon ai-ui-sdk-un-full-screen click-un-full-screen"></i>
142
- <i class="ai-ui-sdk-icon ai-ui-sdk-full-screen click-full-screen"></i>
143
- <i class="ai-ui-sdk-icon ai-ui-sdk-copy click-copy" data-clipboard-text="${encodeCode}"></i>
144
- <i class="ai-ui-sdk-icon ai-ui-sdk-dongzuo-xiazai click-download" data-clipboard-text="${encodeCode}" data-file-name="ai${getLanguageSuffix(language)}"></i>
145
- </span>
146
- </section>
147
- ${originalCode}
148
- </section>`;
149
- }
150
- // 2. 如果有结束标记并且有代码内容,则返回原始代码块
151
- if (code.trim() && hasEndBlock) {
152
- return originalCode;
153
- }
154
- // 3. 否则返回原始内容
155
- // 开始标记
156
- const start = token.markup;
157
- // 结束标记
158
- let end = '';
159
- // 如果代码块长度大于行数,则添加结束标记(markdown不封闭语法)
160
- if (hasEndBlock) {
161
- end = '```';
162
- }
163
- // 如果代码块不为空,则添加换行符
164
- if (code) {
165
- code = code.replace(/\n/g, '<br>');
166
- }
167
- language = `${language}<br>`;
168
- // 返回原始字符串
169
- return `${start}${language}${code}${end}`;
170
- };
171
- };
@@ -1,2 +0,0 @@
1
- import type MarkdownIt from 'markdown-it';
2
- export declare const MarkDownEmojiPlugin: (markdownIt: MarkdownIt) => void;
@@ -1,4 +0,0 @@
1
- // 关闭emoji
2
- export const MarkDownEmojiPlugin = (markdownIt)=>{
3
- markdownIt.core.ruler.disable('emoji');
4
- };
@@ -1,49 +0,0 @@
1
- import type MarkdownIt from 'markdown-it';
2
- import 'x-mavon-editor/dist/css/index.css';
3
- import 'x-mavon-editor/dist/highlightjs/styles/atom-one-dark.min.css';
4
- import './mark-down.postcss';
5
- export type MdProp = {
6
- modelValue?: string;
7
- codeStyle?: string;
8
- previewBackground?: string;
9
- defaultOpen: string;
10
- editable: boolean;
11
- subfield: boolean;
12
- toolbarsFlag: boolean;
13
- boxShadow: boolean;
14
- ref?: (elm: MdRef) => void;
15
- xssOptions: {
16
- whiteList: {
17
- [key: string]: string[];
18
- };
19
- };
20
- externalLink: {
21
- [key: string]: (param?: string) => string;
22
- };
23
- };
24
- type MdRef = {
25
- $paste: () => void;
26
- markdownIt: MarkdownIt;
27
- };
28
- declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
29
- value: {
30
- type: StringConstructor;
31
- };
32
- previewBackground: {
33
- type: StringConstructor;
34
- default: string;
35
- };
36
- }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
37
- [key: string]: any;
38
- }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
39
- value: {
40
- type: StringConstructor;
41
- };
42
- previewBackground: {
43
- type: StringConstructor;
44
- default: string;
45
- };
46
- }>> & Readonly<{}>, {
47
- previewBackground: string;
48
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
49
- export default _default;