@gct-paas/core-web 0.1.4-dev.8 → 0.1.4-dev.9

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 (118) hide show
  1. package/dist/index-BghCpvxN.js +76 -0
  2. package/dist/index-PLrMc0gl.cjs +76 -0
  3. package/dist/index-oVPMi6Ep.js +29160 -0
  4. package/dist/index.esm.min.mjs +34 -24962
  5. package/dist/index.min.cjs +1 -67
  6. package/dist/index.min.css +1 -1
  7. package/dist/index.system.min.js +1 -67
  8. package/dist/monaco-editor-B8X-ou0h.js +20245 -0
  9. package/dist/monaco-editor-Bdgpd_KL.cjs +19 -0
  10. package/dist/monaco-editor-NIWDtQNB.js +19 -0
  11. package/es/_virtual/_plugin-vue_export-helper.mjs +9 -0
  12. package/es/components/app-modal/app-modal-component.css +149 -0
  13. package/es/components/app-modal/app-modal-component.d.ts +26 -0
  14. package/es/components/app-modal/app-modal-component.mjs +140 -0
  15. package/es/components/base-button/base-button.css +74 -0
  16. package/es/components/base-button/base-button.vue.d.ts +173 -0
  17. package/es/components/base-button/base-button.vue.mjs +7 -0
  18. package/es/components/base-button/base-button.vue3.mjs +179 -0
  19. package/es/components/basic-button/basic-button.css +25 -0
  20. package/es/components/basic-button/basic-button.vue.d.ts +100 -0
  21. package/es/components/basic-button/basic-button.vue.mjs +7 -0
  22. package/es/components/basic-button/basic-button.vue3.mjs +130 -0
  23. package/es/components/code-editor/code-editor.d.ts +1 -1
  24. package/es/components/index.d.ts +10 -1
  25. package/es/components/index.mjs +22 -0
  26. package/es/components/layout/flex-container/flex-container.mjs +94 -0
  27. package/es/components/layout/flex-item/flex-item.mjs +55 -0
  28. package/es/components/layout/grid-container/grid-container.mjs +51 -0
  29. package/es/components/layout/view-container/view-container.mjs +38 -0
  30. package/es/components/svg-icon/svg-icon.css +73 -0
  31. package/es/components/svg-icon/svg-icon.vue.d.ts +40 -0
  32. package/es/components/svg-icon/svg-icon.vue.mjs +50 -0
  33. package/es/components/svg-icon/svg-icon.vue3.mjs +6 -0
  34. package/es/create-app-vue.d.ts +9 -0
  35. package/es/create-app-vue.mjs +17 -0
  36. package/es/directives/drag-resize.d.ts +4 -0
  37. package/es/directives/drag-resize.mjs +42 -0
  38. package/es/directives/index.d.ts +8 -0
  39. package/es/directives/index.mjs +9 -0
  40. package/es/directives/target-loading.d.ts +4 -0
  41. package/es/directives/target-loading.mjs +40 -0
  42. package/es/hooks/index.d.ts +1 -0
  43. package/es/hooks/useDragLine.d.ts +6 -0
  44. package/es/hooks/useDragLine.mjs +79 -0
  45. package/es/index.d.ts +5 -4
  46. package/es/index.mjs +29 -13
  47. package/es/modules/code-editor/index.d.ts +163 -0
  48. package/es/modules/code-editor/index.mjs +8 -0
  49. package/es/modules/code-editor/monaco-editor.css +49 -0
  50. package/es/modules/code-editor/monaco-editor.vue.d.ts +143 -0
  51. package/es/modules/code-editor/monaco-editor.vue.mjs +7 -0
  52. package/es/modules/code-editor/monaco-editor.vue2.mjs +440 -0
  53. package/es/modules/code-editor/useEditorConsole.d.ts +54 -0
  54. package/es/modules/code-editor/useEditorConsole.mjs +194 -0
  55. package/es/modules/code-editor/useMonacoEditor.d.ts +26 -0
  56. package/es/modules/code-editor/useMonacoEditor.mjs +26 -0
  57. package/es/modules/color-picker/index.d.ts +2 -0
  58. package/es/modules/color-picker/src/ColorPicker.css +16 -0
  59. package/es/modules/color-picker/src/ColorPicker.vue.d.ts +49 -0
  60. package/es/modules/color-picker/src/ColorPicker.vue.mjs +8 -0
  61. package/es/modules/color-picker/src/ColorPicker.vue2.mjs +545 -0
  62. package/es/modules/color-picker/src/ColorPicker2.css +156 -0
  63. package/es/modules/gct-dnd/constants/index.d.ts +7 -9
  64. package/es/modules/gct-dnd/constants/index.mjs +18 -7
  65. package/es/modules/global-modal/index.d.ts +5 -0
  66. package/es/modules/global-modal/index.mjs +16 -0
  67. package/es/modules/global-modal/src/BasicModal.vue.d.ts +518 -0
  68. package/es/modules/global-modal/src/BasicModal.vue.mjs +221 -0
  69. package/es/modules/global-modal/src/BasicModal.vue2.mjs +5 -0
  70. package/es/modules/global-modal/src/components/GlboalModal.d.ts +251 -0
  71. package/es/modules/global-modal/src/components/GlboalModal.mjs +40 -0
  72. package/es/modules/global-modal/src/components/ModalClose.css +95 -0
  73. package/es/modules/global-modal/src/components/ModalClose.vue.d.ts +27 -0
  74. package/es/modules/global-modal/src/components/ModalClose.vue.mjs +79 -0
  75. package/es/modules/global-modal/src/components/ModalClose.vue3.mjs +6 -0
  76. package/es/modules/global-modal/src/components/ModalFooter.vue.d.ts +270 -0
  77. package/es/modules/global-modal/src/components/ModalFooter.vue.mjs +44 -0
  78. package/es/modules/global-modal/src/components/ModalFooter.vue2.mjs +5 -0
  79. package/es/modules/global-modal/src/components/ModalHeader.vue.d.ts +17 -0
  80. package/es/modules/global-modal/src/components/ModalHeader.vue.mjs +11 -0
  81. package/es/modules/global-modal/src/components/ModalHeader.vue2.mjs +13 -0
  82. package/es/modules/global-modal/src/components/ModalWrapper.vue.d.ts +95 -0
  83. package/es/modules/global-modal/src/components/ModalWrapper.vue.mjs +26 -0
  84. package/es/modules/global-modal/src/components/ModalWrapper.vue2.mjs +136 -0
  85. package/es/modules/global-modal/src/hooks/useModal.d.ts +6 -0
  86. package/es/modules/global-modal/src/hooks/useModal.mjs +120 -0
  87. package/es/modules/global-modal/src/hooks/useModalContext.d.ts +5 -0
  88. package/es/modules/global-modal/src/hooks/useModalContext.mjs +11 -0
  89. package/es/modules/global-modal/src/hooks/useModalDrag.d.ts +7 -0
  90. package/es/modules/global-modal/src/hooks/useModalDrag.mjs +82 -0
  91. package/es/modules/global-modal/src/hooks/useModalFullScreen.d.ts +11 -0
  92. package/es/modules/global-modal/src/hooks/useModalFullScreen.mjs +16 -0
  93. package/es/modules/global-modal/src/index.css +153 -0
  94. package/es/modules/global-modal/src/props.d.ts +156 -0
  95. package/es/modules/global-modal/src/props.mjs +57 -0
  96. package/es/modules/global-modal/src/typing.d.ts +174 -0
  97. package/es/modules/target-loading/index.d.ts +4 -0
  98. package/es/modules/target-loading/src/createLoading.d.ts +13 -0
  99. package/es/modules/target-loading/src/createLoading.mjs +57 -0
  100. package/es/modules/target-loading/src/target-loading.css +18 -0
  101. package/es/modules/target-loading/src/target-loading.vue.d.ts +57 -0
  102. package/es/modules/target-loading/src/target-loading.vue.mjs +52 -0
  103. package/es/modules/target-loading/src/target-loading.vue3.mjs +7 -0
  104. package/es/modules/target-loading/src/typing.d.ts +9 -0
  105. package/es/modules/target-loading/src/useLoading.d.ts +9 -0
  106. package/es/setup-app.d.ts +1 -0
  107. package/es/setup-app.mjs +4 -0
  108. package/es/types/index.d.ts +190 -0
  109. package/es/utils/index.d.ts +4 -1
  110. package/es/utils/message-util/message-util.d.ts +7 -0
  111. package/es/utils/message-util/message-util.mjs +26 -0
  112. package/es/utils/monaco-loader/monaco-loader.d.ts +59 -0
  113. package/es/utils/monaco-loader/monaco-loader.mjs +88 -0
  114. package/es/utils/overlay-controller/overlay-controller.d.ts +18 -0
  115. package/es/utils/overlay-controller/overlay-controller.mjs +23 -0
  116. package/es/widgets/gct-edit-form/gct-edit-form.d.ts +1 -1
  117. package/es/widgets/gct-form/gct-form-collapse/gct-form-collapse.d.ts +1 -1
  118. package/package.json +14 -6
