@tmagic/editor 1.3.0-alpha.12 → 1.3.0-alpha.14

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 (64) hide show
  1. package/dist/style.css +41 -113
  2. package/dist/tmagic-editor.js +1346 -1195
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +1357 -1202
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +11 -11
  7. package/src/Editor.vue +0 -4
  8. package/src/components/CodeBlockEditor.vue +155 -0
  9. package/src/components/CodeParams.vue +59 -0
  10. package/src/fields/Code.vue +27 -19
  11. package/src/fields/CodeSelect.vue +7 -1
  12. package/src/fields/CodeSelectCol.vue +65 -74
  13. package/src/fields/DataSourceFields.vue +7 -9
  14. package/src/fields/DataSourceMethodSelect.vue +147 -0
  15. package/src/fields/DataSourceMethods.vue +103 -0
  16. package/src/fields/EventSelect.vue +33 -7
  17. package/src/fields/UISelect.vue +37 -6
  18. package/src/icons/CodeIcon.vue +0 -2
  19. package/src/index.ts +8 -0
  20. package/src/layouts/CodeEditor.vue +32 -1
  21. package/src/layouts/Framework.vue +7 -3
  22. package/src/layouts/sidebar/Sidebar.vue +2 -10
  23. package/src/layouts/sidebar/code-block/CodeBlockList.vue +79 -117
  24. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +64 -0
  25. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +23 -33
  26. package/src/layouts/sidebar/data-source/DataSourceList.vue +111 -0
  27. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +13 -81
  28. package/src/services/codeBlock.ts +18 -71
  29. package/src/services/dataSource.ts +2 -0
  30. package/src/theme/code-block.scss +0 -122
  31. package/src/theme/code-editor.scss +27 -2
  32. package/src/theme/data-source-methods.scss +13 -0
  33. package/src/theme/event.scss +15 -12
  34. package/src/theme/theme.scss +1 -0
  35. package/src/type.ts +21 -6
  36. package/src/utils/data-source/index.ts +11 -0
  37. package/src/utils/use-code-block-edit.ts +84 -0
  38. package/src/utils/use-data-source-method.ts +101 -0
  39. package/types/components/CodeBlockEditor.vue.d.ts +21 -0
  40. package/types/components/CodeParams.vue.d.ts +26 -0
  41. package/types/components/ContentMenu.vue.d.ts +2 -2
  42. package/types/fields/Code.vue.d.ts +26 -6
  43. package/types/fields/CodeSelectCol.vue.d.ts +16 -5
  44. package/types/fields/DataSourceFields.vue.d.ts +2 -0
  45. package/types/fields/DataSourceMethodSelect.vue.d.ts +44 -0
  46. package/types/fields/DataSourceMethods.vue.d.ts +45 -0
  47. package/types/index.d.ts +4 -0
  48. package/types/layouts/CodeEditor.vue.d.ts +2 -0
  49. package/types/layouts/PropsPanel.vue.d.ts +8 -8
  50. package/types/layouts/sidebar/Sidebar.vue.d.ts +0 -3
  51. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +4 -9
  52. package/types/layouts/sidebar/code-block/{CodeBlockEditor.vue.d.ts → CodeBlockListPanel.vue.d.ts} +5 -6
  53. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -1
  54. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +14 -0
  55. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +1 -11
  56. package/types/services/codeBlock.d.ts +6 -37
  57. package/types/services/dataSource.d.ts +1 -0
  58. package/types/type.d.ts +19 -6
  59. package/types/{components/FunctionEditor.vue.d.ts → utils/use-code-block-edit.d.ts} +26 -123
  60. package/types/utils/use-data-source-method.d.ts +116 -0
  61. package/src/components/CodeDraftEditor.vue +0 -148
  62. package/src/components/FunctionEditor.vue +0 -197
  63. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -100
  64. package/types/components/CodeDraftEditor.vue.d.ts +0 -61
@@ -1,48 +1,228 @@
1
- import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, reactive, watch, createElementBlock, normalizeClass, createVNode, unref, withCtx, createElementVNode, resolveDynamicComponent, toRaw, inject, ref, createTextVNode, mergeProps, toDisplayString, Fragment, renderList, createCommentVNode, nextTick, watchEffect, withModifiers, onMounted, onUnmounted, renderSlot, createSlots, normalizeProps, markRaw, getCurrentInstance, withDirectives, vShow, createStaticVNode, provide, Teleport, onBeforeUnmount, toHandlers } from 'vue';
1
+ import { defineComponent, ref, watch, onMounted, onUnmounted, openBlock, createElementBlock, createBlock, Teleport, createElementVNode, normalizeClass, normalizeStyle, createVNode, unref, computed, reactive, resolveComponent, inject, withCtx, resolveDynamicComponent, toRaw, nextTick, createCommentVNode, createTextVNode, mergeProps, toDisplayString, Fragment, renderList, watchEffect, withModifiers, renderSlot, createSlots, normalizeProps, markRaw, getCurrentInstance, withDirectives, vShow, createStaticVNode, onBeforeUnmount, toHandlers, provide } from 'vue';
2
+ import { FullScreen, Edit, View, Coin, Delete, Plus, Close, ArrowDown, Grid, Memo, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Search, Aim, CopyDocument, DocumentCopy, Files, Hide, Goods, List, EditPen, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
3
+ import { throttle, isEmpty, cloneDeep, map, has, mergeWith, isObject, uniq, difference, union, pick, keys } from 'lodash-es';
4
+ import * as monaco from 'monaco-editor';
2
5
  import serialize from 'serialize-javascript';
3
- import { isEmpty, map, has, throttle, cloneDeep, mergeWith, isObject, uniq, forIn, difference, union, pick, keys } from 'lodash-es';
4
- import { TMagicCard, TMagicIcon, TMagicButton, tMagicMessageBox, getConfig as getConfig$1, TMagicTag, TMagicInput, TMagicTooltip, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, tMagicMessage, TMagicDrawer, TMagicTree, TMagicCollapse, TMagicCollapseItem, TMagicPopover } from '@tmagic/design';
6
+ import { TMagicButton, TMagicCard, tMagicMessage, TMagicIcon, tMagicMessageBox, getConfig as getConfig$1, TMagicTag, TMagicInput, TMagicTooltip, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, TMagicTree, TMagicCollapse, TMagicCollapseItem, TMagicPopover } from '@tmagic/design';
5
7
  import { HookType, ActionType, NodeType } from '@tmagic/schema';
6
- import { Edit, View, Coin, Delete, Plus, Close, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Search, Aim, CopyDocument, DocumentCopy, Files, Hide, Goods, List, EditPen, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
7
- import { createValues, MFormDialog, MSelect, MForm } from '@tmagic/form';
8
+ import { MFormDrawer, MForm, createValues, MFormDialog, MSelect } from '@tmagic/form';
8
9
  import { MagicTable } from '@tmagic/table';
9
- import * as monaco from 'monaco-editor';
10
10
  import Gesto from 'gesto';
11
- import { isPop, getNodePath, isNumber, isPage, toLine, guid, datetimeFormatter, removeClassNameByClassName, getNodes } from '@tmagic/utils';
11
+ import { isPop, getNodePath, isNumber, isPage, toLine, guid, removeClassNameByClassName, getNodes } from '@tmagic/utils';
12
12
  import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType } from '@tmagic/stage';
13
13
  import { EventEmitter } from 'events';
14
14
  import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
15
15
  import KeyController from 'keycon';
16
16
 
17
- const _sfc_main$H = /* @__PURE__ */ defineComponent({
17
+ const _hoisted_1$r = {
18
+ class: /* @__PURE__ */ normalizeClass(`magic-code-editor`)
19
+ };
20
+ const _sfc_main$K = /* @__PURE__ */ defineComponent({
21
+ ...{
22
+ name: "MEditorCodeEditor"
23
+ },
24
+ __name: "CodeEditor",
25
+ props: {
26
+ initValues: {},
27
+ modifiedValues: {},
28
+ type: {},
29
+ language: { default: "javascript" },
30
+ options: { default: () => ({
31
+ tabSize: 2
32
+ }) },
33
+ height: {},
34
+ autoSave: { type: Boolean, default: true }
35
+ },
36
+ emits: ["initd", "save"],
37
+ setup(__props, { expose: __expose, emit }) {
38
+ const props = __props;
39
+ const toString = (v, language) => {
40
+ let value = "";
41
+ if (typeof v !== "string") {
42
+ if (props.language.toLocaleLowerCase() === "json") {
43
+ value = JSON.stringify(v, null, 2);
44
+ } else {
45
+ value = serialize(v, {
46
+ space: 2,
47
+ unsafe: true
48
+ }).replace(/"(\w+)":\s/g, "$1: ");
49
+ }
50
+ } else {
51
+ value = v;
52
+ }
53
+ if (language === "javascript" && value.startsWith("{") && value.endsWith("}")) {
54
+ value = `(${value})`;
55
+ }
56
+ return value;
57
+ };
58
+ let vsEditor = null;
59
+ let vsDiffEditor = null;
60
+ const values = ref("");
61
+ const loading = ref(false);
62
+ const codeEditor = ref();
63
+ const resizeObserver = new globalThis.ResizeObserver(
64
+ throttle(() => {
65
+ vsEditor?.layout();
66
+ vsDiffEditor?.layout();
67
+ }, 300)
68
+ );
69
+ const setEditorValue = (v, m) => {
70
+ values.value = toString(v, props.language);
71
+ if (props.type === "diff") {
72
+ const originalModel = monaco.editor.createModel(values.value, "text/javascript");
73
+ const modifiedModel = monaco.editor.createModel(toString(m, props.language), "text/javascript");
74
+ return vsDiffEditor?.setModel({
75
+ original: originalModel,
76
+ modified: modifiedModel
77
+ });
78
+ }
79
+ return vsEditor?.setValue(values.value);
80
+ };
81
+ const getEditorValue = () => (props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || "";
82
+ const init = async () => {
83
+ if (!codeEditor.value)
84
+ return;
85
+ const options = {
86
+ value: values.value,
87
+ language: props.language,
88
+ theme: "vs-dark",
89
+ ...props.options
90
+ };
91
+ if (props.type === "diff") {
92
+ vsDiffEditor = monaco.editor.createDiffEditor(codeEditor.value, options);
93
+ } else {
94
+ vsEditor = monaco.editor.create(codeEditor.value, options);
95
+ }
96
+ setEditorValue(props.initValues, props.modifiedValues);
97
+ loading.value = false;
98
+ emit("initd", vsEditor);
99
+ codeEditor.value.addEventListener("keydown", (e) => {
100
+ if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
101
+ e.preventDefault();
102
+ e.stopPropagation();
103
+ const newValue = getEditorValue();
104
+ values.value = newValue;
105
+ emit("save", newValue);
106
+ }
107
+ });
108
+ if (props.type !== "diff" && props.autoSave) {
109
+ vsEditor?.onDidBlurEditorWidget(() => {
110
+ const newValue = getEditorValue();
111
+ if (values.value !== newValue) {
112
+ values.value = newValue;
113
+ emit("save", newValue);
114
+ }
115
+ });
116
+ }
117
+ resizeObserver.observe(codeEditor.value);
118
+ };
119
+ watch(
120
+ () => props.initValues,
121
+ (v, preV) => {
122
+ if (v !== preV) {
123
+ setEditorValue(props.initValues, props.modifiedValues);
124
+ }
125
+ },
126
+ {
127
+ deep: true,
128
+ immediate: true
129
+ }
130
+ );
131
+ onMounted(async () => {
132
+ loading.value = true;
133
+ init();
134
+ });
135
+ onUnmounted(() => {
136
+ resizeObserver.disconnect();
137
+ });
138
+ const fullScreen = ref(false);
139
+ const fullScreenHandler = () => {
140
+ fullScreen.value = !fullScreen.value;
141
+ setTimeout(() => {
142
+ vsEditor?.focus();
143
+ vsEditor?.layout();
144
+ vsDiffEditor?.focus();
145
+ vsDiffEditor?.layout();
146
+ });
147
+ };
148
+ __expose({
149
+ values,
150
+ getEditor() {
151
+ return vsEditor || vsDiffEditor;
152
+ },
153
+ getVsEditor() {
154
+ return vsEditor;
155
+ },
156
+ getVsDiffEditor() {
157
+ return vsDiffEditor;
158
+ },
159
+ setEditorValue,
160
+ focus() {
161
+ vsEditor?.focus();
162
+ vsDiffEditor?.focus();
163
+ }
164
+ });
165
+ return (_ctx, _cache) => {
166
+ return openBlock(), createElementBlock("div", _hoisted_1$r, [
167
+ (openBlock(), createBlock(Teleport, {
168
+ to: "body",
169
+ disabled: !fullScreen.value
170
+ }, [
171
+ createElementVNode("div", {
172
+ class: normalizeClass(`magic-code-editor-wrapper${fullScreen.value ? " full-screen" : ""}`),
173
+ style: normalizeStyle(!fullScreen.value && _ctx.height ? `height: ${_ctx.height}` : "100%")
174
+ }, [
175
+ createVNode(unref(TMagicButton), {
176
+ class: "magic-code-editor-full-screen-icon",
177
+ circle: "",
178
+ size: "small",
179
+ icon: unref(FullScreen),
180
+ onClick: fullScreenHandler
181
+ }, null, 8, ["icon"]),
182
+ createElementVNode("div", {
183
+ ref_key: "codeEditor",
184
+ ref: codeEditor,
185
+ class: "magic-code-editor-content"
186
+ }, null, 512)
187
+ ], 6)
188
+ ], 8, ["disabled"]))
189
+ ]);
190
+ };
191
+ }
192
+ });
193
+
194
+ const _sfc_main$J = /* @__PURE__ */ defineComponent({
18
195
  ...{
19
196
  name: "MEditorCode"
20
197
  },
21
198
  __name: "Code",
22
199
  props: {
200
+ config: {},
23
201
  model: {},
24
202
  name: {},
25
- config: {},
26
- prop: {}
203
+ prop: {},
204
+ lastValues: {},
205
+ disabled: { type: Boolean, default: false },
206
+ size: {}
27
207
  },
28
208
  emits: ["change"],
29
209
  setup(__props, { emit }) {
30
210
  const props = __props;
31
- const language = computed(() => props.config.language || "javascript");
32
- const height = computed(() => props.config.height || `${document.body.clientHeight - 168}px`);
33
211
  const save = (v) => {
34
212
  props.model[props.name] = v;
35
213
  emit("change", v);
36
214
  };
37
215
  return (_ctx, _cache) => {
38
- const _component_magic_code_editor = resolveComponent("magic-code-editor");
39
- return openBlock(), createBlock(_component_magic_code_editor, {
40
- style: normalizeStyle(`height: ${height.value}`),
216
+ return openBlock(), createBlock(_sfc_main$K, {
217
+ height: _ctx.config.height,
41
218
  "init-values": _ctx.model[_ctx.name],
42
- language: language.value,
43
- options: _ctx.config.options,
219
+ language: _ctx.config.language,
220
+ options: {
221
+ ..._ctx.config.options,
222
+ readOnly: _ctx.disabled
223
+ },
44
224
  onSave: save
45
- }, null, 8, ["style", "init-values", "language", "options"]);
225
+ }, null, 8, ["height", "init-values", "language", "options"]);
46
226
  };
47
227
  }
48
228
  });
@@ -53,7 +233,7 @@ const setConfig = (option) => {
53
233
  };
54
234
  const getConfig = (key) => $TMAGIC_EDITOR[key];
55
235
 
56
- const _sfc_main$G = /* @__PURE__ */ defineComponent({
236
+ const _sfc_main$I = /* @__PURE__ */ defineComponent({
57
237
  ...{
58
238
  name: "MEditorCodeLink"
59
239
  },
@@ -127,7 +307,7 @@ const _sfc_main$G = /* @__PURE__ */ defineComponent({
127
307
  }
128
308
  });
129
309
 
130
- const _sfc_main$F = /* @__PURE__ */ defineComponent({
310
+ const _sfc_main$H = /* @__PURE__ */ defineComponent({
131
311
  ...{
132
312
  name: "MEditorCodeSelect"
133
313
  },
@@ -142,6 +322,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
142
322
  emits: ["change"],
143
323
  setup(__props, { emit }) {
144
324
  const props = __props;
325
+ const services = inject("services");
145
326
  const codeConfig = computed(() => ({
146
327
  type: "group-list",
147
328
  name: "hookData",
@@ -151,7 +332,9 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
151
332
  items: [
152
333
  {
153
334
  type: "code-select-col",
154
- labelWidth: 0
335
+ name: "codeId",
336
+ labelWidth: 0,
337
+ disabled: () => !services?.codeBlockService.getEditStatus()
155
338
  }
156
339
  ]
157
340
  }));
@@ -192,7 +375,188 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
192
375
  }
193
376
  });
194
377
 
195
- const _hoisted_1$p = ["src"];
378
+ const _sfc_main$G = /* @__PURE__ */ defineComponent({
379
+ ...{
380
+ name: "MEditorCodeBlockEditor"
381
+ },
382
+ __name: "CodeBlockEditor",
383
+ props: {
384
+ content: {},
385
+ disabled: { type: Boolean }
386
+ },
387
+ emits: ["submit"],
388
+ setup(__props, { expose: __expose, emit }) {
389
+ const services = inject("services");
390
+ const columnWidth = computed(() => services?.uiService.get("columnWidth"));
391
+ const size = computed(() => columnWidth.value ? columnWidth.value.center + columnWidth.value.right : 600);
392
+ const codeEditorHeight = ref("600px");
393
+ const defaultParamColConfig = {
394
+ type: "row",
395
+ label: "参数类型",
396
+ items: [
397
+ {
398
+ text: "参数类型",
399
+ labelWidth: "70px",
400
+ type: "select",
401
+ name: "type",
402
+ options: [
403
+ {
404
+ text: "数字",
405
+ label: "数字",
406
+ value: "number"
407
+ },
408
+ {
409
+ text: "字符串",
410
+ label: "字符串",
411
+ value: "text"
412
+ },
413
+ {
414
+ text: "组件",
415
+ label: "组件",
416
+ value: "ui-select"
417
+ }
418
+ ]
419
+ }
420
+ ]
421
+ };
422
+ const functionConfig = computed(() => [
423
+ {
424
+ text: "名称",
425
+ name: "name"
426
+ },
427
+ {
428
+ text: "注释",
429
+ name: "desc"
430
+ },
431
+ {
432
+ type: "table",
433
+ border: true,
434
+ text: "参数",
435
+ enableFullscreen: false,
436
+ name: "params",
437
+ maxHeight: "300px",
438
+ dropSort: false,
439
+ items: [
440
+ {
441
+ type: "text",
442
+ label: "参数名",
443
+ name: "name"
444
+ },
445
+ {
446
+ type: "text",
447
+ label: "注释",
448
+ name: "extra"
449
+ },
450
+ services?.codeBlockService.getParamsColConfig() || defaultParamColConfig
451
+ ]
452
+ },
453
+ {
454
+ name: "content",
455
+ type: "vs-code",
456
+ options: inject("codeOptions", {}),
457
+ height: codeEditorHeight.value,
458
+ onChange: (formState, code) => {
459
+ try {
460
+ getConfig("parseDSL")(code);
461
+ return code;
462
+ } catch (error) {
463
+ tMagicMessage.error(error.message);
464
+ throw error;
465
+ }
466
+ }
467
+ }
468
+ ]);
469
+ const submitForm = async (values) => {
470
+ emit("submit", values);
471
+ };
472
+ const errorHandler = (error) => {
473
+ tMagicMessage.error(error.message);
474
+ };
475
+ const fomDrawer = ref();
476
+ const openHandler = () => {
477
+ setTimeout(() => {
478
+ if (fomDrawer.value) {
479
+ const height = fomDrawer.value?.bodyHeight - 468;
480
+ codeEditorHeight.value = `${height > 100 ? height : 600}px`;
481
+ }
482
+ });
483
+ };
484
+ __expose({
485
+ show() {
486
+ fomDrawer.value?.show();
487
+ },
488
+ hide() {
489
+ fomDrawer.value?.hide();
490
+ }
491
+ });
492
+ return (_ctx, _cache) => {
493
+ return openBlock(), createBlock(unref(MFormDrawer), {
494
+ ref_key: "fomDrawer",
495
+ ref: fomDrawer,
496
+ "label-width": "80px",
497
+ title: _ctx.content.name,
498
+ width: size.value,
499
+ config: functionConfig.value,
500
+ values: _ctx.content,
501
+ disabled: _ctx.disabled,
502
+ onSubmit: submitForm,
503
+ onError: errorHandler,
504
+ onOpen: openHandler
505
+ }, null, 8, ["title", "width", "config", "values", "disabled"]);
506
+ };
507
+ }
508
+ });
509
+
510
+ const _sfc_main$F = /* @__PURE__ */ defineComponent({
511
+ ...{
512
+ name: "MEditorCodeParams"
513
+ },
514
+ __name: "CodeParams",
515
+ props: {
516
+ model: {},
517
+ size: {},
518
+ disabled: { type: Boolean },
519
+ name: {},
520
+ paramsConfig: {}
521
+ },
522
+ emits: ["change"],
523
+ setup(__props, { emit }) {
524
+ const props = __props;
525
+ const form = ref();
526
+ const getFormConfig = (items = []) => [
527
+ {
528
+ type: "fieldset",
529
+ items,
530
+ legend: "参数",
531
+ labelWidth: "70px",
532
+ name: props.name
533
+ }
534
+ ];
535
+ const codeParamsConfig = computed(() => getFormConfig(props.paramsConfig));
536
+ const onParamsChangeHandler = async () => {
537
+ try {
538
+ const value = await form.value?.submitForm(true);
539
+ emit("change", value);
540
+ } catch (e) {
541
+ console.log(e);
542
+ }
543
+ };
544
+ return (_ctx, _cache) => {
545
+ return openBlock(), createBlock(unref(MForm), {
546
+ ref_key: "form",
547
+ ref: form,
548
+ config: codeParamsConfig.value,
549
+ "init-values": _ctx.model,
550
+ disabled: _ctx.disabled,
551
+ size: _ctx.size,
552
+ "watch-props": false,
553
+ onChange: onParamsChangeHandler
554
+ }, null, 8, ["config", "init-values", "disabled", "size"]);
555
+ };
556
+ }
557
+ });
558
+
559
+ const _hoisted_1$q = ["src"];
196
560
  const _sfc_main$E = /* @__PURE__ */ defineComponent({
197
561
  ...{
198
562
  name: "MEditorIcon"
@@ -216,7 +580,7 @@ const _sfc_main$E = /* @__PURE__ */ defineComponent({
216
580
  class: "magic-editor-icon"
217
581
  }, {
218
582
  default: withCtx(() => [
219
- createElementVNode("img", { src: _ctx.icon }, null, 8, _hoisted_1$p)
583
+ createElementVNode("img", { src: _ctx.icon }, null, 8, _hoisted_1$q)
220
584
  ]),
221
585
  _: 1
222
586
  })) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
@@ -235,7 +599,65 @@ const _sfc_main$E = /* @__PURE__ */ defineComponent({
235
599
  }
236
600
  });
237
601
 
238
- const _hoisted_1$o = { class: "m-fields-code-select-col" };
602
+ const useCodeBlockEdit = (codeBlockService) => {
603
+ const codeConfig = ref();
604
+ const codeId = ref();
605
+ const codeBlockEditor = ref();
606
+ const createCodeBlock = async () => {
607
+ if (!codeBlockService) {
608
+ tMagicMessage.error("新增代码块失败");
609
+ return;
610
+ }
611
+ codeConfig.value = {
612
+ name: "代码块",
613
+ content: `({app, params}) => {
614
+ // place your code here
615
+ }`,
616
+ params: []
617
+ };
618
+ codeId.value = await codeBlockService.getUniqueId();
619
+ await nextTick();
620
+ codeBlockEditor.value?.show();
621
+ };
622
+ const editCode = async (id) => {
623
+ const codeBlock = await codeBlockService?.getCodeContentById(id);
624
+ if (!codeBlock) {
625
+ tMagicMessage.error("获取代码块内容失败");
626
+ return;
627
+ }
628
+ let codeContent = codeBlock.content;
629
+ if (typeof codeContent !== "string") {
630
+ codeContent = codeContent.toString();
631
+ }
632
+ codeConfig.value = {
633
+ ...cloneDeep(codeBlock),
634
+ content: codeContent
635
+ };
636
+ codeId.value = id;
637
+ await nextTick();
638
+ codeBlockEditor.value?.show();
639
+ };
640
+ const deleteCode = async (key) => {
641
+ codeBlockService?.deleteCodeDslByIds([key]);
642
+ };
643
+ const submitCodeBlockHandler = async (values) => {
644
+ if (!codeId.value)
645
+ return;
646
+ await codeBlockService?.setCodeDslById(codeId.value, values);
647
+ codeBlockEditor.value?.hide();
648
+ };
649
+ return {
650
+ codeId,
651
+ codeConfig,
652
+ codeBlockEditor,
653
+ createCodeBlock,
654
+ editCode,
655
+ deleteCode,
656
+ submitCodeBlockHandler
657
+ };
658
+ };
659
+
660
+ const _hoisted_1$p = { class: "m-fields-code-select-col" };
239
661
  const _hoisted_2$f = { class: "code-select-container" };
240
662
  const _sfc_main$D = /* @__PURE__ */ defineComponent({
241
663
  ...{
@@ -247,28 +669,33 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
247
669
  model: {},
248
670
  prop: {},
249
671
  name: {},
672
+ lastValues: {},
673
+ disabled: { type: Boolean, default: false },
250
674
  size: {}
251
675
  },
252
676
  emits: ["change"],
253
677
  setup(__props, { emit }) {
254
678
  const props = __props;
255
679
  const services = inject("services");
256
- const mForm = inject("mForm");
680
+ const getParamItemsConfig = (codeId) => {
681
+ if (!codeDsl.value || !codeId)
682
+ return [];
683
+ const paramStatements = codeDsl.value[codeId]?.params;
684
+ if (isEmpty(paramStatements))
685
+ return [];
686
+ return paramStatements.map((paramState) => ({
687
+ labelWidth: "100px",
688
+ text: paramState.name,
689
+ ...paramState
690
+ }));
691
+ };
257
692
  const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
258
- const editable = computed(() => services?.codeBlockService.getEditStatus());
259
- const codeParamsConfig = ref({
260
- type: "fieldset",
261
- items: [],
262
- legend: "参数",
263
- labelWidth: "70px",
264
- name: "params",
265
- display: false
266
- });
693
+ const paramsConfig = ref(getParamItemsConfig(props.model[props.name]));
267
694
  const selectConfig = {
268
695
  type: "select",
269
696
  text: "代码块",
270
- name: "codeId",
271
- labelWidth: "70px",
697
+ name: props.name,
698
+ labelWidth: "80px",
272
699
  options: () => {
273
700
  if (codeDsl.value) {
274
701
  return map(codeDsl.value, (value, key) => ({
@@ -280,56 +707,23 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
280
707
  return [];
281
708
  },
282
709
  onChange: (formState, codeId, { model }) => {
283
- model.params = {};
284
- }
285
- };
286
- const getParamItemsConfig = (codeId) => {
287
- if (!codeDsl.value)
288
- return [];
289
- const paramStatements = codeDsl.value[codeId]?.params;
290
- if (isEmpty(paramStatements))
291
- return [];
292
- return paramStatements.map((paramState) => ({
293
- labelWidth: "100px",
294
- text: paramState.name,
295
- ...paramState
296
- }));
297
- };
298
- const getCodeParamsConfig = (codeId) => {
299
- const paramsConfig = getParamItemsConfig(codeId);
300
- if (!props.model.params || isEmpty(props.model.params)) {
301
- props.model.params = {};
302
- createValues(mForm, paramsConfig, {}, props.model.params);
710
+ paramsConfig.value = getParamItemsConfig(codeId);
711
+ if (paramsConfig.value.length) {
712
+ model.params = createValues(formState, paramsConfig.value, {}, model.params);
713
+ } else {
714
+ model.params = {};
715
+ }
716
+ return codeId;
303
717
  }
304
- codeParamsConfig.value = {
305
- type: "fieldset",
306
- items: paramsConfig,
307
- legend: "参数",
308
- labelWidth: "70px",
309
- name: "params",
310
- display: !isEmpty(paramsConfig)
311
- };
312
718
  };
313
- const onParamsChangeHandler = () => {
719
+ const onParamsChangeHandler = (value) => {
720
+ props.model.params = value.params;
314
721
  emit("change", props.model);
315
722
  };
316
- watch(
317
- () => props.model.codeId,
318
- (codeId) => {
319
- if (!codeId)
320
- return;
321
- getCodeParamsConfig(codeId);
322
- },
323
- {
324
- immediate: true
325
- }
326
- );
327
- const editCode = () => {
328
- services?.codeBlockService.setCodeEditorContent(true, props.model.codeId);
329
- };
723
+ const { codeBlockEditor, codeConfig, editCode, submitCodeBlockHandler } = useCodeBlockEdit(services?.codeBlockService);
330
724
  return (_ctx, _cache) => {
331
725
  const _component_m_form_container = resolveComponent("m-form-container");
332
- return openBlock(), createElementBlock("div", _hoisted_1$o, [
726
+ return openBlock(), createElementBlock("div", _hoisted_1$p, [
333
727
  createElementVNode("div", _hoisted_2$f, [
334
728
  createVNode(_component_m_form_container, {
335
729
  class: "select",
@@ -337,23 +731,35 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
337
731
  model: _ctx.model,
338
732
  onChange: onParamsChangeHandler
339
733
  }, null, 8, ["model"]),
340
- createVNode(_sfc_main$E, {
734
+ _ctx.model[_ctx.name] ? (openBlock(), createBlock(_sfc_main$E, {
735
+ key: 0,
341
736
  class: "icon",
342
- icon: editable.value ? unref(Edit) : unref(View),
343
- onClick: editCode
344
- }, null, 8, ["icon"])
737
+ icon: !_ctx.disabled ? unref(Edit) : unref(View),
738
+ onClick: _cache[0] || (_cache[0] = ($event) => unref(editCode)(_ctx.model[_ctx.name]))
739
+ }, null, 8, ["icon"])) : createCommentVNode("", true)
345
740
  ]),
346
- createVNode(_component_m_form_container, {
347
- config: codeParamsConfig.value,
741
+ paramsConfig.value.length ? (openBlock(), createBlock(_sfc_main$F, {
742
+ key: 0,
743
+ name: "params",
348
744
  model: _ctx.model,
745
+ size: _ctx.size,
746
+ "params-config": paramsConfig.value,
349
747
  onChange: onParamsChangeHandler
350
- }, null, 8, ["config", "model"])
748
+ }, null, 8, ["model", "size", "params-config"])) : createCommentVNode("", true),
749
+ unref(codeConfig) ? (openBlock(), createBlock(_sfc_main$G, {
750
+ key: 1,
751
+ ref_key: "codeBlockEditor",
752
+ ref: codeBlockEditor,
753
+ disabled: _ctx.disabled,
754
+ content: unref(codeConfig),
755
+ onSubmit: unref(submitCodeBlockHandler)
756
+ }, null, 8, ["disabled", "content", "onSubmit"])) : createCommentVNode("", true)
351
757
  ]);
352
758
  };
353
759
  }
354
760
  });
355
761
 
356
- const _hoisted_1$n = { class: "m-editor-data-source-fields" };
762
+ const _hoisted_1$o = { class: "m-editor-data-source-fields" };
357
763
  const _hoisted_2$e = { class: "m-editor-data-source-fields-footer" };
358
764
  const _sfc_main$C = /* @__PURE__ */ defineComponent({
359
765
  ...{
@@ -364,6 +770,7 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
364
770
  config: {},
365
771
  model: {},
366
772
  prop: {},
773
+ lastValues: {},
367
774
  disabled: { type: Boolean, default: false },
368
775
  name: {}
369
776
  },
@@ -374,24 +781,20 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
374
781
  const fieldValues = ref({});
375
782
  const filedTitle = ref("");
376
783
  const newHandler = () => {
377
- if (!addDialog.value)
378
- return;
379
784
  fieldValues.value = {};
380
785
  filedTitle.value = "新增属性";
381
- addDialog.value.dialogVisible = true;
786
+ addDialog.value?.show();
382
787
  };
383
788
  const fieldChange = ({ index, ...value }) => {
384
- if (!addDialog.value)
385
- return;
386
789
  if (index > -1) {
387
790
  props.model[props.name][index] = value;
388
791
  } else {
389
792
  props.model[props.name].push(value);
390
793
  }
391
- addDialog.value.dialogVisible = false;
794
+ addDialog.value?.hide();
392
795
  emit("change", props.model[props.name]);
393
796
  };
394
- const filedColumns = [
797
+ const fieldColumns = [
395
798
  {
396
799
  label: "属性名称",
397
800
  prop: "title"
@@ -411,14 +814,12 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
411
814
  {
412
815
  text: "编辑",
413
816
  handler: (row, index) => {
414
- if (!addDialog.value)
415
- return;
416
817
  fieldValues.value = {
417
818
  ...row,
418
819
  index
419
820
  };
420
821
  filedTitle.value = `编辑${row.title}`;
421
- addDialog.value.dialogVisible = true;
822
+ addDialog.value?.show();
422
823
  }
423
824
  },
424
825
  {
@@ -501,10 +902,10 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
501
902
  }
502
903
  ];
503
904
  return (_ctx, _cache) => {
504
- return openBlock(), createElementBlock("div", _hoisted_1$n, [
905
+ return openBlock(), createElementBlock("div", _hoisted_1$o, [
505
906
  createVNode(unref(MagicTable), {
506
907
  data: _ctx.model[_ctx.name],
507
- columns: filedColumns
908
+ columns: fieldColumns
508
909
  }, null, 8, ["data"]),
509
910
  createElementVNode("div", _hoisted_2$e, [
510
911
  createVNode(unref(TMagicButton), {
@@ -527,16 +928,17 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
527
928
  config: dataSourceFieldsConfig,
528
929
  values: fieldValues.value,
529
930
  parentValues: _ctx.model[_ctx.name],
931
+ disabled: _ctx.disabled,
530
932
  onSubmit: fieldChange
531
- }, null, 8, ["title", "values", "parentValues"])
933
+ }, null, 8, ["title", "values", "parentValues", "disabled"])
532
934
  ]);
533
935
  };
534
936
  }
535
937
  });
536
938
 
537
- const _hoisted_1$m = { style: { "display": "flex", "flex-direction": "column", "line-height": "1.2em" } };
939
+ const _hoisted_1$n = { style: { "display": "flex", "flex-direction": "column", "line-height": "1.2em" } };
538
940
  const _hoisted_2$d = { style: { "font-size": "10px", "color": "rgba(0, 0, 0, 0.6)" } };
539
- const _hoisted_3$6 = { class: "el-input__inner" };
941
+ const _hoisted_3$5 = { class: "el-input__inner" };
540
942
  const _sfc_main$B = /* @__PURE__ */ defineComponent({
541
943
  ...{
542
944
  name: "MEditorDataSourceInput"
@@ -759,50 +1161,333 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
759
1161
  createVNode(_sfc_main$E, { icon: unref(Coin) }, null, 8, ["icon"])
760
1162
  ]),
761
1163
  default: withCtx(({ item }) => [
762
- createElementVNode("div", _hoisted_1$m, [
1164
+ createElementVNode("div", _hoisted_1$n, [
763
1165
  createElementVNode("div", null, toDisplayString(item.text), 1),
764
1166
  createElementVNode("span", _hoisted_2$d, toDisplayString(item.value), 1)
765
1167
  ])
766
1168
  ]),
767
- _: 1
768
- }, 16, ["modelValue"])) : (openBlock(), createElementBlock("div", {
769
- key: 1,
770
- class: normalizeClass(`tmagic-data-source-input-text el-input el-input--${_ctx.size}`),
771
- onMouseup: mouseupHandler
772
- }, [
773
- createElementVNode("div", {
774
- class: normalizeClass(`tmagic-data-source-input-text-wrapper el-input__wrapper ${isFocused.value ? " is-focus" : ""}`)
775
- }, [
776
- createElementVNode("div", _hoisted_3$6, [
777
- (openBlock(true), createElementBlock(Fragment, null, renderList(displayState.value, (item, index) => {
778
- return openBlock(), createElementBlock(Fragment, null, [
779
- item.type === "text" ? (openBlock(), createElementBlock("span", {
780
- key: index,
781
- style: { "margin-right": "2px" }
782
- }, toDisplayString(item.value), 1)) : createCommentVNode("", true),
783
- item.type === "var" ? (openBlock(), createBlock(unref(TMagicTag), {
784
- key: index,
785
- size: _ctx.size
786
- }, {
787
- default: withCtx(() => [
788
- createTextVNode(toDisplayString(item.value), 1)
789
- ]),
790
- _: 2
791
- }, 1032, ["size"])) : createCommentVNode("", true)
792
- ], 64);
793
- }), 256)),
794
- createVNode(_sfc_main$E, {
795
- class: "tmagic-data-source-input-icon",
796
- icon: unref(Coin)
797
- }, null, 8, ["icon"])
798
- ])
799
- ], 2)
800
- ], 34));
1169
+ _: 1
1170
+ }, 16, ["modelValue"])) : (openBlock(), createElementBlock("div", {
1171
+ key: 1,
1172
+ class: normalizeClass(`tmagic-data-source-input-text el-input el-input--${_ctx.size}`),
1173
+ onMouseup: mouseupHandler
1174
+ }, [
1175
+ createElementVNode("div", {
1176
+ class: normalizeClass(`tmagic-data-source-input-text-wrapper el-input__wrapper ${isFocused.value ? " is-focus" : ""}`)
1177
+ }, [
1178
+ createElementVNode("div", _hoisted_3$5, [
1179
+ (openBlock(true), createElementBlock(Fragment, null, renderList(displayState.value, (item, index) => {
1180
+ return openBlock(), createElementBlock(Fragment, null, [
1181
+ item.type === "text" ? (openBlock(), createElementBlock("span", {
1182
+ key: index,
1183
+ style: { "margin-right": "2px" }
1184
+ }, toDisplayString(item.value), 1)) : createCommentVNode("", true),
1185
+ item.type === "var" ? (openBlock(), createBlock(unref(TMagicTag), {
1186
+ key: index,
1187
+ size: _ctx.size
1188
+ }, {
1189
+ default: withCtx(() => [
1190
+ createTextVNode(toDisplayString(item.value), 1)
1191
+ ]),
1192
+ _: 2
1193
+ }, 1032, ["size"])) : createCommentVNode("", true)
1194
+ ], 64);
1195
+ }), 256)),
1196
+ createVNode(_sfc_main$E, {
1197
+ class: "tmagic-data-source-input-icon",
1198
+ icon: unref(Coin)
1199
+ }, null, 8, ["icon"])
1200
+ ])
1201
+ ], 2)
1202
+ ], 34));
1203
+ };
1204
+ }
1205
+ });
1206
+
1207
+ const useDataSourceMethod = () => {
1208
+ const codeConfig = ref();
1209
+ const codeBlockEditor = ref();
1210
+ const dataSource = ref();
1211
+ const dataSourceMethod = ref("");
1212
+ return {
1213
+ codeConfig,
1214
+ codeBlockEditor,
1215
+ createCode: async (model) => {
1216
+ codeConfig.value = {
1217
+ name: "",
1218
+ content: `({ params, dataSource, app }) => {
1219
+ // place your code here
1220
+ }`,
1221
+ params: []
1222
+ };
1223
+ await nextTick();
1224
+ dataSource.value = model;
1225
+ dataSourceMethod.value = "";
1226
+ codeBlockEditor.value?.show();
1227
+ },
1228
+ editCode: async (model, methodName) => {
1229
+ const method = model.methods?.find((method2) => method2.name === methodName);
1230
+ if (!method) {
1231
+ tMagicMessage.error("获取数据源方法失败");
1232
+ return;
1233
+ }
1234
+ let codeContent = method.content;
1235
+ if (typeof codeContent !== "string") {
1236
+ codeContent = codeContent.toString();
1237
+ }
1238
+ codeConfig.value = {
1239
+ ...cloneDeep(method),
1240
+ content: codeContent
1241
+ };
1242
+ await nextTick();
1243
+ dataSource.value = model;
1244
+ dataSourceMethod.value = methodName;
1245
+ codeBlockEditor.value?.show();
1246
+ },
1247
+ deleteCode: async (model, methodName) => {
1248
+ if (!model.methods)
1249
+ return;
1250
+ const index = model.methods.findIndex((method) => method.name === methodName);
1251
+ if (index === -1) {
1252
+ return;
1253
+ }
1254
+ model.methods.splice(index, 1);
1255
+ },
1256
+ submitCode: (values) => {
1257
+ if (!dataSource.value)
1258
+ return;
1259
+ if (!dataSource.value.methods) {
1260
+ dataSource.value.methods = [];
1261
+ }
1262
+ if (values.content) {
1263
+ const parseDSL = getConfig("parseDSL");
1264
+ if (typeof values.content === "string") {
1265
+ values.content = parseDSL(values.content);
1266
+ }
1267
+ }
1268
+ if (dataSourceMethod.value) {
1269
+ const index = dataSource.value.methods.findIndex((method) => method.name === dataSourceMethod.value);
1270
+ dataSource.value.methods.splice(index, 1, values);
1271
+ } else {
1272
+ dataSource.value.methods.push(values);
1273
+ }
1274
+ codeBlockEditor.value?.hide();
1275
+ }
1276
+ };
1277
+ };
1278
+
1279
+ const _hoisted_1$m = { class: "m-editor-data-source-methods" };
1280
+ const _hoisted_2$c = { class: "m-editor-data-source-methods-footer" };
1281
+ const _sfc_main$A = /* @__PURE__ */ defineComponent({
1282
+ ...{
1283
+ name: "MEditorDataSourceMethods"
1284
+ },
1285
+ __name: "DataSourceMethods",
1286
+ props: {
1287
+ config: {},
1288
+ model: {},
1289
+ prop: {},
1290
+ lastValues: {},
1291
+ disabled: { type: Boolean, default: false },
1292
+ name: {}
1293
+ },
1294
+ emits: ["change"],
1295
+ setup(__props, { emit }) {
1296
+ const props = __props;
1297
+ const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
1298
+ const methodColumns = [
1299
+ {
1300
+ label: "名称",
1301
+ prop: "name"
1302
+ },
1303
+ {
1304
+ label: "注释",
1305
+ prop: "desc"
1306
+ },
1307
+ {
1308
+ label: "参数",
1309
+ prop: "params",
1310
+ formatter: (params) => params.map((item) => item.name).join(", ")
1311
+ },
1312
+ {
1313
+ label: "操作",
1314
+ fixed: "right",
1315
+ actions: [
1316
+ {
1317
+ text: "编辑",
1318
+ handler: (row) => {
1319
+ editCode(props.model, row.name);
1320
+ emit("change", props.model[props.name]);
1321
+ }
1322
+ },
1323
+ {
1324
+ text: "删除",
1325
+ buttonType: "danger",
1326
+ handler: (row) => {
1327
+ deleteCode(props.model, row.name);
1328
+ emit("change", props.model[props.name]);
1329
+ }
1330
+ }
1331
+ ]
1332
+ }
1333
+ ];
1334
+ const createCodeHandler = () => {
1335
+ createCode(props.model);
1336
+ emit("change", props.model[props.name]);
1337
+ };
1338
+ const submitCodeHandler = (values) => {
1339
+ submitCode(values);
1340
+ emit("change", props.model[props.name]);
1341
+ };
1342
+ return (_ctx, _cache) => {
1343
+ return openBlock(), createElementBlock("div", _hoisted_1$m, [
1344
+ createVNode(unref(MagicTable), {
1345
+ data: _ctx.model[_ctx.name],
1346
+ columns: methodColumns
1347
+ }, null, 8, ["data"]),
1348
+ createElementVNode("div", _hoisted_2$c, [
1349
+ createVNode(unref(TMagicButton), {
1350
+ size: "small",
1351
+ type: "primary",
1352
+ disabled: _ctx.disabled,
1353
+ plain: "",
1354
+ onClick: createCodeHandler
1355
+ }, {
1356
+ default: withCtx(() => [
1357
+ createTextVNode("添加")
1358
+ ]),
1359
+ _: 1
1360
+ }, 8, ["disabled"])
1361
+ ]),
1362
+ unref(codeConfig) ? (openBlock(), createBlock(_sfc_main$G, {
1363
+ key: 0,
1364
+ ref_key: "codeBlockEditor",
1365
+ ref: codeBlockEditor,
1366
+ disabled: _ctx.disabled,
1367
+ content: unref(codeConfig),
1368
+ onSubmit: submitCodeHandler
1369
+ }, null, 8, ["disabled", "content"])) : createCommentVNode("", true)
1370
+ ]);
1371
+ };
1372
+ }
1373
+ });
1374
+
1375
+ const _hoisted_1$l = { class: "m-fields-data-source-method-select" };
1376
+ const _hoisted_2$b = { class: "data-source-method-select-container" };
1377
+ const _sfc_main$z = /* @__PURE__ */ defineComponent({
1378
+ ...{
1379
+ name: "MEditorDataSourceMethodSelect"
1380
+ },
1381
+ __name: "DataSourceMethodSelect",
1382
+ props: {
1383
+ config: {},
1384
+ model: {},
1385
+ lastValues: {},
1386
+ prop: {},
1387
+ name: {},
1388
+ disabled: { type: Boolean, default: false },
1389
+ size: {}
1390
+ },
1391
+ emits: ["change"],
1392
+ setup(__props, { emit }) {
1393
+ const props = __props;
1394
+ const services = inject("services");
1395
+ const dataSources = computed(() => services?.dataSourceService.get("dataSources"));
1396
+ const getParamItemsConfig = ([dataSourceId, medthodName] = ["", ""]) => {
1397
+ if (!dataSourceId)
1398
+ return [];
1399
+ const paramStatements = dataSources.value?.find((item) => item.id === dataSourceId)?.methods?.find((item) => item.name === medthodName)?.params;
1400
+ if (!paramStatements)
1401
+ return [];
1402
+ return paramStatements.map((paramState) => ({
1403
+ labelWidth: "100px",
1404
+ text: paramState.name,
1405
+ ...paramState
1406
+ }));
1407
+ };
1408
+ const paramsConfig = ref(getParamItemsConfig(props.model.dataSourceMethod));
1409
+ const setParamsConfig = (dataSourceMethod, formState = {}) => {
1410
+ paramsConfig.value = dataSourceMethod ? getParamItemsConfig(dataSourceMethod) : [];
1411
+ if (paramsConfig.value.length) {
1412
+ props.model.params = createValues(formState, paramsConfig.value, {}, props.model.params);
1413
+ } else {
1414
+ props.model.params = {};
1415
+ }
1416
+ };
1417
+ const cascaderConfig = {
1418
+ type: "cascader",
1419
+ text: "数据源方法",
1420
+ name: props.name,
1421
+ labelWidth: "80px",
1422
+ options: () => dataSources.value?.filter((ds) => ds.methods?.length)?.map((ds) => ({
1423
+ label: `${ds.title}(${ds.id})`,
1424
+ value: ds.id,
1425
+ children: ds.methods?.map((method) => ({
1426
+ label: method.name,
1427
+ value: method.name
1428
+ }))
1429
+ })) || [],
1430
+ onChange: (formState, dataSourceMethod) => {
1431
+ setParamsConfig(dataSourceMethod, formState);
1432
+ return dataSourceMethod;
1433
+ }
1434
+ };
1435
+ const onChangeHandler = (value) => {
1436
+ props.model.params = value.params;
1437
+ emit("change", props.model);
1438
+ };
1439
+ const { codeBlockEditor, codeConfig, editCode, submitCode } = useDataSourceMethod();
1440
+ const editCodeHandler = () => {
1441
+ const [id, name] = props.model[props.name];
1442
+ const dataSource = services?.dataSourceService.getDataSourceById(id);
1443
+ if (!dataSource)
1444
+ return;
1445
+ editCode(dataSource, name);
1446
+ setParamsConfig([id, name]);
1447
+ };
1448
+ const submitCodeBlockHandler = (value) => {
1449
+ submitCode(value);
1450
+ };
1451
+ return (_ctx, _cache) => {
1452
+ const _component_m_form_container = resolveComponent("m-form-container");
1453
+ return openBlock(), createElementBlock("div", _hoisted_1$l, [
1454
+ createElementVNode("div", _hoisted_2$b, [
1455
+ createVNode(_component_m_form_container, {
1456
+ class: "select",
1457
+ config: cascaderConfig,
1458
+ model: _ctx.model,
1459
+ onChange: onChangeHandler
1460
+ }, null, 8, ["model"]),
1461
+ _ctx.model[_ctx.name] ? (openBlock(), createBlock(_sfc_main$E, {
1462
+ key: 0,
1463
+ class: "icon",
1464
+ icon: !_ctx.disabled ? unref(Edit) : unref(View),
1465
+ onClick: editCodeHandler
1466
+ }, null, 8, ["icon"])) : createCommentVNode("", true)
1467
+ ]),
1468
+ paramsConfig.value.length ? (openBlock(), createBlock(_sfc_main$F, {
1469
+ key: 0,
1470
+ name: "params",
1471
+ model: _ctx.model,
1472
+ size: _ctx.size,
1473
+ disabled: _ctx.disabled,
1474
+ "params-config": paramsConfig.value,
1475
+ onChange: onChangeHandler
1476
+ }, null, 8, ["model", "size", "disabled", "params-config"])) : createCommentVNode("", true),
1477
+ unref(codeConfig) ? (openBlock(), createBlock(_sfc_main$G, {
1478
+ key: 1,
1479
+ ref_key: "codeBlockEditor",
1480
+ ref: codeBlockEditor,
1481
+ disabled: _ctx.disabled,
1482
+ content: unref(codeConfig),
1483
+ onSubmit: submitCodeBlockHandler
1484
+ }, null, 8, ["disabled", "content"])) : createCommentVNode("", true)
1485
+ ]);
801
1486
  };
802
1487
  }
803
1488
  });
804
1489
 
805
- const _sfc_main$A = /* @__PURE__ */ defineComponent({
1490
+ const _sfc_main$y = /* @__PURE__ */ defineComponent({
806
1491
  ...{
807
1492
  name: "MEditorDataSourceSelect"
808
1493
  },
@@ -855,12 +1540,12 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
855
1540
  }
856
1541
  });
857
1542
 
858
- const _hoisted_1$l = { class: "m-fields-event-select" };
859
- const _hoisted_2$c = {
1543
+ const _hoisted_1$k = { class: "m-fields-event-select" };
1544
+ const _hoisted_2$a = {
860
1545
  key: 1,
861
1546
  class: "fullWidth"
862
1547
  };
863
- const _sfc_main$z = /* @__PURE__ */ defineComponent({
1548
+ const _sfc_main$x = /* @__PURE__ */ defineComponent({
864
1549
  ...{
865
1550
  name: "MEditorEventSelect"
866
1551
  },
@@ -893,7 +1578,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
893
1578
  const defaultActionTypeConfig = {
894
1579
  name: "actionType",
895
1580
  text: "联动类型",
896
- labelWidth: "70px",
1581
+ labelWidth: "80px",
897
1582
  type: "select",
898
1583
  defaultValue: ActionType.COMP,
899
1584
  options: () => [
@@ -905,7 +1590,14 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
905
1590
  {
906
1591
  text: "代码",
907
1592
  label: "代码",
1593
+ disabled: !Object.keys(services?.codeBlockService.getCodeDsl() || {}).length,
908
1594
  value: ActionType.CODE
1595
+ },
1596
+ {
1597
+ text: "数据源",
1598
+ label: "数据源",
1599
+ disabled: !services?.dataSourceService.get("dataSources")?.filter((ds) => ds.methods?.length).length,
1600
+ value: ActionType.DATA_SOURCE
909
1601
  }
910
1602
  ]
911
1603
  };
@@ -915,7 +1607,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
915
1607
  const defaultTargetCompConfig = {
916
1608
  name: "to",
917
1609
  text: "联动组件",
918
- labelWidth: "70px",
1610
+ labelWidth: "80px",
919
1611
  type: "ui-select",
920
1612
  display: (mForm, { model }) => model.actionType === ActionType.COMP
921
1613
  };
@@ -925,7 +1617,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
925
1617
  const defaultCompActionConfig = {
926
1618
  name: "method",
927
1619
  text: "动作",
928
- labelWidth: "70px",
1620
+ labelWidth: "80px",
929
1621
  type: "select",
930
1622
  display: (mForm, { model }) => model.actionType === ActionType.COMP,
931
1623
  options: (mForm, { model }) => {
@@ -944,10 +1636,21 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
944
1636
  const defaultCodeActionConfig = {
945
1637
  type: "code-select-col",
946
1638
  labelWidth: 0,
1639
+ name: "codeId",
1640
+ disabled: () => !services?.codeBlockService.getEditStatus(),
947
1641
  display: (mForm, { model }) => model.actionType === ActionType.CODE
948
1642
  };
949
1643
  return { ...defaultCodeActionConfig, ...props.config.codeActionConfig };
950
1644
  });
1645
+ const dataSourceActionConfig = computed(() => {
1646
+ const defaultDataSourceActionConfig = {
1647
+ type: "data-source-method-select",
1648
+ name: "dataSourceMethod",
1649
+ labelWidth: 0,
1650
+ display: (mForm, { model }) => model.actionType === ActionType.DATA_SOURCE
1651
+ };
1652
+ return { ...defaultDataSourceActionConfig, ...props.config.dataSourceActionConfig };
1653
+ });
951
1654
  const tableConfig = computed(() => ({
952
1655
  type: "table",
953
1656
  name: "events",
@@ -989,7 +1692,13 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
989
1692
  name: "actions",
990
1693
  expandAll: true,
991
1694
  enableToggleMode: false,
992
- items: [actionTypeConfig.value, targetCompConfig.value, compActionConfig.value, codeActionConfig.value]
1695
+ items: [
1696
+ actionTypeConfig.value,
1697
+ targetCompConfig.value,
1698
+ compActionConfig.value,
1699
+ codeActionConfig.value,
1700
+ dataSourceActionConfig.value
1701
+ ]
993
1702
  }
994
1703
  ]
995
1704
  }));
@@ -1022,7 +1731,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
1022
1731
  const _component_m_form_table = resolveComponent("m-form-table");
1023
1732
  const _component_m_form_container = resolveComponent("m-form-container");
1024
1733
  const _component_m_form_panel = resolveComponent("m-form-panel");
1025
- return openBlock(), createElementBlock("div", _hoisted_1$l, [
1734
+ return openBlock(), createElementBlock("div", _hoisted_1$k, [
1026
1735
  isOldVersion.value ? (openBlock(), createBlock(_component_m_form_table, {
1027
1736
  key: 0,
1028
1737
  ref: "eventForm",
@@ -1031,7 +1740,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
1031
1740
  name: "events",
1032
1741
  config: tableConfig.value,
1033
1742
  onChange: onChangeHandler
1034
- }, null, 8, ["size", "model", "config"])) : (openBlock(), createElementBlock("div", _hoisted_2$c, [
1743
+ }, null, 8, ["size", "model", "config"])) : (openBlock(), createElementBlock("div", _hoisted_2$a, [
1035
1744
  createVNode(unref(TMagicButton), {
1036
1745
  class: "create-button",
1037
1746
  type: "primary",
@@ -1073,9 +1782,9 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
1073
1782
  }
1074
1783
  });
1075
1784
 
1076
- const _hoisted_1$k = { class: "m-fields-key-value" };
1077
- const _hoisted_2$b = /* @__PURE__ */ createElementVNode("span", { class: "m-fileds-key-value-delimiter" }, ":", -1);
1078
- const _sfc_main$y = /* @__PURE__ */ defineComponent({
1785
+ const _hoisted_1$j = { class: "m-fields-key-value" };
1786
+ const _hoisted_2$9 = /* @__PURE__ */ createElementVNode("span", { class: "m-fileds-key-value-delimiter" }, ":", -1);
1787
+ const _sfc_main$w = /* @__PURE__ */ defineComponent({
1079
1788
  ...{
1080
1789
  name: "MEditorKeyValue"
1081
1790
  },
@@ -1118,7 +1827,7 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
1118
1827
  records.value.splice(index, 1);
1119
1828
  };
1120
1829
  return (_ctx, _cache) => {
1121
- return openBlock(), createElementBlock("div", _hoisted_1$k, [
1830
+ return openBlock(), createElementBlock("div", _hoisted_1$j, [
1122
1831
  (openBlock(true), createElementBlock(Fragment, null, renderList(records.value, (item, index) => {
1123
1832
  return openBlock(), createElementBlock("div", {
1124
1833
  class: "m-fields-key-value-item",
@@ -1132,7 +1841,7 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
1132
1841
  size: _ctx.size,
1133
1842
  onChange: keyChangeHandler
1134
1843
  }, null, 8, ["modelValue", "onUpdate:modelValue", "disabled", "size"]),
1135
- _hoisted_2$b,
1844
+ _hoisted_2$9,
1136
1845
  createVNode(unref(TMagicInput), {
1137
1846
  placeholder: "value",
1138
1847
  modelValue: records.value[index][1],
@@ -1169,7 +1878,12 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
1169
1878
  }
1170
1879
  });
1171
1880
 
1172
- const _sfc_main$x = /* @__PURE__ */ defineComponent({
1881
+ const _hoisted_1$i = {
1882
+ key: 1,
1883
+ class: "m-fields-ui-select",
1884
+ style: { "display": "flex" }
1885
+ };
1886
+ const _sfc_main$v = /* @__PURE__ */ defineComponent({
1173
1887
  ...{
1174
1888
  name: "MEditorUISelect"
1175
1889
  },
@@ -1222,6 +1936,18 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
1222
1936
  mForm?.$emit("field-change", props.prop, "");
1223
1937
  }
1224
1938
  };
1939
+ const selectNode = async (id) => {
1940
+ await services?.editorService.select(id);
1941
+ services?.editorService.get("stage")?.select(id);
1942
+ };
1943
+ const highlight = throttle((id) => {
1944
+ services?.editorService.highlight(id);
1945
+ services?.editorService.get("stage")?.highlight(id);
1946
+ }, 150);
1947
+ const unhightlight = () => {
1948
+ services?.editorService.set("highlightNode", null);
1949
+ services?.editorService.get("stage")?.clearHighlight();
1950
+ };
1225
1951
  return (_ctx, _cache) => {
1226
1952
  return uiSelectMode.value ? (openBlock(), createElementBlock("div", {
1227
1953
  key: 0,
@@ -1239,195 +1965,70 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
1239
1965
  ]),
1240
1966
  _: 1
1241
1967
  }, 8, ["icon"])
1242
- ])) : (openBlock(), createElementBlock("div", {
1243
- key: 1,
1244
- class: "m-fields-ui-select",
1245
- onClick: startSelect,
1246
- style: { "display": "flex" }
1247
- }, [
1248
- val.value ? (openBlock(), createBlock(unref(TMagicTooltip), {
1249
- key: 0,
1250
- content: "清除"
1251
- }, {
1252
- default: withCtx(() => [
1253
- createVNode(unref(TMagicButton), {
1254
- style: { "padding": "0" },
1255
- type: "danger",
1256
- icon: unref(Close),
1257
- text: "",
1258
- onClick: withModifiers(deleteHandler, ["stop"])
1259
- }, null, 8, ["icon", "onClick"])
1260
- ]),
1261
- _: 1
1262
- })) : createCommentVNode("", true),
1263
- createVNode(unref(TMagicTooltip), {
1264
- content: val.value ? toName.value + "_" + val.value : "点击此处选择"
1968
+ ])) : (openBlock(), createElementBlock("div", _hoisted_1$i, [
1969
+ val.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
1970
+ createVNode(unref(TMagicTooltip), {
1971
+ content: "清除",
1972
+ placement: "top"
1973
+ }, {
1974
+ default: withCtx(() => [
1975
+ createVNode(unref(TMagicButton), {
1976
+ style: { "padding": "0" },
1977
+ type: "danger",
1978
+ icon: unref(Close),
1979
+ text: "",
1980
+ onClick: withModifiers(deleteHandler, ["stop"])
1981
+ }, null, 8, ["icon", "onClick"])
1982
+ ]),
1983
+ _: 1
1984
+ }),
1985
+ createVNode(unref(TMagicTooltip), {
1986
+ content: "点击选中组件",
1987
+ placement: "top"
1988
+ }, {
1989
+ default: withCtx(() => [
1990
+ createVNode(unref(TMagicButton), {
1991
+ text: "",
1992
+ style: { "padding": "0", "margin": "0" },
1993
+ onClick: _cache[0] || (_cache[0] = ($event) => selectNode(val.value)),
1994
+ onMouseenter: _cache[1] || (_cache[1] = ($event) => unref(highlight)(val.value)),
1995
+ onMouseleave: unhightlight
1996
+ }, {
1997
+ default: withCtx(() => [
1998
+ createTextVNode(toDisplayString(`${toName.value}_${val.value}`), 1)
1999
+ ]),
2000
+ _: 1
2001
+ })
2002
+ ]),
2003
+ _: 1
2004
+ })
2005
+ ], 64)) : (openBlock(), createBlock(unref(TMagicTooltip), {
2006
+ key: 1,
2007
+ content: "点击此处选择",
2008
+ placement: "top"
1265
2009
  }, {
1266
2010
  default: withCtx(() => [
1267
2011
  createVNode(unref(TMagicButton), {
1268
2012
  text: "",
1269
- style: { "padding": "0", "margin": "0" }
2013
+ style: { "padding": "0", "margin": "0" },
2014
+ onClick: startSelect
1270
2015
  }, {
1271
- default: withCtx(() => [
1272
- createTextVNode(toDisplayString(val.value ? toName.value + "_" + val.value : "点击此处选择"), 1)
1273
- ]),
1274
- _: 1
1275
- })
1276
- ]),
1277
- _: 1
1278
- }, 8, ["content"])
1279
- ]));
1280
- };
1281
- }
1282
- });
1283
-
1284
- const UISelect_vue_vue_type_style_index_0_lang = '';
1285
-
1286
- const _sfc_main$w = /* @__PURE__ */ defineComponent({
1287
- ...{
1288
- name: "MEditorCodeEditor"
1289
- },
1290
- __name: "CodeEditor",
1291
- props: {
1292
- initValues: {},
1293
- modifiedValues: {},
1294
- type: {},
1295
- language: { default: "javascript" },
1296
- options: { default: () => ({
1297
- tabSize: 2
1298
- }) },
1299
- autoSave: { type: Boolean, default: true }
1300
- },
1301
- emits: ["initd", "save"],
1302
- setup(__props, { expose: __expose, emit }) {
1303
- const props = __props;
1304
- const toString = (v, language) => {
1305
- let value = "";
1306
- if (typeof v !== "string") {
1307
- if (props.language.toLocaleLowerCase() === "json") {
1308
- value = JSON.stringify(v, null, 2);
1309
- } else {
1310
- value = serialize(v, {
1311
- space: 2,
1312
- unsafe: true
1313
- }).replace(/"(\w+)":\s/g, "$1: ");
1314
- }
1315
- } else {
1316
- value = v;
1317
- }
1318
- if (language === "javascript" && value.startsWith("{") && value.endsWith("}")) {
1319
- value = `(${value})`;
1320
- }
1321
- return value;
1322
- };
1323
- let vsEditor = null;
1324
- let vsDiffEditor = null;
1325
- const values = ref("");
1326
- const loading = ref(false);
1327
- const codeEditor = ref();
1328
- const resizeObserver = new globalThis.ResizeObserver(
1329
- throttle(() => {
1330
- vsEditor?.layout();
1331
- vsDiffEditor?.layout();
1332
- }, 300)
1333
- );
1334
- const setEditorValue = (v, m) => {
1335
- values.value = toString(v, props.language);
1336
- if (props.type === "diff") {
1337
- const originalModel = monaco.editor.createModel(values.value, "text/javascript");
1338
- const modifiedModel = monaco.editor.createModel(toString(m, props.language), "text/javascript");
1339
- return vsDiffEditor?.setModel({
1340
- original: originalModel,
1341
- modified: modifiedModel
1342
- });
1343
- }
1344
- return vsEditor?.setValue(values.value);
1345
- };
1346
- const getEditorValue = () => (props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || "";
1347
- const init = async () => {
1348
- if (!codeEditor.value)
1349
- return;
1350
- const options = {
1351
- value: values.value,
1352
- language: props.language,
1353
- theme: "vs-dark",
1354
- ...props.options
1355
- };
1356
- if (props.type === "diff") {
1357
- vsDiffEditor = monaco.editor.createDiffEditor(codeEditor.value, options);
1358
- } else {
1359
- vsEditor = monaco.editor.create(codeEditor.value, options);
1360
- }
1361
- setEditorValue(props.initValues, props.modifiedValues);
1362
- loading.value = false;
1363
- emit("initd", vsEditor);
1364
- codeEditor.value.addEventListener("keydown", (e) => {
1365
- if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
1366
- e.preventDefault();
1367
- e.stopPropagation();
1368
- const newValue = getEditorValue();
1369
- values.value = newValue;
1370
- emit("save", newValue);
1371
- }
1372
- });
1373
- if (props.type !== "diff" && props.autoSave) {
1374
- vsEditor?.onDidBlurEditorWidget(() => {
1375
- const newValue = getEditorValue();
1376
- if (values.value !== newValue) {
1377
- values.value = newValue;
1378
- emit("save", newValue);
1379
- }
1380
- });
1381
- }
1382
- resizeObserver.observe(codeEditor.value);
1383
- };
1384
- watch(
1385
- () => props.initValues,
1386
- (v, preV) => {
1387
- if (v !== preV) {
1388
- setEditorValue(props.initValues, props.modifiedValues);
1389
- }
1390
- },
1391
- {
1392
- deep: true,
1393
- immediate: true
1394
- }
1395
- );
1396
- onMounted(async () => {
1397
- loading.value = true;
1398
- init();
1399
- });
1400
- onUnmounted(() => {
1401
- resizeObserver.disconnect();
1402
- });
1403
- __expose({
1404
- values,
1405
- getEditor() {
1406
- return vsEditor || vsDiffEditor;
1407
- },
1408
- getVsEditor() {
1409
- return vsEditor;
1410
- },
1411
- getVsDiffEditor() {
1412
- return vsDiffEditor;
1413
- },
1414
- setEditorValue,
1415
- focus() {
1416
- vsEditor?.focus();
1417
- vsDiffEditor?.focus();
1418
- }
1419
- });
1420
- return (_ctx, _cache) => {
1421
- return openBlock(), createElementBlock("div", {
1422
- ref_key: "codeEditor",
1423
- ref: codeEditor,
1424
- class: "magic-code-editor"
1425
- }, null, 512);
2016
+ default: withCtx(() => [
2017
+ createTextVNode("点击此处选择")
2018
+ ]),
2019
+ _: 1
2020
+ })
2021
+ ]),
2022
+ _: 1
2023
+ }))
2024
+ ]));
1426
2025
  };
1427
2026
  }
1428
2027
  });
1429
2028
 
1430
- const _sfc_main$v = /* @__PURE__ */ defineComponent({
2029
+ const UISelect_vue_vue_type_style_index_0_lang = '';
2030
+
2031
+ const _sfc_main$u = /* @__PURE__ */ defineComponent({
1431
2032
  ...{
1432
2033
  name: "MEditorResizer"
1433
2034
  },
@@ -1469,7 +2070,7 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
1469
2070
  }
1470
2071
  });
1471
2072
 
1472
- const _sfc_main$u = /* @__PURE__ */ defineComponent({
2073
+ const _sfc_main$t = /* @__PURE__ */ defineComponent({
1473
2074
  ...{
1474
2075
  name: "MEditorLayout"
1475
2076
  },
@@ -1581,7 +2182,7 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
1581
2182
  }, [
1582
2183
  renderSlot(_ctx.$slots, "left")
1583
2184
  ], 6),
1584
- createVNode(_sfc_main$v, { onChange: changeLeft })
2185
+ createVNode(_sfc_main$u, { onChange: changeLeft })
1585
2186
  ], 64)) : createCommentVNode("", true),
1586
2187
  createElementVNode("div", {
1587
2188
  class: normalizeClass(["m-editor-layout-center", _ctx.centerClass]),
@@ -1590,7 +2191,7 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
1590
2191
  renderSlot(_ctx.$slots, "center")
1591
2192
  ], 6),
1592
2193
  hasRight.value && _ctx.$slots.right ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
1593
- createVNode(_sfc_main$v, { onChange: changeRight }),
2194
+ createVNode(_sfc_main$u, { onChange: changeRight }),
1594
2195
  createElementVNode("div", {
1595
2196
  class: normalizeClass(["m-editor-layout-right", _ctx.rightClass]),
1596
2197
  style: normalizeStyle(`width: ${_ctx.right}px`)
@@ -3513,10 +4114,10 @@ const useStage = (stageOptions) => {
3513
4114
  return stage;
3514
4115
  };
3515
4116
 
3516
- const _hoisted_1$j = { class: "m-editor-empty-panel" };
3517
- const _hoisted_2$a = { class: "m-editor-empty-content" };
3518
- const _hoisted_3$5 = /* @__PURE__ */ createElementVNode("p", null, "新增页面", -1);
3519
- const _sfc_main$t = /* @__PURE__ */ defineComponent({
4117
+ const _hoisted_1$h = { class: "m-editor-empty-panel" };
4118
+ const _hoisted_2$8 = { class: "m-editor-empty-content" };
4119
+ const _hoisted_3$4 = /* @__PURE__ */ createElementVNode("p", null, "新增页面", -1);
4120
+ const _sfc_main$s = /* @__PURE__ */ defineComponent({
3520
4121
  ...{
3521
4122
  name: "MEditorAddPageBox"
3522
4123
  },
@@ -3536,8 +4137,8 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
3536
4137
  });
3537
4138
  };
3538
4139
  return (_ctx, _cache) => {
3539
- return openBlock(), createElementBlock("div", _hoisted_1$j, [
3540
- createElementVNode("div", _hoisted_2$a, [
4140
+ return openBlock(), createElementBlock("div", _hoisted_1$h, [
4141
+ createElementVNode("div", _hoisted_2$8, [
3541
4142
  createElementVNode("div", {
3542
4143
  class: "m-editor-empty-button",
3543
4144
  onClick: clickHandler
@@ -3545,7 +4146,7 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
3545
4146
  createElementVNode("div", null, [
3546
4147
  createVNode(_sfc_main$E, { icon: unref(Plus) }, null, 8, ["icon"])
3547
4148
  ]),
3548
- _hoisted_3$5
4149
+ _hoisted_3$4
3549
4150
  ])
3550
4151
  ])
3551
4152
  ]);
@@ -3553,12 +4154,11 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
3553
4154
  }
3554
4155
  });
3555
4156
 
3556
- const _hoisted_1$i = { class: "m-editor" };
3557
4157
  const DEFAULT_LEFT_COLUMN_WIDTH = 310;
3558
4158
  const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
3559
4159
  const LEFT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorLeftColumnWidthData";
3560
4160
  const RIGHT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorRightColumnWidthData";
3561
- const _sfc_main$s = /* @__PURE__ */ defineComponent({
4161
+ const _sfc_main$r = /* @__PURE__ */ defineComponent({
3562
4162
  ...{
3563
4163
  name: "MEditorFramework"
3564
4164
  },
@@ -3566,6 +4166,7 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
3566
4166
  setup(__props) {
3567
4167
  const codeOptions = inject("codeOptions", {});
3568
4168
  const { editorService, uiService } = inject("services") || {};
4169
+ const content = ref();
3569
4170
  const root = computed(() => editorService?.get("root"));
3570
4171
  const pageLength = computed(() => editorService?.get("pageLength") || 0);
3571
4172
  const showSrc = computed(() => uiService?.get("showSrc"));
@@ -3581,13 +4182,14 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
3581
4182
  (length) => {
3582
4183
  const left = columnWidth.value.left || DEFAULT_LEFT_COLUMN_WIDTH;
3583
4184
  columnWidth.value.left = left;
4185
+ const container = content.value || document.body;
3584
4186
  if (length <= 0) {
3585
4187
  columnWidth.value.right = void 0;
3586
- columnWidth.value.center = globalThis.document.body.clientWidth - left;
4188
+ columnWidth.value.center = container.clientWidth - left;
3587
4189
  } else {
3588
4190
  const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
3589
4191
  columnWidth.value.right = right;
3590
- columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
4192
+ columnWidth.value.center = container.clientWidth - left - right;
3591
4193
  }
3592
4194
  uiService?.set("columnWidth", columnWidth.value);
3593
4195
  },
@@ -3624,18 +4226,22 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
3624
4226
  }
3625
4227
  };
3626
4228
  return (_ctx, _cache) => {
3627
- return openBlock(), createElementBlock("div", _hoisted_1$i, [
4229
+ return openBlock(), createElementBlock("div", {
4230
+ class: "m-editor",
4231
+ ref_key: "content",
4232
+ ref: content
4233
+ }, [
3628
4234
  renderSlot(_ctx.$slots, "header"),
3629
4235
  renderSlot(_ctx.$slots, "nav"),
3630
4236
  renderSlot(_ctx.$slots, "content-before"),
3631
4237
  showSrc.value ? renderSlot(_ctx.$slots, "src-code", { key: 0 }, () => [
3632
- createVNode(_sfc_main$w, {
4238
+ createVNode(_sfc_main$K, {
3633
4239
  class: "m-editor-content",
3634
4240
  "init-values": root.value,
3635
4241
  options: unref(codeOptions),
3636
4242
  onSave: saveCode
3637
4243
  }, null, 8, ["init-values", "options"])
3638
- ]) : (openBlock(), createBlock(_sfc_main$u, {
4244
+ ]) : (openBlock(), createBlock(_sfc_main$t, {
3639
4245
  key: 1,
3640
4246
  class: "m-editor-content",
3641
4247
  "left-class": "m-editor-framework-left",
@@ -3654,7 +4260,7 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
3654
4260
  ]),
3655
4261
  center: withCtx(() => [
3656
4262
  pageLength.value > 0 ? renderSlot(_ctx.$slots, "workspace", { key: 0 }) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
3657
- createVNode(_sfc_main$t)
4263
+ createVNode(_sfc_main$s)
3658
4264
  ])
3659
4265
  ]),
3660
4266
  _: 2
@@ -3674,17 +4280,17 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
3674
4280
  ]), 1032, ["left", "right"])),
3675
4281
  renderSlot(_ctx.$slots, "content-after"),
3676
4282
  renderSlot(_ctx.$slots, "footer")
3677
- ]);
4283
+ ], 512);
3678
4284
  };
3679
4285
  }
3680
4286
  });
3681
4287
 
3682
- const _hoisted_1$h = {
4288
+ const _hoisted_1$g = {
3683
4289
  key: 1,
3684
4290
  class: "menu-item-text"
3685
4291
  };
3686
- const _hoisted_2$9 = { class: "el-dropdown-link menubar-menu-button" };
3687
- const _sfc_main$r = /* @__PURE__ */ defineComponent({
4292
+ const _hoisted_2$7 = { class: "el-dropdown-link menubar-menu-button" };
4293
+ const _sfc_main$q = /* @__PURE__ */ defineComponent({
3688
4294
  ...{
3689
4295
  name: "MEditorToolButton"
3690
4296
  },
@@ -3763,7 +4369,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
3763
4369
  _ctx.data.type === "divider" ? (openBlock(), createBlock(unref(TMagicDivider), {
3764
4370
  key: 0,
3765
4371
  direction: _ctx.data.direction || "vertical"
3766
- }, null, 8, ["direction"])) : _ctx.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$h, toDisplayString(_ctx.data.text), 1)) : _ctx.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
4372
+ }, null, 8, ["direction"])) : _ctx.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$g, toDisplayString(_ctx.data.text), 1)) : _ctx.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
3767
4373
  _ctx.data.tooltip ? (openBlock(), createBlock(unref(TMagicTooltip), {
3768
4374
  key: 0,
3769
4375
  effect: "dark",
@@ -3827,7 +4433,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
3827
4433
  })) : createCommentVNode("", true)
3828
4434
  ]),
3829
4435
  default: withCtx(() => [
3830
- createElementVNode("span", _hoisted_2$9, [
4436
+ createElementVNode("span", _hoisted_2$7, [
3831
4437
  createTextVNode(toDisplayString(_ctx.data.text), 1),
3832
4438
  createVNode(unref(TMagicIcon), { class: "el-icon--right" }, {
3833
4439
  default: withCtx(() => [
@@ -3844,7 +4450,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
3844
4450
  }
3845
4451
  });
3846
4452
 
3847
- const _sfc_main$q = /* @__PURE__ */ defineComponent({
4453
+ const _sfc_main$p = /* @__PURE__ */ defineComponent({
3848
4454
  ...{
3849
4455
  name: "MEditorNavMenu"
3850
4456
  },
@@ -4006,7 +4612,7 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
4006
4612
  style: normalizeStyle(`width: ${columnWidth.value?.[key]}px`)
4007
4613
  }, [
4008
4614
  (openBlock(true), createElementBlock(Fragment, null, renderList(buttons.value[key], (item, index) => {
4009
- return openBlock(), createBlock(_sfc_main$r, {
4615
+ return openBlock(), createBlock(_sfc_main$q, {
4010
4616
  data: item,
4011
4617
  key: index
4012
4618
  }, null, 8, ["data"]);
@@ -4018,8 +4624,8 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
4018
4624
  }
4019
4625
  });
4020
4626
 
4021
- const _hoisted_1$g = { class: "m-editor-props-panel" };
4022
- const _sfc_main$p = /* @__PURE__ */ defineComponent({
4627
+ const _hoisted_1$f = { class: "m-editor-props-panel" };
4628
+ const _sfc_main$o = /* @__PURE__ */ defineComponent({
4023
4629
  ...{
4024
4630
  name: "MEditorPropsPanel"
4025
4631
  },
@@ -4072,7 +4678,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
4072
4678
  };
4073
4679
  __expose({ configForm, submit });
4074
4680
  return (_ctx, _cache) => {
4075
- return withDirectives((openBlock(), createElementBlock("div", _hoisted_1$g, [
4681
+ return withDirectives((openBlock(), createElementBlock("div", _hoisted_1$f, [
4076
4682
  renderSlot(_ctx.$slots, "props-panel-header"),
4077
4683
  createVNode(unref(MForm), {
4078
4684
  ref_key: "configForm",
@@ -4092,7 +4698,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
4092
4698
  }
4093
4699
  });
4094
4700
 
4095
- const _sfc_main$o = /* @__PURE__ */ defineComponent({
4701
+ const _sfc_main$n = /* @__PURE__ */ defineComponent({
4096
4702
  ...{
4097
4703
  name: "MEditorSearchInput"
4098
4704
  },
@@ -4127,8 +4733,8 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
4127
4733
  }
4128
4734
  });
4129
4735
 
4130
- const _hoisted_1$f = { xmlns: "http://www.w3.org/2000/svg" };
4131
- const _hoisted_2$8 = /* @__PURE__ */ createElementVNode("g", {
4736
+ const _hoisted_1$e = { xmlns: "http://www.w3.org/2000/svg" };
4737
+ const _hoisted_2$6 = /* @__PURE__ */ createElementVNode("g", {
4132
4738
  fill: "#7C878E",
4133
4739
  "fill-rule": "evenodd"
4134
4740
  }, [
@@ -4138,488 +4744,60 @@ const _hoisted_2$8 = /* @__PURE__ */ createElementVNode("g", {
4138
4744
  }),
4139
4745
  /* @__PURE__ */ createElementVNode("path", { d: "M8 13.5L2.3 9.2 0.7 10.5 8 16 15.3 10.5 13.7 9.2z" })
4140
4746
  ], -1);
4141
- const _hoisted_3$4 = [
4142
- _hoisted_2$8
4747
+ const _hoisted_3$3 = [
4748
+ _hoisted_2$6
4143
4749
  ];
4144
- const _sfc_main$n = /* @__PURE__ */ defineComponent({
4750
+ const _sfc_main$m = /* @__PURE__ */ defineComponent({
4145
4751
  ...{
4146
4752
  name: "MEditorAppManageIcon"
4147
4753
  },
4148
4754
  __name: "AppManageIcon",
4149
4755
  setup(__props) {
4150
4756
  return (_ctx, _cache) => {
4151
- return openBlock(), createElementBlock("svg", _hoisted_1$f, _hoisted_3$4);
4757
+ return openBlock(), createElementBlock("svg", _hoisted_1$e, _hoisted_3$3);
4152
4758
  };
4153
4759
  }
4154
4760
  });
4155
4761
 
4156
- const _hoisted_1$e = {
4762
+ const _hoisted_1$d = {
4157
4763
  viewBox: "0 0 32 32",
4158
4764
  version: "1.1",
4159
4765
  xmlns: "http://www.w3.org/2000/svg",
4160
4766
  "xmlns:xlink": "http://www.w3.org/1999/xlink"
4161
4767
  };
4162
- const _hoisted_2$7 = /* @__PURE__ */ createStaticVNode('<defs><rect id="path-1" x="0" y="0" width="32" height="32"></rect></defs><g id="组件规范" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="03图标" transform="translate(-561.000000, -2356.000000)"><g id="icon/line/Universal/code" transform="translate(561.000000, 2356.000000)"><g id="路径"><mask id="mask-2" fill="white"><use xlink:href="#path-1"></use></mask><use id="蒙版" fill="#D8D8D8" opacity="0" xlink:href="#path-1"></use><path d="M21.9284587,7.9482233 L29.8079004,15.827665 C29.9055315,15.9252961 29.9055315,16.0835874 29.8079004,16.1812184 L21.9284587,24.0606602 C21.8308276,24.1582912 21.6725364,24.1582912 21.5749053,24.0606602 L20.3374684,22.8232233 C20.2419143,22.7276698 20.2398813,22.5740096 20.331369,22.4759832 L20.3374687,22.4696702 L26.8027181,16.0044417 L20.3374687,9.53921328 C20.2398372,9.44158265 20.2398369,9.2832914 20.3374679,9.18566017 L21.5749053,7.9482233 C21.6725364,7.85059223 21.8308276,7.85059223 21.9284587,7.9482233 Z M10.3999684,7.9482233 L11.6374053,9.18566017 C11.7329594,9.28121371 11.7349925,9.43487387 11.6435048,9.53290029 L11.637405,9.53921328 L5.17215562,16.0044417 L11.637405,22.4696702 C11.7329593,22.5652236 11.7349926,22.7188837 11.643505,22.8169103 L11.6374053,22.8232233 L10.3999684,24.0606602 C10.3023374,24.1582912 10.1440461,24.1582912 10.046415,24.0606602 L2.1669733,16.1812184 C2.06934223,16.0835874 2.06934223,15.9252961 2.1669733,15.827665 L10.046415,7.9482233 C10.1440461,7.85059223 10.3023374,7.85059223 10.3999684,7.9482233 Z M17.2612532,9.29310422 L18.9262468,9.83189578 C19.0576112,9.87440526 19.1296423,10.0153579 19.0871328,10.1467222 L15.0848232,22.514807 C15.0423138,22.6461714 14.9013612,22.7182025 14.7699968,22.675693 L13.1050032,22.1369014 C12.9736388,22.0943919 12.9016077,21.9534393 12.9441172,21.822075 L16.9464268,9.45399022 C16.9889362,9.32262585 17.1298888,9.25059474 17.2612532,9.29310422 Z" id="形状" fill="#1D1F24" mask="url(#mask-2)"></path></g></g><g id="icon切图" transform="translate(226.000000, 1782.000000)"></g></g></g>', 2);
4163
- const _hoisted_4$4 = [
4164
- _hoisted_2$7
4768
+ const _hoisted_2$5 = /* @__PURE__ */ createStaticVNode('<defs><rect id="path-1" x="0" y="0" width="32" height="32"></rect></defs><g id="组件规范" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="03图标" transform="translate(-561.000000, -2356.000000)"><g id="icon/line/Universal/code" transform="translate(561.000000, 2356.000000)"><g id="路径"><mask id="mask-2" fill="white"><use xlink:href="#path-1"></use></mask><use id="蒙版" fill="#D8D8D8" opacity="0" xlink:href="#path-1"></use><path d="M21.9284587,7.9482233 L29.8079004,15.827665 C29.9055315,15.9252961 29.9055315,16.0835874 29.8079004,16.1812184 L21.9284587,24.0606602 C21.8308276,24.1582912 21.6725364,24.1582912 21.5749053,24.0606602 L20.3374684,22.8232233 C20.2419143,22.7276698 20.2398813,22.5740096 20.331369,22.4759832 L20.3374687,22.4696702 L26.8027181,16.0044417 L20.3374687,9.53921328 C20.2398372,9.44158265 20.2398369,9.2832914 20.3374679,9.18566017 L21.5749053,7.9482233 C21.6725364,7.85059223 21.8308276,7.85059223 21.9284587,7.9482233 Z M10.3999684,7.9482233 L11.6374053,9.18566017 C11.7329594,9.28121371 11.7349925,9.43487387 11.6435048,9.53290029 L11.637405,9.53921328 L5.17215562,16.0044417 L11.637405,22.4696702 C11.7329593,22.5652236 11.7349926,22.7188837 11.643505,22.8169103 L11.6374053,22.8232233 L10.3999684,24.0606602 C10.3023374,24.1582912 10.1440461,24.1582912 10.046415,24.0606602 L2.1669733,16.1812184 C2.06934223,16.0835874 2.06934223,15.9252961 2.1669733,15.827665 L10.046415,7.9482233 C10.1440461,7.85059223 10.3023374,7.85059223 10.3999684,7.9482233 Z M17.2612532,9.29310422 L18.9262468,9.83189578 C19.0576112,9.87440526 19.1296423,10.0153579 19.0871328,10.1467222 L15.0848232,22.514807 C15.0423138,22.6461714 14.9013612,22.7182025 14.7699968,22.675693 L13.1050032,22.1369014 C12.9736388,22.0943919 12.9016077,21.9534393 12.9441172,21.822075 L16.9464268,9.45399022 C16.9889362,9.32262585 17.1298888,9.25059474 17.2612532,9.29310422 Z" id="形状" fill="#1D1F24" mask="url(#mask-2)"></path></g></g><g id="icon切图" transform="translate(226.000000, 1782.000000)"></g></g></g>', 2);
4769
+ const _hoisted_4$1 = [
4770
+ _hoisted_2$5
4165
4771
  ];
4166
- const _sfc_main$m = /* @__PURE__ */ defineComponent({
4772
+ const _sfc_main$l = /* @__PURE__ */ defineComponent({
4167
4773
  ...{
4168
4774
  name: "MEditorCodeIcon"
4169
4775
  },
4170
4776
  __name: "CodeIcon",
4171
4777
  setup(__props) {
4172
4778
  return (_ctx, _cache) => {
4173
- return openBlock(), createElementBlock("svg", _hoisted_1$e, _hoisted_4$4);
4174
- };
4175
- }
4176
- });
4177
-
4178
- const _hoisted_1$d = {
4179
- key: 0,
4180
- class: "m-editor-content-bottom"
4181
- };
4182
- const _hoisted_2$6 = {
4183
- key: 1,
4184
- class: "m-editor-content-bottom"
4185
- };
4186
- const _sfc_main$l = /* @__PURE__ */ defineComponent({
4187
- ...{
4188
- name: "MEditorCodeDraftEditor"
4189
- },
4190
- __name: "CodeDraftEditor",
4191
- props: {
4192
- id: {},
4193
- content: {},
4194
- editable: { type: Boolean, default: true },
4195
- autoSaveDraft: { type: Boolean, default: true },
4196
- codeOptions: {},
4197
- language: {}
4198
- },
4199
- emits: ["close", "saveAndClose"],
4200
- setup(__props, { expose: __expose, emit }) {
4201
- const props = __props;
4202
- const services = inject("services");
4203
- const codeContent = ref("");
4204
- const editorContent = ref("");
4205
- const codeEditor = ref();
4206
- const originCodeContent = ref("");
4207
- const isFullScreen = ref(false);
4208
- const codeOptions = computed(() => ({
4209
- ...props.codeOptions,
4210
- readOnly: !props.editable
4211
- }));
4212
- watchEffect(() => {
4213
- codeContent.value = props.content;
4214
- if (!originCodeContent.value) {
4215
- originCodeContent.value = codeContent.value;
4216
- }
4217
- const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
4218
- if (codeDraft) {
4219
- codeContent.value = codeDraft;
4220
- }
4221
- });
4222
- const saveCodeDraft = async (codeValue) => {
4223
- if (!props.autoSaveDraft)
4224
- return;
4225
- if (originCodeContent.value === codeValue) {
4226
- services?.codeBlockService.removeCodeDraft(props.id);
4227
- return;
4228
- }
4229
- services?.codeBlockService.setCodeDraft(props.id, codeValue);
4230
- tMagicMessage.success(`代码草稿成功保存到本地 ${datetimeFormatter( new Date())}`);
4231
- };
4232
- const saveAndClose = () => {
4233
- if (!codeEditor.value || !props.editable)
4234
- return;
4235
- editorContent.value = codeEditor.value.getEditor()?.getValue();
4236
- emit("saveAndClose", editorContent.value);
4237
- };
4238
- const close = async () => {
4239
- const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
4240
- if (codeDraft) {
4241
- try {
4242
- await tMagicMessageBox.confirm("您有代码修改未保存,是否保存后再关闭?", "提示", {
4243
- confirmButtonText: "保存并关闭",
4244
- cancelButtonText: "直接关闭",
4245
- type: "warning",
4246
- distinguishCancelAndClose: true
4247
- });
4248
- saveAndClose();
4249
- } catch (action) {
4250
- if (action === "cancel") {
4251
- services?.codeBlockService.removeCodeDraft(props.id);
4252
- emit("close");
4253
- }
4254
- }
4255
- } else {
4256
- emit("close");
4257
- }
4258
- };
4259
- const toggleFullScreen = () => {
4260
- isFullScreen.value = !isFullScreen.value;
4261
- if (codeEditor.value) {
4262
- codeEditor.value.focus();
4263
- }
4264
- };
4265
- __expose({
4266
- saveAndClose,
4267
- close
4268
- });
4269
- return (_ctx, _cache) => {
4270
- return openBlock(), createElementBlock("div", {
4271
- class: normalizeClass(["m-editor-wrapper", isFullScreen.value ? "fullScreen" : "normal"])
4272
- }, [
4273
- createVNode(_sfc_main$w, {
4274
- ref_key: "codeEditor",
4275
- ref: codeEditor,
4276
- class: "m-editor-container",
4277
- "init-values": `${codeContent.value}`,
4278
- onSave: saveCodeDraft,
4279
- language: _ctx.language,
4280
- options: codeOptions.value
4281
- }, null, 8, ["init-values", "language", "options"]),
4282
- _ctx.editable ? (openBlock(), createElementBlock("div", _hoisted_1$d, [
4283
- createVNode(unref(TMagicButton), {
4284
- type: "primary",
4285
- class: "button",
4286
- onClick: toggleFullScreen
4287
- }, {
4288
- default: withCtx(() => [
4289
- createTextVNode(toDisplayString(isFullScreen.value ? "退出全屏" : "全屏"), 1)
4290
- ]),
4291
- _: 1
4292
- }),
4293
- createVNode(unref(TMagicButton), {
4294
- type: "primary",
4295
- class: "button",
4296
- onClick: saveAndClose
4297
- }, {
4298
- default: withCtx(() => [
4299
- createTextVNode("确认")
4300
- ]),
4301
- _: 1
4302
- }),
4303
- createVNode(unref(TMagicButton), {
4304
- class: "button",
4305
- onClick: close
4306
- }, {
4307
- default: withCtx(() => [
4308
- createTextVNode("关闭")
4309
- ]),
4310
- _: 1
4311
- })
4312
- ])) : (openBlock(), createElementBlock("div", _hoisted_2$6, [
4313
- createVNode(unref(TMagicButton), {
4314
- type: "primary",
4315
- class: "button",
4316
- onClick: toggleFullScreen
4317
- }, {
4318
- default: withCtx(() => [
4319
- createTextVNode(toDisplayString(isFullScreen.value ? "退出全屏" : "全屏"), 1)
4320
- ]),
4321
- _: 1
4322
- }),
4323
- createVNode(unref(TMagicButton), {
4324
- class: "button",
4325
- onClick: close
4326
- }, {
4327
- default: withCtx(() => [
4328
- createTextVNode("关闭")
4329
- ]),
4330
- _: 1
4331
- })
4332
- ]))
4333
- ], 2);
4334
- };
4335
- }
4336
- });
4337
-
4338
- const _hoisted_1$c = { class: "code-name-wrapper" };
4339
- const _hoisted_2$5 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "代码块名称", -1);
4340
- const _hoisted_3$3 = { class: "code-name-wrapper" };
4341
- const _hoisted_4$3 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "参数", -1);
4342
- const _sfc_main$k = /* @__PURE__ */ defineComponent({
4343
- ...{
4344
- name: "MEditorFunctionEditor"
4345
- },
4346
- __name: "FunctionEditor",
4347
- props: {
4348
- id: {},
4349
- name: {},
4350
- content: {},
4351
- editable: { type: Boolean, default: true },
4352
- autoSaveDraft: { type: Boolean, default: true },
4353
- codeOptions: {},
4354
- paramsColConfig: {}
4355
- },
4356
- setup(__props, { expose: __expose }) {
4357
- const props = __props;
4358
- provide("mForm", null);
4359
- const defaultParamColConfig = {
4360
- type: "row",
4361
- label: "参数类型",
4362
- items: [
4363
- {
4364
- text: "参数类型",
4365
- labelWidth: "70px",
4366
- type: "select",
4367
- name: "type",
4368
- options: [
4369
- {
4370
- text: "数字",
4371
- label: "数字",
4372
- value: "number"
4373
- },
4374
- {
4375
- text: "字符串",
4376
- label: "字符串",
4377
- value: "text"
4378
- }
4379
- ]
4380
- }
4381
- ]
4382
- };
4383
- const paramsColConfig = props.paramsColConfig || defaultParamColConfig;
4384
- const tableConfig = {
4385
- type: "table",
4386
- border: true,
4387
- enableFullscreen: false,
4388
- name: "params",
4389
- maxHeight: "300px",
4390
- dropSort: false,
4391
- items: [
4392
- {
4393
- type: "text",
4394
- label: "参数名",
4395
- name: "name",
4396
- width: 200
4397
- },
4398
- {
4399
- type: "text",
4400
- label: "参数注释",
4401
- name: "tip",
4402
- width: 200
4403
- },
4404
- paramsColConfig
4405
- ]
4406
- };
4407
- const services = inject("services");
4408
- const codeName = ref("");
4409
- const codeContent = ref("");
4410
- const evalRes = ref(true);
4411
- const tableModel = ref();
4412
- watchEffect(() => {
4413
- codeName.value = props.name;
4414
- codeContent.value = props.content;
4415
- });
4416
- const initTableModel = () => {
4417
- const codeDsl = cloneDeep(services?.codeBlockService.getCodeDsl());
4418
- if (!codeDsl)
4419
- return;
4420
- tableModel.value = {
4421
- params: codeDsl[props.id]?.params || []
4422
- };
4423
- };
4424
- initTableModel();
4425
- const beforeSave = (codeValue) => {
4426
- try {
4427
- getConfig("parseDSL")(codeValue);
4428
- return true;
4429
- } catch (e) {
4430
- tMagicMessage.error(e.stack);
4431
- return false;
4432
- }
4433
- };
4434
- const saveCode = async (codeValue) => {
4435
- if (!props.editable)
4436
- return;
4437
- evalRes.value = beforeSave(codeValue);
4438
- if (evalRes.value) {
4439
- await services?.codeBlockService.setCodeDslById(props.id, {
4440
- name: codeName.value,
4441
- content: codeValue,
4442
- params: tableModel.value?.params || []
4443
- });
4444
- tMagicMessage.success("代码成功保存到本地");
4445
- services?.codeBlockService.removeCodeDraft(props.id);
4446
- }
4447
- };
4448
- const saveAndClose = async (codeValue) => {
4449
- await saveCode(codeValue);
4450
- if (evalRes.value) {
4451
- close();
4452
- }
4453
- };
4454
- const close = () => {
4455
- services?.codeBlockService.setCodeEditorShowStatus(false);
4456
- };
4457
- const codeDraftEditor = ref();
4458
- __expose({
4459
- codeDraftEditor
4460
- });
4461
- return (_ctx, _cache) => {
4462
- const _component_m_form_table = resolveComponent("m-form-table");
4463
- return openBlock(), createBlock(unref(TMagicCard), { shadow: "never" }, {
4464
- header: withCtx(() => [
4465
- createElementVNode("div", _hoisted_1$c, [
4466
- _hoisted_2$5,
4467
- createVNode(unref(TMagicInput), {
4468
- class: "code-name-input",
4469
- modelValue: codeName.value,
4470
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeName.value = $event),
4471
- disabled: !_ctx.editable
4472
- }, null, 8, ["modelValue", "disabled"])
4473
- ]),
4474
- createElementVNode("div", _hoisted_3$3, [
4475
- _hoisted_4$3,
4476
- createVNode(_component_m_form_table, {
4477
- style: { "width": "800px" },
4478
- config: tableConfig,
4479
- model: tableModel.value,
4480
- enableToggleMode: false,
4481
- name: "params",
4482
- prop: "params",
4483
- size: "small"
4484
- }, null, 8, ["model"])
4485
- ])
4486
- ]),
4487
- default: withCtx(() => [
4488
- createVNode(_sfc_main$l, {
4489
- ref_key: "codeDraftEditor",
4490
- ref: codeDraftEditor,
4491
- id: _ctx.id,
4492
- content: codeContent.value,
4493
- editable: _ctx.editable,
4494
- autoSaveDraft: _ctx.autoSaveDraft,
4495
- codeOptions: _ctx.codeOptions,
4496
- language: "javascript",
4497
- onSaveAndClose: saveAndClose,
4498
- onClose: close
4499
- }, null, 8, ["id", "content", "editable", "autoSaveDraft", "codeOptions"])
4500
- ]),
4501
- _: 1
4502
- });
4503
- };
4504
- }
4505
- });
4506
-
4507
- const _hoisted_1$b = {
4508
- key: 0,
4509
- class: "m-editor-code-block-editor-panel"
4510
- };
4511
- const _sfc_main$j = /* @__PURE__ */ defineComponent({
4512
- ...{
4513
- name: "MEditorCodeBlockEditor"
4514
- },
4515
- __name: "CodeBlockEditor",
4516
- props: {
4517
- paramsColConfig: {}
4518
- },
4519
- setup(__props) {
4520
- const services = inject("services");
4521
- const codeOptions = inject("codeOptions", {});
4522
- const size = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get("columnWidth").left || 0));
4523
- const left = ref(200);
4524
- const currentTitle = ref("");
4525
- const codeConfig = ref(null);
4526
- const state = reactive({
4527
- codeList: []
4528
- });
4529
- const id = computed(() => services?.codeBlockService.getId() || "");
4530
- const editable = computed(() => services?.codeBlockService.getEditStatus());
4531
- const selectedIds = computed(() => services?.codeBlockService.getCombineIds() || []);
4532
- watchEffect(async () => {
4533
- codeConfig.value = cloneDeep(await services?.codeBlockService.getCodeContentById(id.value)) || null;
4534
- if (!codeConfig.value)
4535
- return;
4536
- codeConfig.value.content = serializeConfig(codeConfig.value.content);
4537
- });
4538
- watchEffect(async () => {
4539
- const codeDsl = await services?.codeBlockService.getCodeDslByIds(selectedIds.value) || null;
4540
- if (!codeDsl)
4541
- return;
4542
- state.codeList = [];
4543
- forIn(codeDsl, (value, key) => {
4544
- state.codeList.push({
4545
- id: key,
4546
- name: value.name
4547
- });
4548
- });
4549
- currentTitle.value = state.codeList[0]?.name || "";
4550
- });
4551
- const functionEditor = ref();
4552
- const handleClose = async () => {
4553
- await functionEditor.value?.codeDraftEditor?.close();
4554
- };
4555
- return (_ctx, _cache) => {
4556
- return openBlock(), createBlock(unref(TMagicDrawer), {
4557
- class: "code-editor-dialog",
4558
- "model-value": true,
4559
- title: currentTitle.value,
4560
- "close-on-press-escape": true,
4561
- "append-to-body": true,
4562
- "show-close": false,
4563
- "close-on-click-modal": true,
4564
- size: size.value,
4565
- "before-close": handleClose
4566
- }, {
4567
- default: withCtx(() => [
4568
- createVNode(_sfc_main$u, {
4569
- left: left.value,
4570
- "onUpdate:left": _cache[0] || (_cache[0] = ($event) => left.value = $event),
4571
- "min-left": 45,
4572
- class: "code-editor-layout"
4573
- }, {
4574
- center: withCtx(() => [
4575
- !unref(isEmpty)(codeConfig.value) ? (openBlock(), createElementBlock("div", _hoisted_1$b, [
4576
- renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id: id.value }),
4577
- codeConfig.value ? (openBlock(), createBlock(_sfc_main$k, {
4578
- key: 0,
4579
- ref_key: "functionEditor",
4580
- ref: functionEditor,
4581
- id: id.value,
4582
- name: codeConfig.value.name,
4583
- content: codeConfig.value.content,
4584
- paramsColConfig: _ctx.paramsColConfig,
4585
- editable: !!editable.value,
4586
- autoSaveDraft: true,
4587
- codeOptions: unref(codeOptions)
4588
- }, null, 8, ["id", "name", "content", "paramsColConfig", "editable", "codeOptions"])) : createCommentVNode("", true)
4589
- ])) : createCommentVNode("", true)
4590
- ]),
4591
- _: 3
4592
- }, 8, ["left"])
4593
- ]),
4594
- _: 3
4595
- }, 8, ["title", "size"]);
4779
+ return openBlock(), createElementBlock("svg", _hoisted_1$d, _hoisted_4$1);
4596
4780
  };
4597
4781
  }
4598
4782
  });
4599
4783
 
4600
- const _hoisted_1$a = { class: "search-wrapper" };
4601
- const _hoisted_2$4 = ["id"];
4602
- const _hoisted_3$2 = { class: "list-item" };
4603
- const _hoisted_4$2 = {
4784
+ const _hoisted_1$c = ["id"];
4785
+ const _hoisted_2$4 = { class: "list-item" };
4786
+ const _hoisted_3$2 = {
4604
4787
  key: 2,
4605
4788
  class: "right-tool"
4606
4789
  };
4607
- const _sfc_main$i = /* @__PURE__ */ defineComponent({
4790
+ const _sfc_main$k = /* @__PURE__ */ defineComponent({
4608
4791
  ...{
4609
4792
  name: "MEditorCodeBlockList"
4610
4793
  },
4611
4794
  __name: "CodeBlockList",
4612
4795
  props: {
4613
- customError: { type: Function },
4614
- paramsColConfig: {}
4796
+ customError: { type: Function }
4615
4797
  },
4616
- setup(__props) {
4798
+ emits: ["edit", "remove"],
4799
+ setup(__props, { expose: __expose, emit }) {
4617
4800
  const props = __props;
4618
- const treeProps = {
4619
- children: "children",
4620
- label: "name",
4621
- value: "id"
4622
- };
4623
4801
  const { codeBlockService, depService, editorService } = inject("services") || {};
4624
4802
  const codeList = computed(
4625
4803
  () => Object.values(depService?.targets["code-block"] || {}).map((target) => {
@@ -4636,54 +4814,16 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
4636
4814
  codeBlockContent: codeBlockService?.getCodeContentById(target.id),
4637
4815
  children: compNodes
4638
4816
  };
4639
- })
4640
- );
4641
- const expandedKeys = computed(() => codeList.value.map((item) => item.id));
4642
- const editable = computed(() => codeBlockService?.getEditStatus());
4643
- const isShowCodeBlockEditor = computed(() => codeBlockService?.getCodeEditorShowStatus() || false);
4644
- const createCodeBlock = async () => {
4645
- if (!codeBlockService) {
4646
- tMagicMessage.error("新增代码块失败");
4647
- return;
4648
- }
4649
- const codeConfig = {
4650
- name: "代码块",
4651
- content: `({app, params}) => {
4652
- // place your code here
4653
- }`,
4654
- params: []
4655
- };
4656
- const id = await codeBlockService.getUniqueId();
4657
- await codeBlockService.setCodeDslById(id, codeConfig);
4658
- codeBlockService.setCodeEditorContent(true, id);
4659
- };
4660
- const editCode = async (key) => {
4661
- codeBlockService?.setCodeEditorContent(true, key);
4662
- };
4663
- const deleteCode = (key) => {
4664
- const currentCode = codeList.value.find((codeItem) => codeItem.id === key);
4665
- const existBinds = Boolean(currentCode?.children.length);
4666
- const undeleteableList = codeBlockService?.getUndeletableList() || [];
4667
- if (!existBinds && !undeleteableList.includes(key)) {
4668
- codeBlockService?.deleteCodeDslByIds([key]);
4669
- } else {
4670
- if (typeof props.customError === "function") {
4671
- props.customError(key, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
4672
- } else {
4673
- tMagicMessage.error("代码块删除失败");
4674
- }
4675
- }
4676
- };
4677
- const tree = ref();
4817
+ })
4818
+ );
4819
+ const expandedKeys = computed(() => codeList.value.map((item) => item.id));
4820
+ const editable = computed(() => codeBlockService?.getEditStatus());
4678
4821
  const filterNode = (value, data) => {
4679
4822
  if (!value) {
4680
4823
  return true;
4681
4824
  }
4682
4825
  return `${data.name}${data.id}`.toLocaleLowerCase().indexOf(value.toLocaleLowerCase()) !== -1;
4683
4826
  };
4684
- const filterTextChangeHandler = (val) => {
4685
- tree.value?.filter(val);
4686
- };
4687
4827
  const selectComp = (compId) => {
4688
4828
  const stage = editorService?.get("stage");
4689
4829
  editorService?.select(compId);
@@ -4696,106 +4836,166 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
4696
4836
  selectComp(node.parent.data.id);
4697
4837
  }
4698
4838
  };
4839
+ const editCode = (id) => {
4840
+ emit("edit", id);
4841
+ };
4842
+ const deleteCode = async (id) => {
4843
+ const currentCode = codeList.value.find((codeItem) => codeItem.id === id);
4844
+ const existBinds = Boolean(currentCode?.children.length);
4845
+ const undeleteableList = codeBlockService?.getUndeletableList() || [];
4846
+ if (!existBinds && !undeleteableList.includes(id)) {
4847
+ await tMagicMessageBox.confirm("确定删除该代码块吗?", "提示", {
4848
+ confirmButtonText: "确定",
4849
+ cancelButtonText: "取消",
4850
+ type: "warning"
4851
+ });
4852
+ emit("remove", id);
4853
+ } else {
4854
+ if (typeof props.customError === "function") {
4855
+ props.customError(id, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
4856
+ } else {
4857
+ tMagicMessage.error("代码块删除失败");
4858
+ }
4859
+ }
4860
+ };
4861
+ const tree = ref();
4862
+ __expose({
4863
+ filter(val) {
4864
+ tree.value?.filter(val);
4865
+ }
4866
+ });
4867
+ return (_ctx, _cache) => {
4868
+ return openBlock(), createBlock(unref(TMagicTree), {
4869
+ ref_key: "tree",
4870
+ ref: tree,
4871
+ class: "magic-editor-layer-tree",
4872
+ "node-key": "id",
4873
+ "empty-text": "暂无代码块",
4874
+ "default-expanded-keys": expandedKeys.value,
4875
+ "expand-on-click-node": false,
4876
+ data: codeList.value,
4877
+ props: {
4878
+ children: "children",
4879
+ label: "name",
4880
+ value: "id"
4881
+ },
4882
+ "highlight-current": true,
4883
+ "filter-node-method": filterNode,
4884
+ onNodeClick: clickHandler
4885
+ }, {
4886
+ default: withCtx(({ data }) => [
4887
+ createElementVNode("div", {
4888
+ id: data.id,
4889
+ class: "list-container"
4890
+ }, [
4891
+ createElementVNode("div", _hoisted_2$4, [
4892
+ data.type === "code" ? (openBlock(), createBlock(_sfc_main$l, {
4893
+ key: 0,
4894
+ class: "codeIcon"
4895
+ })) : createCommentVNode("", true),
4896
+ data.type === "node" ? (openBlock(), createBlock(_sfc_main$m, {
4897
+ key: 1,
4898
+ class: "compIcon"
4899
+ })) : createCommentVNode("", true),
4900
+ createElementVNode("span", {
4901
+ class: normalizeClass(["name", { code: data.type === "code", hook: data.type === "key" }])
4902
+ }, toDisplayString(data.name) + " (" + toDisplayString(data.id) + ")", 3),
4903
+ data.type === "code" ? (openBlock(), createElementBlock("div", _hoisted_3$2, [
4904
+ createVNode(unref(TMagicTooltip), {
4905
+ effect: "dark",
4906
+ content: editable.value ? "编辑" : "查看",
4907
+ placement: "bottom"
4908
+ }, {
4909
+ default: withCtx(() => [
4910
+ createVNode(_sfc_main$E, {
4911
+ icon: editable.value ? unref(Edit) : unref(View),
4912
+ class: "edit-icon",
4913
+ onClick: withModifiers(($event) => editCode(data.id), ["stop"])
4914
+ }, null, 8, ["icon", "onClick"])
4915
+ ]),
4916
+ _: 2
4917
+ }, 1032, ["content"]),
4918
+ editable.value ? (openBlock(), createBlock(unref(TMagicTooltip), {
4919
+ key: 0,
4920
+ effect: "dark",
4921
+ content: "删除",
4922
+ placement: "bottom"
4923
+ }, {
4924
+ default: withCtx(() => [
4925
+ createVNode(_sfc_main$E, {
4926
+ icon: unref(Close),
4927
+ class: "edit-icon",
4928
+ onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
4929
+ }, null, 8, ["icon", "onClick"])
4930
+ ]),
4931
+ _: 2
4932
+ }, 1024)) : createCommentVNode("", true),
4933
+ renderSlot(_ctx.$slots, "code-block-panel-tool", {
4934
+ id: data.id,
4935
+ data: data.codeBlockContent
4936
+ })
4937
+ ])) : createCommentVNode("", true)
4938
+ ])
4939
+ ], 8, _hoisted_1$c)
4940
+ ]),
4941
+ _: 3
4942
+ }, 8, ["default-expanded-keys", "data"]);
4943
+ };
4944
+ }
4945
+ });
4946
+
4947
+ const _hoisted_1$b = { class: "search-wrapper" };
4948
+ const _sfc_main$j = /* @__PURE__ */ defineComponent({
4949
+ ...{
4950
+ name: "MEditorCodeBlockListPanel"
4951
+ },
4952
+ __name: "CodeBlockListPanel",
4953
+ props: {
4954
+ customError: { type: Function }
4955
+ },
4956
+ setup(__props) {
4957
+ const { codeBlockService } = inject("services") || {};
4958
+ const editable = computed(() => codeBlockService?.getEditStatus());
4959
+ const { codeBlockEditor, codeConfig, editCode, deleteCode, createCodeBlock, submitCodeBlockHandler } = useCodeBlockEdit(codeBlockService);
4960
+ const codeBlockList = ref();
4961
+ const filterTextChangeHandler = (val) => {
4962
+ codeBlockList.value?.filter(val);
4963
+ };
4699
4964
  return (_ctx, _cache) => {
4700
4965
  return openBlock(), createBlock(unref(TMagicScrollbar), { class: "m-editor-code-block-list m-editor-dep-list-panel" }, {
4701
4966
  default: withCtx(() => [
4702
4967
  renderSlot(_ctx.$slots, "code-block-panel-header", {}, () => [
4703
- createElementVNode("div", _hoisted_1$a, [
4704
- createVNode(_sfc_main$o, { onSearch: filterTextChangeHandler }),
4968
+ createElementVNode("div", _hoisted_1$b, [
4969
+ createVNode(_sfc_main$n, { onSearch: filterTextChangeHandler }),
4705
4970
  editable.value ? (openBlock(), createBlock(unref(TMagicButton), {
4706
4971
  key: 0,
4707
4972
  class: "create-code-button",
4708
4973
  type: "primary",
4709
4974
  size: "small",
4710
- onClick: createCodeBlock
4975
+ onClick: unref(createCodeBlock)
4711
4976
  }, {
4712
4977
  default: withCtx(() => [
4713
4978
  createTextVNode("新增")
4714
4979
  ]),
4715
4980
  _: 1
4716
- })) : createCommentVNode("", true)
4981
+ }, 8, ["onClick"])) : createCommentVNode("", true)
4717
4982
  ])
4718
4983
  ]),
4719
- createVNode(unref(TMagicTree), {
4720
- ref_key: "tree",
4721
- ref: tree,
4722
- class: "magic-editor-layer-tree",
4723
- "node-key": "id",
4724
- "empty-text": "暂无代码块",
4725
- "default-expanded-keys": expandedKeys.value,
4726
- "expand-on-click-node": false,
4727
- data: codeList.value,
4728
- props: treeProps,
4729
- "highlight-current": true,
4730
- "filter-node-method": filterNode,
4731
- onNodeClick: clickHandler
4732
- }, {
4733
- default: withCtx(({ data }) => [
4734
- createElementVNode("div", {
4735
- id: data.id,
4736
- class: "list-container"
4737
- }, [
4738
- createElementVNode("div", _hoisted_3$2, [
4739
- data.type === "code" ? (openBlock(), createBlock(_sfc_main$m, {
4740
- key: 0,
4741
- class: "codeIcon"
4742
- })) : createCommentVNode("", true),
4743
- data.type === "node" ? (openBlock(), createBlock(_sfc_main$n, {
4744
- key: 1,
4745
- class: "compIcon"
4746
- })) : createCommentVNode("", true),
4747
- createElementVNode("span", {
4748
- class: normalizeClass(["name", { code: data.type === "code", hook: data.type === "key" }])
4749
- }, toDisplayString(data.name) + " (" + toDisplayString(data.id) + ")", 3),
4750
- data.type === "code" ? (openBlock(), createElementBlock("div", _hoisted_4$2, [
4751
- createVNode(unref(TMagicTooltip), {
4752
- effect: "dark",
4753
- content: editable.value ? "编辑" : "查看",
4754
- placement: "bottom"
4755
- }, {
4756
- default: withCtx(() => [
4757
- createVNode(_sfc_main$E, {
4758
- icon: editable.value ? unref(Edit) : unref(View),
4759
- class: "edit-icon",
4760
- onClick: withModifiers(($event) => editCode(`${data.id}`), ["stop"])
4761
- }, null, 8, ["icon", "onClick"])
4762
- ]),
4763
- _: 2
4764
- }, 1032, ["content"]),
4765
- editable.value ? (openBlock(), createBlock(unref(TMagicTooltip), {
4766
- key: 0,
4767
- effect: "dark",
4768
- content: "删除",
4769
- placement: "bottom"
4770
- }, {
4771
- default: withCtx(() => [
4772
- createVNode(_sfc_main$E, {
4773
- icon: unref(Close),
4774
- class: "edit-icon",
4775
- onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
4776
- }, null, 8, ["icon", "onClick"])
4777
- ]),
4778
- _: 2
4779
- }, 1024)) : createCommentVNode("", true),
4780
- renderSlot(_ctx.$slots, "code-block-panel-tool", {
4781
- id: data.id,
4782
- data: data.codeBlockContent
4783
- })
4784
- ])) : createCommentVNode("", true)
4785
- ])
4786
- ], 8, _hoisted_2$4)
4787
- ]),
4788
- _: 3
4789
- }, 8, ["default-expanded-keys", "data"]),
4790
- isShowCodeBlockEditor.value ? (openBlock(), createBlock(_sfc_main$j, {
4984
+ createVNode(_sfc_main$k, {
4985
+ ref_key: "codeBlockList",
4986
+ ref: codeBlockList,
4987
+ "custom-error": _ctx.customError,
4988
+ onEdit: unref(editCode),
4989
+ onRemove: unref(deleteCode)
4990
+ }, null, 8, ["custom-error", "onEdit", "onRemove"]),
4991
+ unref(codeConfig) ? (openBlock(), createBlock(_sfc_main$G, {
4791
4992
  key: 0,
4792
- paramsColConfig: _ctx.paramsColConfig
4793
- }, {
4794
- "code-block-edit-panel-header": withCtx(({ id }) => [
4795
- renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
4796
- ]),
4797
- _: 3
4798
- }, 8, ["paramsColConfig"])) : createCommentVNode("", true)
4993
+ ref_key: "codeBlockEditor",
4994
+ ref: codeBlockEditor,
4995
+ disabled: !editable.value,
4996
+ content: unref(codeConfig),
4997
+ onSubmit: unref(submitCodeBlockHandler)
4998
+ }, null, 8, ["disabled", "content", "onSubmit"])) : createCommentVNode("", true)
4799
4999
  ]),
4800
5000
  _: 3
4801
5001
  });
@@ -4803,14 +5003,15 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
4803
5003
  }
4804
5004
  });
4805
5005
 
4806
- const _sfc_main$h = /* @__PURE__ */ defineComponent({
5006
+ const _sfc_main$i = /* @__PURE__ */ defineComponent({
4807
5007
  ...{
4808
5008
  name: "MEditorDataSourceConfigPanel"
4809
5009
  },
4810
5010
  __name: "DataSourceConfigPanel",
4811
5011
  props: {
4812
5012
  title: {},
4813
- values: {}
5013
+ values: {},
5014
+ disabled: { type: Boolean }
4814
5015
  },
4815
5016
  emits: ["submit"],
4816
5017
  setup(__props, { expose: __expose, emit }) {
@@ -4819,7 +5020,7 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
4819
5020
  const services = inject("services");
4820
5021
  const size = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get("columnWidth").left || 0));
4821
5022
  const dataSourceConfig = computed(() => services?.dataSourceService.getFormConfig(type.value) || []);
4822
- const form = ref();
5023
+ const fomDrawer = ref();
4823
5024
  const initValues = ref({});
4824
5025
  watchEffect(() => {
4825
5026
  initValues.value = props.values;
@@ -4832,84 +5033,53 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
4832
5033
  type.value = value.type || "base";
4833
5034
  initValues.value = value;
4834
5035
  };
4835
- const submitHandler = async () => {
4836
- try {
4837
- const values = await form.value?.submitForm();
4838
- emit("submit", values);
4839
- } catch (error) {
4840
- tMagicMessage.error(error.message);
4841
- }
5036
+ const submitHandler = (values) => {
5037
+ emit("submit", values);
4842
5038
  };
4843
- const visible = ref(false);
4844
- const hide = () => {
4845
- visible.value = false;
5039
+ const errorHandler = (error) => {
5040
+ tMagicMessage.error(error.message);
4846
5041
  };
4847
5042
  __expose({
4848
5043
  show() {
4849
- visible.value = true;
5044
+ fomDrawer.value?.show();
4850
5045
  },
4851
- hide
5046
+ hide() {
5047
+ fomDrawer.value?.hide();
5048
+ }
4852
5049
  });
4853
5050
  return (_ctx, _cache) => {
4854
- return openBlock(), createBlock(unref(TMagicDrawer), {
4855
- modelValue: visible.value,
4856
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => visible.value = $event),
5051
+ return openBlock(), createBlock(unref(MFormDrawer), {
5052
+ ref_key: "fomDrawer",
5053
+ ref: fomDrawer,
5054
+ "label-width": "80px",
4857
5055
  title: _ctx.title,
4858
- "close-on-press-escape": true,
4859
- "append-to-body": true,
4860
- "show-close": true,
4861
- "close-on-click-modal": true,
4862
- size: size.value
4863
- }, {
4864
- footer: withCtx(() => [
4865
- createElementVNode("div", null, [
4866
- createVNode(unref(TMagicButton), {
4867
- type: "primary",
4868
- onClick: submitHandler
4869
- }, {
4870
- default: withCtx(() => [
4871
- createTextVNode("确定")
4872
- ]),
4873
- _: 1
4874
- }),
4875
- createVNode(unref(TMagicButton), { onClick: hide }, {
4876
- default: withCtx(() => [
4877
- createTextVNode("关闭")
4878
- ]),
4879
- _: 1
4880
- })
4881
- ])
4882
- ]),
4883
- default: withCtx(() => [
4884
- createVNode(unref(MForm), {
4885
- ref_key: "form",
4886
- ref: form,
4887
- config: dataSourceConfig.value,
4888
- "init-values": initValues.value,
4889
- onChange: changeHandler
4890
- }, null, 8, ["config", "init-values"])
4891
- ]),
4892
- _: 1
4893
- }, 8, ["modelValue", "title", "size"]);
5056
+ width: size.value,
5057
+ config: dataSourceConfig.value,
5058
+ values: initValues.value,
5059
+ disabled: _ctx.disabled,
5060
+ onChange: changeHandler,
5061
+ onSubmit: submitHandler,
5062
+ onError: errorHandler
5063
+ }, null, 8, ["title", "width", "config", "values", "disabled"]);
4894
5064
  };
4895
5065
  }
4896
5066
  });
4897
5067
 
4898
- const _hoisted_1$9 = { class: "search-wrapper" };
4899
- const _hoisted_2$3 = ["id"];
4900
- const _hoisted_3$1 = { class: "list-item" };
4901
- const _hoisted_4$1 = {
5068
+ const _hoisted_1$a = ["id"];
5069
+ const _hoisted_2$3 = { class: "list-item" };
5070
+ const _hoisted_3$1 = {
4902
5071
  key: 2,
4903
5072
  class: "right-tool"
4904
5073
  };
4905
- const _sfc_main$g = /* @__PURE__ */ defineComponent({
5074
+ const _sfc_main$h = /* @__PURE__ */ defineComponent({
4906
5075
  ...{
4907
- name: "MEditorDataSourceListPanel"
5076
+ name: "MEditorDataSourceList"
4908
5077
  },
4909
- __name: "DataSourceListPanel",
4910
- setup(__props) {
4911
- const services = inject("services", {});
4912
- const { dataSourceService, depService, editorService } = inject("services") || {};
5078
+ __name: "DataSourceList",
5079
+ emits: ["edit", "remove"],
5080
+ setup(__props, { expose: __expose, emit }) {
5081
+ const { depService, editorService, dataSourceService } = inject("services") || {};
5082
+ const editable = computed(() => dataSourceService?.get("editable") ?? true);
4913
5083
  const list = computed(
4914
5084
  () => Object.values(depService?.targets["data-source"] || {}).map((target) => ({
4915
5085
  id: target.id,
@@ -4923,8 +5093,123 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
4923
5093
  }))
4924
5094
  }))
4925
5095
  );
5096
+ const editHandler = (id) => {
5097
+ emit("edit", id);
5098
+ };
5099
+ const removeHandler = async (id) => {
5100
+ await tMagicMessageBox.confirm("确定删除?", "提示", {
5101
+ confirmButtonText: "确定",
5102
+ cancelButtonText: "取消",
5103
+ type: "warning"
5104
+ });
5105
+ emit("remove", id);
5106
+ };
5107
+ const selectComp = (compId) => {
5108
+ const stage = editorService?.get("stage");
5109
+ editorService?.select(compId);
5110
+ stage?.select(compId);
5111
+ };
5112
+ const clickHandler = (data, node) => {
5113
+ if (data.type === "node") {
5114
+ selectComp(data.id);
5115
+ } else if (data.type === "key") {
5116
+ selectComp(node.parent.data.id);
5117
+ }
5118
+ };
5119
+ const tree = ref();
5120
+ __expose({
5121
+ filter(val) {
5122
+ debugger;
5123
+ tree.value?.filter(val);
5124
+ }
5125
+ });
5126
+ return (_ctx, _cache) => {
5127
+ return openBlock(), createBlock(unref(TMagicTree), {
5128
+ ref_key: "tree",
5129
+ ref: tree,
5130
+ class: "magic-editor-layer-tree",
5131
+ "node-key": "id",
5132
+ "empty-text": "暂无代码块",
5133
+ "default-expand-all": "",
5134
+ "expand-on-click-node": false,
5135
+ data: list.value,
5136
+ "highlight-current": true,
5137
+ onNodeClick: clickHandler
5138
+ }, {
5139
+ default: withCtx(({ data }) => [
5140
+ createElementVNode("div", {
5141
+ id: data.id,
5142
+ class: "list-container"
5143
+ }, [
5144
+ createElementVNode("div", _hoisted_2$3, [
5145
+ data.type === "code" ? (openBlock(), createBlock(_sfc_main$E, {
5146
+ key: 0,
5147
+ class: "codeIcon",
5148
+ icon: unref(Coin)
5149
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
5150
+ data.type === "node" ? (openBlock(), createBlock(_sfc_main$E, {
5151
+ key: 1,
5152
+ class: "compIcon",
5153
+ icon: unref(Aim)
5154
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
5155
+ createElementVNode("span", {
5156
+ class: normalizeClass(["name", { code: data.type === "code", hook: data.type === "key" }])
5157
+ }, toDisplayString(data.name) + "(" + toDisplayString(data.id) + ")", 3),
5158
+ data.type === "code" ? (openBlock(), createElementBlock("div", _hoisted_3$1, [
5159
+ createVNode(unref(TMagicTooltip), {
5160
+ effect: "dark",
5161
+ content: editable.value ? "编辑" : "查看",
5162
+ placement: "bottom"
5163
+ }, {
5164
+ default: withCtx(() => [
5165
+ createVNode(_sfc_main$E, {
5166
+ icon: editable.value ? unref(Edit) : unref(View),
5167
+ class: "edit-icon",
5168
+ onClick: withModifiers(($event) => editHandler(`${data.id}`), ["stop"])
5169
+ }, null, 8, ["icon", "onClick"])
5170
+ ]),
5171
+ _: 2
5172
+ }, 1032, ["content"]),
5173
+ editable.value ? (openBlock(), createBlock(unref(TMagicTooltip), {
5174
+ key: 0,
5175
+ effect: "dark",
5176
+ content: "删除",
5177
+ placement: "bottom"
5178
+ }, {
5179
+ default: withCtx(() => [
5180
+ createVNode(_sfc_main$E, {
5181
+ icon: unref(Close),
5182
+ class: "edit-icon",
5183
+ onClick: withModifiers(($event) => removeHandler(`${data.id}`), ["stop"])
5184
+ }, null, 8, ["icon", "onClick"])
5185
+ ]),
5186
+ _: 2
5187
+ }, 1024)) : createCommentVNode("", true),
5188
+ renderSlot(_ctx.$slots, "data-source-panel-tool", {
5189
+ id: data.id,
5190
+ data: data.codeBlockContent
5191
+ })
5192
+ ])) : createCommentVNode("", true)
5193
+ ])
5194
+ ], 8, _hoisted_1$a)
5195
+ ]),
5196
+ _: 3
5197
+ }, 8, ["data"]);
5198
+ };
5199
+ }
5200
+ });
5201
+
5202
+ const _hoisted_1$9 = { class: "search-wrapper" };
5203
+ const _sfc_main$g = /* @__PURE__ */ defineComponent({
5204
+ ...{
5205
+ name: "MEditorDataSourceListPanel"
5206
+ },
5207
+ __name: "DataSourceListPanel",
5208
+ setup(__props) {
5209
+ const { dataSourceService } = inject("services") || {};
4926
5210
  const editDialog = ref();
4927
5211
  const dataSourceValues = ref({});
5212
+ const editable = computed(() => dataSourceService?.get("editable") ?? true);
4928
5213
  const addHandler = () => {
4929
5214
  if (!editDialog.value)
4930
5215
  return;
@@ -4932,24 +5217,17 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
4932
5217
  editDialog.value.show();
4933
5218
  };
4934
5219
  const editHandler = (id) => {
4935
- if (!editDialog.value || !services)
5220
+ if (!editDialog.value)
4936
5221
  return;
4937
5222
  dataSourceValues.value = {
4938
5223
  ...dataSourceService?.getDataSourceById(id)
4939
5224
  };
4940
5225
  editDialog.value.show();
4941
5226
  };
4942
- const removeHandler = async (id) => {
4943
- await tMagicMessageBox.confirm("确定删除?", "提示", {
4944
- confirmButtonText: "确定",
4945
- cancelButtonText: "取消",
4946
- type: "warning"
4947
- });
5227
+ const removeHandler = (id) => {
4948
5228
  dataSourceService?.remove(id);
4949
5229
  };
4950
5230
  const submitDataSourceHandler = (value) => {
4951
- if (!services)
4952
- return;
4953
5231
  if (value.id) {
4954
5232
  dataSourceService?.update(value);
4955
5233
  } else {
@@ -4957,28 +5235,17 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
4957
5235
  }
4958
5236
  editDialog.value?.hide();
4959
5237
  };
4960
- const tree = ref();
5238
+ const dataSourceList = ref();
4961
5239
  const filterTextChangeHandler = (val) => {
4962
- tree.value?.filter(val);
4963
- };
4964
- const selectComp = (compId) => {
4965
- const stage = editorService?.get("stage");
4966
- editorService?.select(compId);
4967
- stage?.select(compId);
4968
- };
4969
- const clickHandler = (data, node) => {
4970
- if (data.type === "node") {
4971
- selectComp(data.id);
4972
- } else if (data.type === "key") {
4973
- selectComp(node.parent.data.id);
4974
- }
5240
+ dataSourceList.value?.filter(val);
4975
5241
  };
4976
5242
  return (_ctx, _cache) => {
4977
5243
  return openBlock(), createBlock(unref(TMagicScrollbar), { class: "data-source-list-panel m-editor-dep-list-panel" }, {
4978
5244
  default: withCtx(() => [
4979
5245
  createElementVNode("div", _hoisted_1$9, [
4980
- createVNode(_sfc_main$o, { onSearch: filterTextChangeHandler }),
4981
- createVNode(unref(TMagicButton), {
5246
+ createVNode(_sfc_main$n, { onSearch: filterTextChangeHandler }),
5247
+ editable.value ? (openBlock(), createBlock(unref(TMagicButton), {
5248
+ key: 0,
4982
5249
  type: "primary",
4983
5250
  size: "small",
4984
5251
  onClick: addHandler
@@ -4987,87 +5254,22 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
4987
5254
  createTextVNode("新增")
4988
5255
  ]),
4989
5256
  _: 1
4990
- })
5257
+ })) : createCommentVNode("", true)
4991
5258
  ]),
4992
- createVNode(unref(TMagicTree), {
4993
- ref_key: "tree",
4994
- ref: tree,
4995
- class: "magic-editor-layer-tree",
4996
- "node-key": "id",
4997
- "empty-text": "暂无代码块",
4998
- "default-expand-all": "",
4999
- "expand-on-click-node": false,
5000
- data: list.value,
5001
- "highlight-current": true,
5002
- onNodeClick: clickHandler
5003
- }, {
5004
- default: withCtx(({ data }) => [
5005
- createElementVNode("div", {
5006
- id: data.id,
5007
- class: "list-container"
5008
- }, [
5009
- createElementVNode("div", _hoisted_3$1, [
5010
- data.type === "code" ? (openBlock(), createBlock(_sfc_main$E, {
5011
- key: 0,
5012
- class: "codeIcon",
5013
- icon: unref(Coin)
5014
- }, null, 8, ["icon"])) : createCommentVNode("", true),
5015
- data.type === "node" ? (openBlock(), createBlock(_sfc_main$E, {
5016
- key: 1,
5017
- class: "compIcon",
5018
- icon: unref(Aim)
5019
- }, null, 8, ["icon"])) : createCommentVNode("", true),
5020
- createElementVNode("span", {
5021
- class: normalizeClass(["name", { code: data.type === "code", hook: data.type === "key" }])
5022
- }, toDisplayString(data.name) + "(" + toDisplayString(data.id) + ")", 3),
5023
- data.type === "code" ? (openBlock(), createElementBlock("div", _hoisted_4$1, [
5024
- createVNode(unref(TMagicTooltip), {
5025
- effect: "dark",
5026
- content: "编辑",
5027
- placement: "bottom"
5028
- }, {
5029
- default: withCtx(() => [
5030
- createVNode(_sfc_main$E, {
5031
- class: "edit-icon",
5032
- icon: unref(Edit),
5033
- onClick: withModifiers(($event) => editHandler(`${data.id}`), ["stop"])
5034
- }, null, 8, ["icon", "onClick"])
5035
- ]),
5036
- _: 2
5037
- }, 1024),
5038
- createVNode(unref(TMagicTooltip), {
5039
- effect: "dark",
5040
- content: "删除",
5041
- placement: "bottom"
5042
- }, {
5043
- default: withCtx(() => [
5044
- createVNode(_sfc_main$E, {
5045
- icon: unref(Close),
5046
- class: "edit-icon",
5047
- onClick: withModifiers(($event) => removeHandler(`${data.id}`), ["stop"])
5048
- }, null, 8, ["icon", "onClick"])
5049
- ]),
5050
- _: 2
5051
- }, 1024),
5052
- renderSlot(_ctx.$slots, "data-source-panel-tool", {
5053
- id: data.id,
5054
- data: data.codeBlockContent
5055
- })
5056
- ])) : createCommentVNode("", true)
5057
- ])
5058
- ], 8, _hoisted_2$3)
5059
- ]),
5060
- _: 3
5061
- }, 8, ["data"]),
5062
5259
  createVNode(_sfc_main$h, {
5260
+ onEdit: editHandler,
5261
+ onRemove: removeHandler
5262
+ }),
5263
+ createVNode(_sfc_main$i, {
5063
5264
  ref_key: "editDialog",
5064
5265
  ref: editDialog,
5266
+ disabled: !editable.value,
5065
5267
  values: dataSourceValues.value,
5066
5268
  title: typeof dataSourceValues.value.id !== "undefined" ? `编辑${dataSourceValues.value.title}` : "新增",
5067
5269
  onSubmit: submitDataSourceHandler
5068
- }, null, 8, ["values", "title"])
5270
+ }, null, 8, ["disabled", "values", "title"])
5069
5271
  ]),
5070
- _: 3
5272
+ _: 1
5071
5273
  });
5072
5274
  };
5073
5275
  }
@@ -5153,7 +5355,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
5153
5355
  "model-value": collapseValue.value
5154
5356
  }, {
5155
5357
  default: withCtx(() => [
5156
- createVNode(_sfc_main$o, { onSearch: filterTextChangeHandler }),
5358
+ createVNode(_sfc_main$n, { onSearch: filterTextChangeHandler }),
5157
5359
  (openBlock(true), createElementBlock(Fragment, null, renderList(list.value, (group, index) => {
5158
5360
  return openBlock(), createElementBlock(Fragment, null, [
5159
5361
  group.items && group.items.length ? (openBlock(), createBlock(unref(TMagicCollapseItem), {
@@ -5310,7 +5512,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
5310
5512
  }, [
5311
5513
  createElementVNode("div", null, [
5312
5514
  (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.menuData, (item, index) => {
5313
- return openBlock(), createBlock(_sfc_main$r, {
5515
+ return openBlock(), createBlock(_sfc_main$q, {
5314
5516
  "event-type": "mouseup",
5315
5517
  ref_for: true,
5316
5518
  ref_key: "buttons",
@@ -5795,7 +5997,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
5795
5997
  return openBlock(), createBlock(unref(TMagicScrollbar), { class: "magic-editor-layer-panel" }, {
5796
5998
  default: withCtx(() => [
5797
5999
  renderSlot(_ctx.$slots, "layer-panel-header"),
5798
- createVNode(_sfc_main$o, { onSearch: filterTextChangeHandler }),
6000
+ createVNode(_sfc_main$n, { onSearch: filterTextChangeHandler }),
5799
6001
  values.value.length ? (openBlock(), createBlock(unref(TMagicTree), {
5800
6002
  key: 0,
5801
6003
  class: "magic-editor-layer-tree",
@@ -5899,7 +6101,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
5899
6101
  type: "component",
5900
6102
  icon: EditPen,
5901
6103
  text: "代码编辑",
5902
- component: _sfc_main$i,
6104
+ component: _sfc_main$j,
5903
6105
  slots: {}
5904
6106
  },
5905
6107
  "data-source": {
@@ -5993,16 +6195,6 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
5993
6195
  ]),
5994
6196
  key: "4"
5995
6197
  } : void 0,
5996
- config.$key === "code-block" || config.slots?.codeBlockEditPanelHeader ? {
5997
- name: "code-block-edit-panel-header",
5998
- fn: withCtx(({ id }) => [
5999
- config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
6000
- key: 0,
6001
- id
6002
- }) : config.slots?.codeBlockEditPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockEditPanelHeader), { key: 1 })) : createCommentVNode("", true)
6003
- ]),
6004
- key: "5"
6005
- } : void 0,
6006
6198
  config.$key === "layer" || config.slots?.layerNodeContent ? {
6007
6199
  name: "layer-node-content",
6008
6200
  fn: withCtx(({ data: nodeData, node }) => [
@@ -6016,7 +6208,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
6016
6208
  node
6017
6209
  }, null, 8, ["data", "node"])) : createCommentVNode("", true)
6018
6210
  ]),
6019
- key: "6"
6211
+ key: "5"
6020
6212
  } : void 0
6021
6213
  ]), 1040)) : createCommentVNode("", true)
6022
6214
  ]),
@@ -6262,7 +6454,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
6262
6454
  default: withCtx(() => [
6263
6455
  createElementVNode("div", null, [
6264
6456
  renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
6265
- createVNode(_sfc_main$r, {
6457
+ createVNode(_sfc_main$q, {
6266
6458
  data: {
6267
6459
  type: "button",
6268
6460
  text: "复制",
@@ -6270,7 +6462,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
6270
6462
  handler: () => copy(item)
6271
6463
  }
6272
6464
  }, null, 8, ["data"]),
6273
- createVNode(_sfc_main$r, {
6465
+ createVNode(_sfc_main$q, {
6274
6466
  data: {
6275
6467
  type: "button",
6276
6468
  text: "删除",
@@ -7005,22 +7197,14 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
7005
7197
 
7006
7198
  class CodeBlock extends BaseService {
7007
7199
  state = reactive({
7008
- isShowCodeEditor: false,
7009
7200
  codeDsl: null,
7010
- id: "",
7011
7201
  editable: true,
7012
7202
  combineIds: [],
7013
- undeletableList: []
7203
+ undeletableList: [],
7204
+ paramsColConfig: void 0
7014
7205
  });
7015
7206
  constructor() {
7016
- super([
7017
- "setCodeDslById",
7018
- "setCodeEditorShowStatus",
7019
- "setEditStatus",
7020
- "setCombineIds",
7021
- "setUndeleteableList",
7022
- "deleteCodeDslByIds"
7023
- ]);
7207
+ super(["setCodeDslById", "setEditStatus", "setCombineIds", "setUndeleteableList", "deleteCodeDslByIds"]);
7024
7208
  }
7025
7209
  /**
7026
7210
  * 设置活动的代码块dsl数据源
@@ -7067,7 +7251,10 @@ class CodeBlock extends BaseService {
7067
7251
  const codeConfigProcessed = codeConfig;
7068
7252
  if (codeConfig.content) {
7069
7253
  const parseDSL = getConfig("parseDSL");
7070
- codeConfigProcessed.content = parseDSL(codeConfig.content);
7254
+ if (typeof codeConfig.content === "string") {
7255
+ codeConfig.content = parseDSL(codeConfig.content);
7256
+ }
7257
+ codeConfigProcessed.content = codeConfig.content;
7071
7258
  }
7072
7259
  const existContent = codeDsl[id] || {};
7073
7260
  codeDsl[id] = {
@@ -7085,40 +7272,6 @@ class CodeBlock extends BaseService {
7085
7272
  const codeDsl = this.getCodeDsl();
7086
7273
  return pick(codeDsl, ids);
7087
7274
  }
7088
- /**
7089
- * 设置代码编辑面板展示状态
7090
- * @param {boolean} status 是否展示代码编辑面板
7091
- * @returns {void}
7092
- */
7093
- async setCodeEditorShowStatus(status) {
7094
- this.state.isShowCodeEditor = status;
7095
- }
7096
- /**
7097
- * 获取代码编辑面板展示状态
7098
- * @returns {boolean} 是否展示代码编辑面板
7099
- */
7100
- getCodeEditorShowStatus() {
7101
- return this.state.isShowCodeEditor;
7102
- }
7103
- /**
7104
- * 设置代码编辑面板展示状态及展示内容
7105
- * @param {boolean} status 是否展示代码编辑面板
7106
- * @param {Id} id 代码块id
7107
- * @returns {void}
7108
- */
7109
- setCodeEditorContent(status, id) {
7110
- if (!id)
7111
- return;
7112
- this.setId(id);
7113
- this.state.isShowCodeEditor = status;
7114
- }
7115
- /**
7116
- * 获取当前选中的代码块内容
7117
- * @returns {CodeBlockContent | null}
7118
- */
7119
- getCurrentDsl() {
7120
- return this.getCodeContentById(this.state.id);
7121
- }
7122
7275
  /**
7123
7276
  * 获取编辑状态
7124
7277
  * @returns {boolean} 是否可编辑
@@ -7134,23 +7287,6 @@ class CodeBlock extends BaseService {
7134
7287
  async setEditStatus(status) {
7135
7288
  this.state.editable = status;
7136
7289
  }
7137
- /**
7138
- * 设置当前选中的代码块ID
7139
- * @param {Id} id 代码块id
7140
- * @returns {void}
7141
- */
7142
- setId(id) {
7143
- if (!id)
7144
- return;
7145
- this.state.id = id;
7146
- }
7147
- /**
7148
- * 获取当前选中的代码块ID
7149
- * @returns {Id} id 代码块id
7150
- */
7151
- getId() {
7152
- return this.state.id;
7153
- }
7154
7290
  /**
7155
7291
  * 设置当前选中组件已关联绑定的代码块id数组
7156
7292
  * @param {string[]} ids 代码块id数组
@@ -7212,6 +7348,12 @@ class CodeBlock extends BaseService {
7212
7348
  this.emit("remove", id);
7213
7349
  });
7214
7350
  }
7351
+ setParamsColConfig(config) {
7352
+ this.state.paramsColConfig = config;
7353
+ }
7354
+ getParamsColConfig() {
7355
+ return this.state.paramsColConfig;
7356
+ }
7215
7357
  /**
7216
7358
  * 生成代码块唯一id
7217
7359
  * @returns {Id} 代码块唯一id
@@ -7225,9 +7367,7 @@ class CodeBlock extends BaseService {
7225
7367
  return await this.getUniqueId();
7226
7368
  }
7227
7369
  resetState() {
7228
- this.state.isShowCodeEditor = false;
7229
7370
  this.state.codeDsl = null;
7230
- this.state.id = "";
7231
7371
  this.state.editable = true;
7232
7372
  this.state.combineIds = [];
7233
7373
  this.state.undeletableList = [];
@@ -7360,6 +7500,17 @@ const fillConfig = (config) => [
7360
7500
  defaultValue: []
7361
7501
  }
7362
7502
  ]
7503
+ },
7504
+ {
7505
+ type: "panel",
7506
+ title: "方法定义",
7507
+ items: [
7508
+ {
7509
+ name: "methods",
7510
+ type: "data-source-methods",
7511
+ defaultValue: []
7512
+ }
7513
+ ]
7363
7514
  }
7364
7515
  ];
7365
7516
  const getFormConfig = (type, configs) => {
@@ -7376,6 +7527,7 @@ const getFormConfig = (type, configs) => {
7376
7527
  class DataSource extends BaseService {
7377
7528
  state = reactive({
7378
7529
  dataSources: [],
7530
+ editable: true,
7379
7531
  configs: {}
7380
7532
  });
7381
7533
  set(name, value) {
@@ -8371,11 +8523,11 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
8371
8523
  const _sfc_main = defineComponent({
8372
8524
  name: "MEditor",
8373
8525
  components: {
8374
- TMagicNavMenu: _sfc_main$q,
8526
+ TMagicNavMenu: _sfc_main$p,
8375
8527
  Sidebar: _sfc_main$a,
8376
8528
  Workspace: _sfc_main$1,
8377
- PropsPanel: _sfc_main$p,
8378
- Framework: _sfc_main$s
8529
+ PropsPanel: _sfc_main$o,
8530
+ Framework: _sfc_main$r
8379
8531
  },
8380
8532
  props: editorProps,
8381
8533
  emits: ["props-panel-mounted", "update:modelValue"],
@@ -8478,9 +8630,6 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
8478
8630
  data
8479
8631
  })
8480
8632
  ]),
8481
- "code-block-edit-panel-header": withCtx(({ id }) => [
8482
- renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
8483
- ]),
8484
8633
  _: 3
8485
8634
  }, 8, ["data", "layer-content-menu"])
8486
8635
  ])
@@ -8543,19 +8692,21 @@ const index = {
8543
8692
  app.config.globalProperties.$TMAGIC_EDITOR = option;
8544
8693
  setConfig(option);
8545
8694
  app.component(Editor.name, Editor);
8546
- app.component("m-fields-ui-select", _sfc_main$x);
8547
- app.component("m-fields-code-link", _sfc_main$G);
8548
- app.component("m-fields-vs-code", _sfc_main$H);
8549
- app.component("magic-code-editor", _sfc_main$w);
8550
- app.component("m-fields-code-select", _sfc_main$F);
8695
+ app.component("m-fields-ui-select", _sfc_main$v);
8696
+ app.component("m-fields-code-link", _sfc_main$I);
8697
+ app.component("m-fields-vs-code", _sfc_main$J);
8698
+ app.component("magic-code-editor", _sfc_main$K);
8699
+ app.component("m-fields-code-select", _sfc_main$H);
8551
8700
  app.component("m-fields-code-select-col", _sfc_main$D);
8552
- app.component("m-fields-event-select", _sfc_main$z);
8701
+ app.component("m-fields-event-select", _sfc_main$x);
8553
8702
  app.component("m-fields-data-source-fields", _sfc_main$C);
8554
- app.component("m-fields-key-value", _sfc_main$y);
8703
+ app.component("m-fields-key-value", _sfc_main$w);
8555
8704
  app.component("m-fields-data-source-input", _sfc_main$B);
8556
- app.component("m-fields-data-source-select", _sfc_main$A);
8705
+ app.component("m-fields-data-source-select", _sfc_main$y);
8706
+ app.component("m-fields-data-source-methods", _sfc_main$A);
8707
+ app.component("m-fields-data-source-method-select", _sfc_main$z);
8557
8708
  }
8558
8709
  };
8559
8710
 
8560
- export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$i as CodeBlockList, CodeDeleteErrorType, _sfc_main$F as CodeSelect, _sfc_main$D as CodeSelectCol, ColumnLayout, _sfc_main$f as ComponentListPanel, _sfc_main$e as ContentMenu, _sfc_main$C as DataSourceFields, _sfc_main$B as DataSourceInput, _sfc_main$A as DataSourceSelect, _sfc_main$z as EventSelect, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$E as Icon, KeyBindingCommand, _sfc_main$y as KeyValue, Keys, LayerOffset, _sfc_main$b as LayerPanel, Layout, _sfc_main$u as LayoutContainer, _sfc_main$p as PropsPanel, _sfc_main$v as Resizer, _sfc_main$u as SplitView, _sfc_main$w as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$r as ToolButton, V_GUIDE_LINE_STORAGE_KEY, beforePaste, change2Fixed, codeBlockService, dataSourceService, debug, index as default, depService, editorService, error, eventsService, fillConfig$1 as fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, uiService, useStage, warn };
8711
+ export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$G as CodeBlockEditor, _sfc_main$k as CodeBlockList, _sfc_main$j as CodeBlockListPanel, CodeDeleteErrorType, _sfc_main$H as CodeSelect, _sfc_main$D as CodeSelectCol, ColumnLayout, _sfc_main$f as ComponentListPanel, _sfc_main$e as ContentMenu, _sfc_main$C as DataSourceFields, _sfc_main$B as DataSourceInput, _sfc_main$z as DataSourceMethodSelect, _sfc_main$A as DataSourceMethods, _sfc_main$y as DataSourceSelect, _sfc_main$x as EventSelect, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$E as Icon, KeyBindingCommand, _sfc_main$w as KeyValue, Keys, LayerOffset, _sfc_main$b as LayerPanel, Layout, _sfc_main$t as LayoutContainer, _sfc_main$o as PropsPanel, _sfc_main$u as Resizer, _sfc_main$t as SplitView, _sfc_main$K as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$q as ToolButton, V_GUIDE_LINE_STORAGE_KEY, beforePaste, change2Fixed, codeBlockService, dataSourceService, debug, index as default, depService, editorService, error, eventsService, fillConfig$1 as fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, uiService, useStage, warn };
8561
8712
  //# sourceMappingURL=tmagic-editor.js.map