@@ -0,0 +1,440 @@
1
+ import { defineComponent, ref, watch, computed, onMounted, onUnmounted, resolveComponent, openBlock, createElementBlock, renderSlot, createElementVNode, createVNode, normalizeStyle, withCtx, createTextVNode, toDisplayString, unref, createBlock, normalizeClass, createCommentVNode } from 'vue';
2
+ import { SearchOutlined, UpCircleOutlined, DownCircleOutlined, FormatPainterOutlined, CloudDownloadOutlined, ClearOutlined, RobotOutlined } from '@ant-design/icons-vue';
3
+ import { Theme } from './useMonacoEditor.mjs';
4
+ import { format } from 'sql-formatter';
5
+ import 'ant-design-vue';
6
+ import { monacoLoader } from '../../utils/monaco-loader/monaco-loader.mjs';
7
+ import 'lodash-es';
8
+ import '@gct-paas/core';
9
+ import 'vue3-dnd';
10
+ import 'react-dnd-html5-backend';
11
+ import '../../components/app-modal/app-modal-component.css';/* empty css */
12
+
13
+ const _hoisted_1 = { class: "hex-monaco-editor m-e w-full h-full overflow-hidden" };
14
+ const _hoisted_2 = { class: "m-e-main" };
15
+ const _sfc_main = /* @__PURE__ */ defineComponent({
16
+ __name: "monaco-editor",
17
+ props: {
18
+ value: { default: "" },
19
+ title: { default: "" },
20
+ language: { default: "typescript" },
21
+ theme: { default: Theme.DARK },
22
+ readonly: { type: Boolean, default: false },
23
+ direction: { default: "bottom" },
24
+ gapVal: { default: 20 }
25
+ },
26
+ emits: [
27
+ "update:value",
28
+ "change",
29
+ "editor-mounted",
30
+ "blur",
31
+ "focus",
32
+ "chat-bot-click"
33
+ ],
34
+ setup(__props, { expose: __expose, emit: __emit }) {
35
+ const props = __props;
36
+ const isMonacoReady = ref(false);
37
+ let monaco = null;
38
+ watch(
39
+ () => props.language,
40
+ async (newVal) => {
41
+ if (monacoEditor && monacoEditor.getModel() && monaco) {
42
+ monaco.editor.setModelLanguage(monacoEditor.getModel(), newVal);
43
+ }
44
+ }
45
+ );
46
+ const emit = __emit;
47
+ const Editor = ref();
48
+ let monacoEditor;
49
+ const wordWrap = ref(true);
50
+ const fullScreen = ref(false);
51
+ const isThemeLightOrBlack = ref(false);
52
+ const isChatBotActive = ref(false);
53
+ const isRagEnabled = ref(false);
54
+ const getStyle = computed(() => {
55
+ return {
56
+ color: isThemeLightOrBlack.value ? "#000" : "#fff",
57
+ marginRight: props.gapVal + "px"
58
+ };
59
+ });
60
+ if (props.theme === Theme.VS) {
61
+ isThemeLightOrBlack.value = true;
62
+ }
63
+ let option = {
64
+ value: props.value ?? "",
65
+ // 编辑器内容
66
+ language: props.language,
67
+ automaticLayout: true,
68
+ // 是否自动布局
69
+ theme: props.theme,
70
+ readOnly: props.readonly,
71
+ wordWrap: wordWrap.value ? "on" : "off",
72
+ // 当单行文本太长时截断换行,true 为换行,false 为不换行
73
+ scrollBeyondLastLine: false,
74
+ // 滚动完最后一行后再滚动一屏幕
75
+ // 是否开启小地图
76
+ minimap: {
77
+ enabled: true
78
+ },
79
+ tabSize: 2,
80
+ // tab缩进长度
81
+ autoClosingBrackets: "always",
82
+ // 是否自动添加结束括号(包括中括号) "always" | "languageDefined" | "beforeWhitespace" | "never"
83
+ autoClosingDelete: "always",
84
+ // 是否自动删除结束括号(包括中括号) "always" | "never" | "auto"
85
+ autoClosingOvertype: "always",
86
+ // 是否关闭改写 即使用insert模式时是覆盖后面的文字还是不覆盖后面的文字 "always" | "never" | "auto"
87
+ autoClosingQuotes: "always",
88
+ // 是否自动添加结束的单引号 双引号 "always" | "languageDefined" | "beforeWhitespace" | "never"
89
+ comments: {
90
+ ignoreEmptyLines: true,
91
+ // 插入行注释时忽略空行。默认为真。
92
+ insertSpace: true
93
+ // 在行注释标记之后和块注释标记内插入一个空格。默认为真。
94
+ },
95
+ // 注释配置
96
+ columnSelection: false,
97
+ // 启用列编辑 按下shift键位然后按↑↓键位可以实现列选择 然后实现列编辑
98
+ folding: true,
99
+ // 是否启用代码折叠
100
+ fixedOverflowWidgets: true,
101
+ // 超出编辑器大小的使用fixed属性显示
102
+ // 编辑器悬停配置
103
+ hover: {
104
+ sticky: true,
105
+ // 悬停是否粘滞,可以点击并选择其内容
106
+ above: false
107
+ // 悬停是否应该显示在直线上方
108
+ }
109
+ };
110
+ async function init() {
111
+ monaco = await monacoLoader.loadMonaco();
112
+ dispose();
113
+ initEditor();
114
+ if (props.value) {
115
+ handleFormatCodeClick();
116
+ }
117
+ }
118
+ async function onInit() {
119
+ const bol = await _api.apaas.basicConfig.getAiRagEnabled();
120
+ if (bol == true) {
121
+ isRagEnabled.value = true;
122
+ } else {
123
+ isRagEnabled.value = false;
124
+ }
125
+ }
126
+ function initEditor() {
127
+ if (!monaco) {
128
+ console.warn(
129
+ "[MonacoEditor] Monaco editor is not available for initEditor"
130
+ );
131
+ return;
132
+ }
133
+ monacoEditor = monaco.editor.create(Editor.value, option);
134
+ if (props.direction === "bottom") {
135
+ scrollToBottom();
136
+ } else if (props.direction === "top") {
137
+ scrollToTop();
138
+ }
139
+ monacoEditor.onDidChangeModelContent(() => {
140
+ emit("change", getEditorContent());
141
+ emit("update:value", getEditorContent());
142
+ });
143
+ monacoEditor.onDidBlurEditorText(() => {
144
+ emit("blur", getEditorContent());
145
+ emit("update:value", getEditorContent());
146
+ });
147
+ monacoEditor.onDidFocusEditorText(() => {
148
+ emit("focus");
149
+ });
150
+ isMonacoReady.value = true;
151
+ emit("editor-mounted", monacoEditor);
152
+ }
153
+ function setEditorContent(val) {
154
+ monacoEditor.setValue(val);
155
+ emit("change", getEditorContent());
156
+ emit("update:value", getEditorContent());
157
+ }
158
+ function getEditorContent() {
159
+ return monacoEditor.getValue();
160
+ }
161
+ function getEditorMarkers() {
162
+ if (!monaco) {
163
+ console.warn(
164
+ "[MonacoEditor] Monaco editor is not available for getEditorMarkers"
165
+ );
166
+ return [];
167
+ }
168
+ const model = monacoEditor.getModel();
169
+ if (!model) {
170
+ return [];
171
+ }
172
+ return monaco.editor.getModelMarkers({ resource: model.uri });
173
+ }
174
+ function findByKeyword() {
175
+ if (!monaco) {
176
+ console.warn(
177
+ "[MonacoEditor] Monaco editor is not available for findByKeyword"
178
+ );
179
+ return;
180
+ }
181
+ try {
182
+ monacoEditor.focus();
183
+ monacoEditor.setSelection(new monaco.Range(1, 9999, 1, 1e4));
184
+ monacoEditor.trigger("", "actions.find", null);
185
+ } catch (error) {
186
+ console.error(error);
187
+ }
188
+ }
189
+ function scrollToTop() {
190
+ monacoEditor.setScrollPosition({ scrollTop: 0 });
191
+ }
192
+ function scrollToBottom() {
193
+ monacoEditor.revealLine(monacoEditor.getModel().getLineCount());
194
+ }
195
+ function setEditorWordWrap() {
196
+ wordWrap.value = !wordWrap.value;
197
+ if (wordWrap.value) {
198
+ monacoEditor.updateOptions({ wordWrap: "on" });
199
+ } else {
200
+ monacoEditor.updateOptions({ wordWrap: "off" });
201
+ }
202
+ }
203
+ function setEditorTheme() {
204
+ isThemeLightOrBlack.value = !isThemeLightOrBlack.value;
205
+ if (isThemeLightOrBlack.value) {
206
+ monacoEditor.updateOptions({ theme: "vs" });
207
+ } else {
208
+ monacoEditor.updateOptions({ theme: "vs-dark" });
209
+ }
210
+ }
211
+ function handleFullScreenClick() {
212
+ if (!Editor.value.fullscreenElement) {
213
+ Editor.value.requestFullscreen();
214
+ fullScreen.value = true;
215
+ } else {
216
+ Editor.value.exitFullscreen();
217
+ fullScreen.value = false;
218
+ }
219
+ }
220
+ function handleDownloadLogClick() {
221
+ exportFile(props.title, monacoEditor.getValue());
222
+ }
223
+ function exportFile(name, data) {
224
+ const url = window.URL || window.webkitURL || window;
225
+ const blob = new Blob([data]);
226
+ const event = document.createEvent("MouseEvents");
227
+ event.initMouseEvent(
228
+ "click",
229
+ true,
230
+ false,
231
+ window,
232
+ 0,
233
+ 0,
234
+ 0,
235
+ 0,
236
+ 0,
237
+ false,
238
+ false,
239
+ false,
240
+ false,
241
+ 0,
242
+ null
243
+ );
244
+ const link = document.createElementNS(
245
+ "http://www.w3.org/1999/xhtml",
246
+ "a"
247
+ );
248
+ link.href = url.createObjectURL(blob);
249
+ link.download = name;
250
+ link.dispatchEvent(event);
251
+ }
252
+ function handleFormatCodeClick() {
253
+ if (props.language == "sql") {
254
+ const sqlContent = getEditorContent();
255
+ const formattedSql = format(sqlContent);
256
+ monacoEditor.setValue(formattedSql);
257
+ } else {
258
+ monacoEditor.getAction("editor.action.formatDocument").run();
259
+ }
260
+ const newVal = getEditorContent();
261
+ emit("change", newVal);
262
+ emit("update:value", newVal);
263
+ }
264
+ function handleClearClick() {
265
+ setEditorContent("");
266
+ }
267
+ function handleChatBotClick() {
268
+ isChatBotActive.value = !isChatBotActive.value;
269
+ emit("chat-bot-click");
270
+ }
271
+ function dispose() {
272
+ if (monacoEditor) {
273
+ monacoEditor.dispose();
274
+ }
275
+ }
276
+ function getMonacoEditor() {
277
+ return monacoEditor;
278
+ }
279
+ onMounted(() => {
280
+ init();
281
+ });
282
+ onUnmounted(() => {
283
+ dispose();
284
+ });
285
+ function setValue(code) {
286
+ const model = monacoEditor.getModel();
287
+ if (!model) return;
288
+ const fullRange = model.getFullModelRange();
289
+ monacoEditor.executeEdits("setValue", [
290
+ {
291
+ range: fullRange,
292
+ text: code,
293
+ forceMoveMarkers: false
294
+ }
295
+ ]);
296
+ emit("change", getEditorContent());
297
+ emit("update:value", getEditorContent());
298
+ }
299
+ function getValue() {
300
+ return monacoEditor.getValue();
301
+ }
302
+ function getSelectCode() {
303
+ const selection = monacoEditor.getSelection();
304
+ if (selection) {
305
+ const text = monacoEditor.getModel()?.getValueInRange(selection);
306
+ const startLineNumber = selection.startLineNumber;
307
+ const startColumn = selection.startColumn;
308
+ const endLineNumber = selection.endLineNumber;
309
+ const endColumn = selection.endColumn;
310
+ const textBeforeRange = {
311
+ startLineNumber: 1,
312
+ startColumn: 1,
313
+ endLineNumber: startLineNumber,
314
+ endColumn: startColumn
315
+ };
316
+ const textBefore = monacoEditor.getModel().getValueInRange(textBeforeRange);
317
+ const textAfterRange = {
318
+ startLineNumber: endLineNumber,
319
+ startColumn: endColumn,
320
+ endLineNumber: monacoEditor.getModel().getLineCount(),
321
+ endColumn: monacoEditor.getModel().getLineMaxColumn(monacoEditor.getModel().getLineCount())
322
+ };
323
+ const textAfter = monacoEditor.getModel().getValueInRange(textAfterRange);
324
+ return {
325
+ text,
326
+ textBefore,
327
+ textAfter
328
+ };
329
+ }
330
+ return {};
331
+ }
332
+ onInit();
333
+ __expose({
334
+ isMonacoReady,
335
+ reload(newVal) {
336
+ if (monacoEditor == null) {
337
+ console.warn("[MonacoEditor] Monaco editor is not available for reload");
338
+ return;
339
+ }
340
+ monacoEditor.setValue(newVal || "");
341
+ },
342
+ getMonacoEditor,
343
+ setEditorContent,
344
+ getEditorContent,
345
+ scrollToTop,
346
+ scrollToBottom,
347
+ setEditorWordWrap,
348
+ setEditorTheme,
349
+ handleFullScreenClick,
350
+ handleDownloadLogClick,
351
+ getEditorMarkers,
352
+ handleFormatCodeClick,
353
+ getValue,
354
+ setValue,
355
+ getSelectCode,
356
+ isChatBotActive,
357
+ handleChatBotClick
358
+ });
359
+ return (_ctx, _cache) => {
360
+ const _component_a_col = resolveComponent("a-col");
361
+ const _component_a_row = resolveComponent("a-row");
362
+ return openBlock(), createElementBlock("div", _hoisted_1, [
363
+ renderSlot(_ctx.$slots, "header", {}, void 0, true),
364
+ createElementVNode("div", _hoisted_2, [
365
+ createVNode(_component_a_row, {
366
+ class: "m-e-main_toolbar w-full flex",
367
+ type: "flex",
368
+ justify: "space-between",
369
+ style: normalizeStyle(
370
+ isThemeLightOrBlack.value ? "background-color: #fff; box-shadow: 0px 2px 5px #ddd;" : "background-color: #1e1e1e; box-shadow: 0px 2px 5px #111;"
371
+ )
372
+ }, {
373
+ default: withCtx(() => [
374
+ createVNode(_component_a_col, {
375
+ class: "m-e-main_toolbar_left flex-1",
376
+ style: normalizeStyle(isThemeLightOrBlack.value ? "color: #000" : "color: #fff")
377
+ }, {
378
+ default: withCtx(() => [
379
+ createElementVNode("span", null, [
380
+ renderSlot(_ctx.$slots, "title", {}, () => [
381
+ createTextVNode(toDisplayString(__props.title), 1)
382
+ ], true)
383
+ ])
384
+ ]),
385
+ _: 3
386
+ }, 8, ["style"]),
387
+ createVNode(_component_a_col, {
388
+ class: "m-e-main_toolbar_right",
389
+ style: normalizeStyle(getStyle.value)
390
+ }, {
391
+ default: withCtx(() => [
392
+ createVNode(unref(SearchOutlined), {
393
+ class: "icon",
394
+ onClick: findByKeyword
395
+ }),
396
+ createVNode(unref(UpCircleOutlined), {
397
+ class: "icon",
398
+ onClick: scrollToTop
399
+ }),
400
+ createVNode(unref(DownCircleOutlined), {
401
+ class: "icon",
402
+ onClick: scrollToBottom
403
+ }),
404
+ createVNode(unref(FormatPainterOutlined), {
405
+ class: "icon",
406
+ onClick: handleFormatCodeClick
407
+ }),
408
+ createVNode(unref(CloudDownloadOutlined), {
409
+ class: "icon",
410
+ onClick: handleDownloadLogClick
411
+ }),
412
+ createVNode(unref(ClearOutlined), {
413
+ class: "icon",
414
+ onClick: handleClearClick
415
+ }),
416
+ isRagEnabled.value ? (openBlock(), createBlock(unref(RobotOutlined), {
417
+ key: 0,
418
+ title: "聊天机器人",
419
+ class: normalizeClass(["icon", { "icon-active": isChatBotActive.value }]),
420
+ onClick: handleChatBotClick
421
+ }, null, 8, ["class"])) : createCommentVNode("", true)
422
+ ]),
423
+ _: 1
424
+ }, 8, ["style"])
425
+ ]),
426
+ _: 3
427
+ }, 8, ["style"]),
428
+ createElementVNode("div", {
429
+ ref_key: "Editor",
430
+ ref: Editor,
431
+ class: "m-e-main_container"
432
+ }, null, 512)
433
+ ]),
434
+ renderSlot(_ctx.$slots, "footer", {}, void 0, true)
435
+ ]);
436
+ };
437
+ }
438
+ });
439
+
440
+ export { _sfc_main as default };
@@ -0,0 +1,54 @@
1
+ interface EditorConsoleState {
2
+ /** 显隐 */
3
+ visible?: boolean;
4
+ /** 输入默认值 */
5
+ defaultInput?: string;
6
+ /** tab选项卡key */
7
+ tabActiveKey?: string;
8
+ /** 索引签名,允许字符串键访问 */
9
+ [key: string]: string | boolean | undefined;
10
+ }
11
+ interface ConsoleValueState {
12
+ output: string;
13
+ error: string;
14
+ logs: unknown[];
15
+ }
16
+ export declare function useEditorConsole(props?: EditorConsoleState): {
17
+ editorConsoleState: import('vue').Ref<{
18
+ [x: string]: string | boolean | undefined;
19
+ visible?: boolean | undefined;
20
+ defaultInput?: string | undefined;
21
+ tabActiveKey?: string | undefined;
22
+ }, EditorConsoleState | {
23
+ [x: string]: string | boolean | undefined;
24
+ visible?: boolean | undefined;
25
+ defaultInput?: string | undefined;
26
+ tabActiveKey?: string | undefined;
27
+ }>;
28
+ consoleValueState: import('vue').Ref<{
29
+ output: string;
30
+ error: string;
31
+ logs: unknown[];
32
+ }, ConsoleValueState | {
33
+ output: string;
34
+ error: string;
35
+ logs: unknown[];
36
+ }>;
37
+ toggleVisible: () => void;
38
+ changeTabActiveKey: (key: string) => void;
39
+ };
40
+ export declare function useEditorConsoleInner(): {
41
+ getInstance: () => any;
42
+ showConsolePanel: () => void;
43
+ hideConsolePanel: () => void;
44
+ getInputValue: ({ showError, ignoreError }?: {
45
+ showError?: boolean | undefined;
46
+ ignoreError?: boolean | undefined;
47
+ }) => Promise<any>;
48
+ setConsoleResult: (result: IObject) => void;
49
+ formatJson2Notes: (value: unknown, options?: {
50
+ newline?: boolean;
51
+ spaceAfterColon?: boolean;
52
+ }) => string;
53
+ };
54
+ export {};
@@ -0,0 +1,194 @@
1
+ import { shallowRef, ref, watch, unref, nextTick } from 'vue';
2
+ import { isEmpty, cloneDeep } from 'lodash-es';
3
+ import 'ant-design-vue';
4
+ import { monacoLoader } from '../../utils/monaco-loader/monaco-loader.mjs';
5
+ import '@gct-paas/core';
6
+ import 'vue3-dnd';
7
+ import 'react-dnd-html5-backend';
8
+ import '../../components/app-modal/app-modal-component.css';/* empty css */
9
+
10
+ const instanceRef = shallowRef(null);
11
+ const editorConsoleState = ref({
12
+ visible: false,
13
+ defaultInput: "",
14
+ tabActiveKey: ""
15
+ });
16
+ const consoleValueState = ref({
17
+ output: "",
18
+ error: "",
19
+ logs: []
20
+ });
21
+ function useEditorConsole(props) {
22
+ watch(
23
+ () => props,
24
+ () => {
25
+ if (props) {
26
+ Object.keys(props).forEach((key) => {
27
+ editorConsoleState.value[key] = unref(props[key]);
28
+ });
29
+ }
30
+ },
31
+ { immediate: true }
32
+ );
33
+ watch(
34
+ () => unref(editorConsoleState).visible,
35
+ async (visible) => {
36
+ await nextTick();
37
+ if (visible && !unref(instanceRef)) {
38
+ const monaco = await monacoLoader.loadMonaco();
39
+ instanceRef.value = monaco.editor.create(
40
+ document.querySelector(".editor-console__input"),
41
+ {
42
+ value: props?.defaultInput,
43
+ language: "json",
44
+ automaticLayout: true,
45
+ minimap: {
46
+ enabled: false
47
+ }
48
+ }
49
+ );
50
+ }
51
+ }
52
+ );
53
+ function toggleVisible() {
54
+ editorConsoleState.value.visible = !unref(editorConsoleState).visible;
55
+ }
56
+ function changeTabActiveKey(key) {
57
+ editorConsoleState.value.tabActiveKey = key;
58
+ }
59
+ return {
60
+ editorConsoleState,
61
+ consoleValueState,
62
+ toggleVisible,
63
+ changeTabActiveKey
64
+ };
65
+ }
66
+ function useEditorConsoleInner() {
67
+ const getInstance = () => {
68
+ const instance = unref(instanceRef);
69
+ if (!instance) {
70
+ console.warn("useEditorConsoleInner instance is undefined!");
71
+ }
72
+ return instance;
73
+ };
74
+ function showConsolePanel() {
75
+ editorConsoleState.value.visible = true;
76
+ }
77
+ function hideConsolePanel() {
78
+ editorConsoleState.value.visible = false;
79
+ }
80
+ async function getInputValue({ showError = true, ignoreError = false } = {}) {
81
+ const monaco = await monacoLoader.loadMonaco();
82
+ const errs = monaco.editor.getModelMarkers({
83
+ owner: "json"
84
+ });
85
+ if (errs.length > 0) {
86
+ if (showError) {
87
+ _gct.message.error("参数语法错误");
88
+ }
89
+ if (!ignoreError) {
90
+ return Promise.reject();
91
+ }
92
+ }
93
+ return getInstance()?.getValue() ?? unref(editorConsoleState).defaultInput;
94
+ }
95
+ function formatJson2Notes(value, options) {
96
+ if (isEmpty(value)) {
97
+ return value;
98
+ }
99
+ let cloneJson = cloneDeep(value);
100
+ if (typeof value !== "string") {
101
+ try {
102
+ cloneJson = decodeURIComponent(JSON.stringify(cloneJson));
103
+ } catch (error) {
104
+ console.error(error);
105
+ cloneJson = JSON.stringify(cloneJson);
106
+ }
107
+ } else {
108
+ try {
109
+ cloneJson = decodeURIComponent(cloneJson);
110
+ } catch (error) {
111
+ console.warn(error);
112
+ }
113
+ try {
114
+ cloneJson = JSON.parse(cloneJson);
115
+ } catch (err) {
116
+ console.warn(err);
117
+ }
118
+ cloneJson = JSON.stringify(cloneJson);
119
+ }
120
+ const {
121
+ /** 在 '{' or '[' follows ':'位置移除新行 */
122
+ newline = false,
123
+ /** 在冒号后面加空格 */
124
+ spaceAfterColon = true
125
+ } = options || {};
126
+ let codeStr = cloneJson;
127
+ let regex;
128
+ regex = /([{}])/g;
129
+ codeStr = codeStr.replace(regex, "\r\n$1\r\n");
130
+ regex = /([[\]])/g;
131
+ codeStr = codeStr.replace(regex, "\r\n$1\r\n");
132
+ regex = /(,)/g;
133
+ codeStr = codeStr.replace(regex, "$1\r\n");
134
+ regex = /(\r\n\r\n)/g;
135
+ codeStr = codeStr.replace(regex, "\r\n");
136
+ regex = /\r\n,/g;
137
+ codeStr = codeStr.replace(regex, ",");
138
+ if (!newline) {
139
+ regex = /:\r\n\{/g;
140
+ codeStr = codeStr.replace(regex, ":{");
141
+ regex = /:\r\n\[/g;
142
+ codeStr = codeStr.replace(regex, ":[");
143
+ }
144
+ if (spaceAfterColon) {
145
+ regex = /:/g;
146
+ codeStr = codeStr.replace(regex, ": ");
147
+ }
148
+ let formatted = "", pad = 0;
149
+ const PADDING = " ";
150
+ codeStr.split("\r\n").forEach(function(node) {
151
+ let i = 0, indent = 0, padding = "";
152
+ if (node.match(/\{$/) || node.match(/\[$/)) {
153
+ indent = 1;
154
+ } else if (node.match(/\}/) || node.match(/\]/)) {
155
+ if (pad !== 0) {
156
+ pad -= 1;
157
+ }
158
+ } else {
159
+ indent = 0;
160
+ }
161
+ for (i = 0; i < pad; i++) {
162
+ padding += PADDING;
163
+ }
164
+ formatted += padding + node + "\r\n";
165
+ pad += indent;
166
+ });
167
+ return formatted;
168
+ }
169
+ function setConsoleResult(result) {
170
+ const { code, message, data } = result;
171
+ if (code === 200) {
172
+ const { logs: jsLogs, data: jsOutput } = data;
173
+ consoleValueState.value.output = formatJson2Notes(jsOutput);
174
+ consoleValueState.value.logs = jsLogs;
175
+ consoleValueState.value.error = "";
176
+ editorConsoleState.value.tabActiveKey = "2";
177
+ } else {
178
+ consoleValueState.value.output = "";
179
+ consoleValueState.value.logs = [];
180
+ consoleValueState.value.error = message;
181
+ editorConsoleState.value.tabActiveKey = "3";
182
+ }
183
+ }
184
+ return {
185
+ getInstance,
186
+ showConsolePanel,
187
+ hideConsolePanel,
188
+ getInputValue,
189
+ setConsoleResult,
190
+ formatJson2Notes
191
+ };
192
+ }
193
+
194
+ export { useEditorConsole, useEditorConsoleInner };