@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,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('lodash-es'), require('@tmagic/design'), require('@tmagic/schema'), require('@element-plus/icons-vue'), require('@tmagic/form'), require('@tmagic/table'), require('monaco-editor'), require('gesto'), require('@tmagic/utils'), require('@tmagic/stage'), require('events'), require('@tmagic/core'), require('keycon')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', 'lodash-es', '@tmagic/design', '@tmagic/schema', '@element-plus/icons-vue', '@tmagic/form', '@tmagic/table', 'monaco-editor', 'gesto', '@tmagic/utils', '@tmagic/stage', 'events', '@tmagic/core', 'keycon'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.Vue, global.serialize, global.lodashEs, global.design, global.schema, global.iconsVue, global.form, global.table, global.monaco, global.Gesto, global.utils, global.StageCore, global.events, global.core, global.KeyController));
5
- })(this, (function (exports, vue, serialize, lodashEs, design, schema, iconsVue, form, table, monaco, Gesto, utils, StageCore, events, core, KeyController) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('@element-plus/icons-vue'), require('lodash-es'), require('monaco-editor'), require('serialize-javascript'), require('@tmagic/design'), require('@tmagic/schema'), require('@tmagic/form'), require('@tmagic/table'), require('gesto'), require('@tmagic/utils'), require('@tmagic/stage'), require('events'), require('@tmagic/core'), require('keycon')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue', '@element-plus/icons-vue', 'lodash-es', 'monaco-editor', 'serialize-javascript', '@tmagic/design', '@tmagic/schema', '@tmagic/form', '@tmagic/table', 'gesto', '@tmagic/utils', '@tmagic/stage', 'events', '@tmagic/core', 'keycon'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.Vue, global.iconsVue, global.lodashEs, global.monaco, global.serialize, global.design, global.schema, global.form, global.table, global.Gesto, global.utils, global.StageCore, global.events, global.core, global.KeyController));
5
+ })(this, (function (exports, vue, iconsVue, lodashEs, monaco, serialize, design, schema, form, table, Gesto, utils, StageCore, events, core, KeyController) { 'use strict';
6
6
 
7
7
  function _interopNamespaceDefault(e) {
8
8
  const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
@@ -23,35 +23,215 @@
23
23
 
24
24
  const monaco__namespace = /*#__PURE__*/_interopNamespaceDefault(monaco);
25
25
 
26
- const _sfc_main$H = /* @__PURE__ */ vue.defineComponent({
26
+ const _hoisted_1$r = {
27
+ class: /* @__PURE__ */ vue.normalizeClass(`magic-code-editor`)
28
+ };
29
+ const _sfc_main$K = /* @__PURE__ */ vue.defineComponent({
30
+ ...{
31
+ name: "MEditorCodeEditor"
32
+ },
33
+ __name: "CodeEditor",
34
+ props: {
35
+ initValues: {},
36
+ modifiedValues: {},
37
+ type: {},
38
+ language: { default: "javascript" },
39
+ options: { default: () => ({
40
+ tabSize: 2
41
+ }) },
42
+ height: {},
43
+ autoSave: { type: Boolean, default: true }
44
+ },
45
+ emits: ["initd", "save"],
46
+ setup(__props, { expose: __expose, emit }) {
47
+ const props = __props;
48
+ const toString = (v, language) => {
49
+ let value = "";
50
+ if (typeof v !== "string") {
51
+ if (props.language.toLocaleLowerCase() === "json") {
52
+ value = JSON.stringify(v, null, 2);
53
+ } else {
54
+ value = serialize(v, {
55
+ space: 2,
56
+ unsafe: true
57
+ }).replace(/"(\w+)":\s/g, "$1: ");
58
+ }
59
+ } else {
60
+ value = v;
61
+ }
62
+ if (language === "javascript" && value.startsWith("{") && value.endsWith("}")) {
63
+ value = `(${value})`;
64
+ }
65
+ return value;
66
+ };
67
+ let vsEditor = null;
68
+ let vsDiffEditor = null;
69
+ const values = vue.ref("");
70
+ const loading = vue.ref(false);
71
+ const codeEditor = vue.ref();
72
+ const resizeObserver = new globalThis.ResizeObserver(
73
+ lodashEs.throttle(() => {
74
+ vsEditor?.layout();
75
+ vsDiffEditor?.layout();
76
+ }, 300)
77
+ );
78
+ const setEditorValue = (v, m) => {
79
+ values.value = toString(v, props.language);
80
+ if (props.type === "diff") {
81
+ const originalModel = monaco__namespace.editor.createModel(values.value, "text/javascript");
82
+ const modifiedModel = monaco__namespace.editor.createModel(toString(m, props.language), "text/javascript");
83
+ return vsDiffEditor?.setModel({
84
+ original: originalModel,
85
+ modified: modifiedModel
86
+ });
87
+ }
88
+ return vsEditor?.setValue(values.value);
89
+ };
90
+ const getEditorValue = () => (props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || "";
91
+ const init = async () => {
92
+ if (!codeEditor.value)
93
+ return;
94
+ const options = {
95
+ value: values.value,
96
+ language: props.language,
97
+ theme: "vs-dark",
98
+ ...props.options
99
+ };
100
+ if (props.type === "diff") {
101
+ vsDiffEditor = monaco__namespace.editor.createDiffEditor(codeEditor.value, options);
102
+ } else {
103
+ vsEditor = monaco__namespace.editor.create(codeEditor.value, options);
104
+ }
105
+ setEditorValue(props.initValues, props.modifiedValues);
106
+ loading.value = false;
107
+ emit("initd", vsEditor);
108
+ codeEditor.value.addEventListener("keydown", (e) => {
109
+ if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
110
+ e.preventDefault();
111
+ e.stopPropagation();
112
+ const newValue = getEditorValue();
113
+ values.value = newValue;
114
+ emit("save", newValue);
115
+ }
116
+ });
117
+ if (props.type !== "diff" && props.autoSave) {
118
+ vsEditor?.onDidBlurEditorWidget(() => {
119
+ const newValue = getEditorValue();
120
+ if (values.value !== newValue) {
121
+ values.value = newValue;
122
+ emit("save", newValue);
123
+ }
124
+ });
125
+ }
126
+ resizeObserver.observe(codeEditor.value);
127
+ };
128
+ vue.watch(
129
+ () => props.initValues,
130
+ (v, preV) => {
131
+ if (v !== preV) {
132
+ setEditorValue(props.initValues, props.modifiedValues);
133
+ }
134
+ },
135
+ {
136
+ deep: true,
137
+ immediate: true
138
+ }
139
+ );
140
+ vue.onMounted(async () => {
141
+ loading.value = true;
142
+ init();
143
+ });
144
+ vue.onUnmounted(() => {
145
+ resizeObserver.disconnect();
146
+ });
147
+ const fullScreen = vue.ref(false);
148
+ const fullScreenHandler = () => {
149
+ fullScreen.value = !fullScreen.value;
150
+ setTimeout(() => {
151
+ vsEditor?.focus();
152
+ vsEditor?.layout();
153
+ vsDiffEditor?.focus();
154
+ vsDiffEditor?.layout();
155
+ });
156
+ };
157
+ __expose({
158
+ values,
159
+ getEditor() {
160
+ return vsEditor || vsDiffEditor;
161
+ },
162
+ getVsEditor() {
163
+ return vsEditor;
164
+ },
165
+ getVsDiffEditor() {
166
+ return vsDiffEditor;
167
+ },
168
+ setEditorValue,
169
+ focus() {
170
+ vsEditor?.focus();
171
+ vsDiffEditor?.focus();
172
+ }
173
+ });
174
+ return (_ctx, _cache) => {
175
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$r, [
176
+ (vue.openBlock(), vue.createBlock(vue.Teleport, {
177
+ to: "body",
178
+ disabled: !fullScreen.value
179
+ }, [
180
+ vue.createElementVNode("div", {
181
+ class: vue.normalizeClass(`magic-code-editor-wrapper${fullScreen.value ? " full-screen" : ""}`),
182
+ style: vue.normalizeStyle(!fullScreen.value && _ctx.height ? `height: ${_ctx.height}` : "100%")
183
+ }, [
184
+ vue.createVNode(vue.unref(design.TMagicButton), {
185
+ class: "magic-code-editor-full-screen-icon",
186
+ circle: "",
187
+ size: "small",
188
+ icon: vue.unref(iconsVue.FullScreen),
189
+ onClick: fullScreenHandler
190
+ }, null, 8, ["icon"]),
191
+ vue.createElementVNode("div", {
192
+ ref_key: "codeEditor",
193
+ ref: codeEditor,
194
+ class: "magic-code-editor-content"
195
+ }, null, 512)
196
+ ], 6)
197
+ ], 8, ["disabled"]))
198
+ ]);
199
+ };
200
+ }
201
+ });
202
+
203
+ const _sfc_main$J = /* @__PURE__ */ vue.defineComponent({
27
204
  ...{
28
205
  name: "MEditorCode"
29
206
  },
30
207
  __name: "Code",
31
208
  props: {
209
+ config: {},
32
210
  model: {},
33
211
  name: {},
34
- config: {},
35
- prop: {}
212
+ prop: {},
213
+ lastValues: {},
214
+ disabled: { type: Boolean, default: false },
215
+ size: {}
36
216
  },
37
217
  emits: ["change"],
38
218
  setup(__props, { emit }) {
39
219
  const props = __props;
40
- const language = vue.computed(() => props.config.language || "javascript");
41
- const height = vue.computed(() => props.config.height || `${document.body.clientHeight - 168}px`);
42
220
  const save = (v) => {
43
221
  props.model[props.name] = v;
44
222
  emit("change", v);
45
223
  };
46
224
  return (_ctx, _cache) => {
47
- const _component_magic_code_editor = vue.resolveComponent("magic-code-editor");
48
- return vue.openBlock(), vue.createBlock(_component_magic_code_editor, {
49
- style: vue.normalizeStyle(`height: ${height.value}`),
225
+ return vue.openBlock(), vue.createBlock(_sfc_main$K, {
226
+ height: _ctx.config.height,
50
227
  "init-values": _ctx.model[_ctx.name],
51
- language: language.value,
52
- options: _ctx.config.options,
228
+ language: _ctx.config.language,
229
+ options: {
230
+ ..._ctx.config.options,
231
+ readOnly: _ctx.disabled
232
+ },
53
233
  onSave: save
54
- }, null, 8, ["style", "init-values", "language", "options"]);
234
+ }, null, 8, ["height", "init-values", "language", "options"]);
55
235
  };
56
236
  }
57
237
  });
@@ -62,7 +242,7 @@
62
242
  };
63
243
  const getConfig = (key) => $TMAGIC_EDITOR[key];
64
244
 
65
- const _sfc_main$G = /* @__PURE__ */ vue.defineComponent({
245
+ const _sfc_main$I = /* @__PURE__ */ vue.defineComponent({
66
246
  ...{
67
247
  name: "MEditorCodeLink"
68
248
  },
@@ -136,7 +316,7 @@
136
316
  }
137
317
  });
138
318
 
139
- const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
319
+ const _sfc_main$H = /* @__PURE__ */ vue.defineComponent({
140
320
  ...{
141
321
  name: "MEditorCodeSelect"
142
322
  },
@@ -151,6 +331,7 @@
151
331
  emits: ["change"],
152
332
  setup(__props, { emit }) {
153
333
  const props = __props;
334
+ const services = vue.inject("services");
154
335
  const codeConfig = vue.computed(() => ({
155
336
  type: "group-list",
156
337
  name: "hookData",
@@ -160,7 +341,9 @@
160
341
  items: [
161
342
  {
162
343
  type: "code-select-col",
163
- labelWidth: 0
344
+ name: "codeId",
345
+ labelWidth: 0,
346
+ disabled: () => !services?.codeBlockService.getEditStatus()
164
347
  }
165
348
  ]
166
349
  }));
@@ -201,7 +384,188 @@
201
384
  }
202
385
  });
203
386
 
204
- const _hoisted_1$p = ["src"];
387
+ const _sfc_main$G = /* @__PURE__ */ vue.defineComponent({
388
+ ...{
389
+ name: "MEditorCodeBlockEditor"
390
+ },
391
+ __name: "CodeBlockEditor",
392
+ props: {
393
+ content: {},
394
+ disabled: { type: Boolean }
395
+ },
396
+ emits: ["submit"],
397
+ setup(__props, { expose: __expose, emit }) {
398
+ const services = vue.inject("services");
399
+ const columnWidth = vue.computed(() => services?.uiService.get("columnWidth"));
400
+ const size = vue.computed(() => columnWidth.value ? columnWidth.value.center + columnWidth.value.right : 600);
401
+ const codeEditorHeight = vue.ref("600px");
402
+ const defaultParamColConfig = {
403
+ type: "row",
404
+ label: "参数类型",
405
+ items: [
406
+ {
407
+ text: "参数类型",
408
+ labelWidth: "70px",
409
+ type: "select",
410
+ name: "type",
411
+ options: [
412
+ {
413
+ text: "数字",
414
+ label: "数字",
415
+ value: "number"
416
+ },
417
+ {
418
+ text: "字符串",
419
+ label: "字符串",
420
+ value: "text"
421
+ },
422
+ {
423
+ text: "组件",
424
+ label: "组件",
425
+ value: "ui-select"
426
+ }
427
+ ]
428
+ }
429
+ ]
430
+ };
431
+ const functionConfig = vue.computed(() => [
432
+ {
433
+ text: "名称",
434
+ name: "name"
435
+ },
436
+ {
437
+ text: "注释",
438
+ name: "desc"
439
+ },
440
+ {
441
+ type: "table",
442
+ border: true,
443
+ text: "参数",
444
+ enableFullscreen: false,
445
+ name: "params",
446
+ maxHeight: "300px",
447
+ dropSort: false,
448
+ items: [
449
+ {
450
+ type: "text",
451
+ label: "参数名",
452
+ name: "name"
453
+ },
454
+ {
455
+ type: "text",
456
+ label: "注释",
457
+ name: "extra"
458
+ },
459
+ services?.codeBlockService.getParamsColConfig() || defaultParamColConfig
460
+ ]
461
+ },
462
+ {
463
+ name: "content",
464
+ type: "vs-code",
465
+ options: vue.inject("codeOptions", {}),
466
+ height: codeEditorHeight.value,
467
+ onChange: (formState, code) => {
468
+ try {
469
+ getConfig("parseDSL")(code);
470
+ return code;
471
+ } catch (error) {
472
+ design.tMagicMessage.error(error.message);
473
+ throw error;
474
+ }
475
+ }
476
+ }
477
+ ]);
478
+ const submitForm = async (values) => {
479
+ emit("submit", values);
480
+ };
481
+ const errorHandler = (error) => {
482
+ design.tMagicMessage.error(error.message);
483
+ };
484
+ const fomDrawer = vue.ref();
485
+ const openHandler = () => {
486
+ setTimeout(() => {
487
+ if (fomDrawer.value) {
488
+ const height = fomDrawer.value?.bodyHeight - 468;
489
+ codeEditorHeight.value = `${height > 100 ? height : 600}px`;
490
+ }
491
+ });
492
+ };
493
+ __expose({
494
+ show() {
495
+ fomDrawer.value?.show();
496
+ },
497
+ hide() {
498
+ fomDrawer.value?.hide();
499
+ }
500
+ });
501
+ return (_ctx, _cache) => {
502
+ return vue.openBlock(), vue.createBlock(vue.unref(form.MFormDrawer), {
503
+ ref_key: "fomDrawer",
504
+ ref: fomDrawer,
505
+ "label-width": "80px",
506
+ title: _ctx.content.name,
507
+ width: size.value,
508
+ config: functionConfig.value,
509
+ values: _ctx.content,
510
+ disabled: _ctx.disabled,
511
+ onSubmit: submitForm,
512
+ onError: errorHandler,
513
+ onOpen: openHandler
514
+ }, null, 8, ["title", "width", "config", "values", "disabled"]);
515
+ };
516
+ }
517
+ });
518
+
519
+ const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
520
+ ...{
521
+ name: "MEditorCodeParams"
522
+ },
523
+ __name: "CodeParams",
524
+ props: {
525
+ model: {},
526
+ size: {},
527
+ disabled: { type: Boolean },
528
+ name: {},
529
+ paramsConfig: {}
530
+ },
531
+ emits: ["change"],
532
+ setup(__props, { emit }) {
533
+ const props = __props;
534
+ const form$1 = vue.ref();
535
+ const getFormConfig = (items = []) => [
536
+ {
537
+ type: "fieldset",
538
+ items,
539
+ legend: "参数",
540
+ labelWidth: "70px",
541
+ name: props.name
542
+ }
543
+ ];
544
+ const codeParamsConfig = vue.computed(() => getFormConfig(props.paramsConfig));
545
+ const onParamsChangeHandler = async () => {
546
+ try {
547
+ const value = await form$1.value?.submitForm(true);
548
+ emit("change", value);
549
+ } catch (e) {
550
+ console.log(e);
551
+ }
552
+ };
553
+ return (_ctx, _cache) => {
554
+ return vue.openBlock(), vue.createBlock(vue.unref(form.MForm), {
555
+ ref_key: "form",
556
+ ref: form$1,
557
+ config: codeParamsConfig.value,
558
+ "init-values": _ctx.model,
559
+ disabled: _ctx.disabled,
560
+ size: _ctx.size,
561
+ "watch-props": false,
562
+ onChange: onParamsChangeHandler
563
+ }, null, 8, ["config", "init-values", "disabled", "size"]);
564
+ };
565
+ }
566
+ });
567
+
568
+ const _hoisted_1$q = ["src"];
205
569
  const _sfc_main$E = /* @__PURE__ */ vue.defineComponent({
206
570
  ...{
207
571
  name: "MEditorIcon"
@@ -225,7 +589,7 @@
225
589
  class: "magic-editor-icon"
226
590
  }, {
227
591
  default: vue.withCtx(() => [
228
- vue.createElementVNode("img", { src: _ctx.icon }, null, 8, _hoisted_1$p)
592
+ vue.createElementVNode("img", { src: _ctx.icon }, null, 8, _hoisted_1$q)
229
593
  ]),
230
594
  _: 1
231
595
  })) : typeof _ctx.icon === "string" ? (vue.openBlock(), vue.createElementBlock("i", {
@@ -244,7 +608,65 @@
244
608
  }
245
609
  });
246
610
 
247
- const _hoisted_1$o = { class: "m-fields-code-select-col" };
611
+ const useCodeBlockEdit = (codeBlockService) => {
612
+ const codeConfig = vue.ref();
613
+ const codeId = vue.ref();
614
+ const codeBlockEditor = vue.ref();
615
+ const createCodeBlock = async () => {
616
+ if (!codeBlockService) {
617
+ design.tMagicMessage.error("新增代码块失败");
618
+ return;
619
+ }
620
+ codeConfig.value = {
621
+ name: "代码块",
622
+ content: `({app, params}) => {
623
+ // place your code here
624
+ }`,
625
+ params: []
626
+ };
627
+ codeId.value = await codeBlockService.getUniqueId();
628
+ await vue.nextTick();
629
+ codeBlockEditor.value?.show();
630
+ };
631
+ const editCode = async (id) => {
632
+ const codeBlock = await codeBlockService?.getCodeContentById(id);
633
+ if (!codeBlock) {
634
+ design.tMagicMessage.error("获取代码块内容失败");
635
+ return;
636
+ }
637
+ let codeContent = codeBlock.content;
638
+ if (typeof codeContent !== "string") {
639
+ codeContent = codeContent.toString();
640
+ }
641
+ codeConfig.value = {
642
+ ...lodashEs.cloneDeep(codeBlock),
643
+ content: codeContent
644
+ };
645
+ codeId.value = id;
646
+ await vue.nextTick();
647
+ codeBlockEditor.value?.show();
648
+ };
649
+ const deleteCode = async (key) => {
650
+ codeBlockService?.deleteCodeDslByIds([key]);
651
+ };
652
+ const submitCodeBlockHandler = async (values) => {
653
+ if (!codeId.value)
654
+ return;
655
+ await codeBlockService?.setCodeDslById(codeId.value, values);
656
+ codeBlockEditor.value?.hide();
657
+ };
658
+ return {
659
+ codeId,
660
+ codeConfig,
661
+ codeBlockEditor,
662
+ createCodeBlock,
663
+ editCode,
664
+ deleteCode,
665
+ submitCodeBlockHandler
666
+ };
667
+ };
668
+
669
+ const _hoisted_1$p = { class: "m-fields-code-select-col" };
248
670
  const _hoisted_2$f = { class: "code-select-container" };
249
671
  const _sfc_main$D = /* @__PURE__ */ vue.defineComponent({
250
672
  ...{
@@ -256,28 +678,33 @@
256
678
  model: {},
257
679
  prop: {},
258
680
  name: {},
681
+ lastValues: {},
682
+ disabled: { type: Boolean, default: false },
259
683
  size: {}
260
684
  },
261
685
  emits: ["change"],
262
686
  setup(__props, { emit }) {
263
687
  const props = __props;
264
688
  const services = vue.inject("services");
265
- const mForm = vue.inject("mForm");
689
+ const getParamItemsConfig = (codeId) => {
690
+ if (!codeDsl.value || !codeId)
691
+ return [];
692
+ const paramStatements = codeDsl.value[codeId]?.params;
693
+ if (lodashEs.isEmpty(paramStatements))
694
+ return [];
695
+ return paramStatements.map((paramState) => ({
696
+ labelWidth: "100px",
697
+ text: paramState.name,
698
+ ...paramState
699
+ }));
700
+ };
266
701
  const codeDsl = vue.computed(() => services?.codeBlockService.getCodeDsl());
267
- const editable = vue.computed(() => services?.codeBlockService.getEditStatus());
268
- const codeParamsConfig = vue.ref({
269
- type: "fieldset",
270
- items: [],
271
- legend: "参数",
272
- labelWidth: "70px",
273
- name: "params",
274
- display: false
275
- });
702
+ const paramsConfig = vue.ref(getParamItemsConfig(props.model[props.name]));
276
703
  const selectConfig = {
277
704
  type: "select",
278
705
  text: "代码块",
279
- name: "codeId",
280
- labelWidth: "70px",
706
+ name: props.name,
707
+ labelWidth: "80px",
281
708
  options: () => {
282
709
  if (codeDsl.value) {
283
710
  return lodashEs.map(codeDsl.value, (value, key) => ({
@@ -289,56 +716,23 @@
289
716
  return [];
290
717
  },
291
718
  onChange: (formState, codeId, { model }) => {
292
- model.params = {};
293
- }
294
- };
295
- const getParamItemsConfig = (codeId) => {
296
- if (!codeDsl.value)
297
- return [];
298
- const paramStatements = codeDsl.value[codeId]?.params;
299
- if (lodashEs.isEmpty(paramStatements))
300
- return [];
301
- return paramStatements.map((paramState) => ({
302
- labelWidth: "100px",
303
- text: paramState.name,
304
- ...paramState
305
- }));
306
- };
307
- const getCodeParamsConfig = (codeId) => {
308
- const paramsConfig = getParamItemsConfig(codeId);
309
- if (!props.model.params || lodashEs.isEmpty(props.model.params)) {
310
- props.model.params = {};
311
- form.createValues(mForm, paramsConfig, {}, props.model.params);
719
+ paramsConfig.value = getParamItemsConfig(codeId);
720
+ if (paramsConfig.value.length) {
721
+ model.params = form.createValues(formState, paramsConfig.value, {}, model.params);
722
+ } else {
723
+ model.params = {};
724
+ }
725
+ return codeId;
312
726
  }
313
- codeParamsConfig.value = {
314
- type: "fieldset",
315
- items: paramsConfig,
316
- legend: "参数",
317
- labelWidth: "70px",
318
- name: "params",
319
- display: !lodashEs.isEmpty(paramsConfig)
320
- };
321
727
  };
322
- const onParamsChangeHandler = () => {
728
+ const onParamsChangeHandler = (value) => {
729
+ props.model.params = value.params;
323
730
  emit("change", props.model);
324
731
  };
325
- vue.watch(
326
- () => props.model.codeId,
327
- (codeId) => {
328
- if (!codeId)
329
- return;
330
- getCodeParamsConfig(codeId);
331
- },
332
- {
333
- immediate: true
334
- }
335
- );
336
- const editCode = () => {
337
- services?.codeBlockService.setCodeEditorContent(true, props.model.codeId);
338
- };
732
+ const { codeBlockEditor, codeConfig, editCode, submitCodeBlockHandler } = useCodeBlockEdit(services?.codeBlockService);
339
733
  return (_ctx, _cache) => {
340
734
  const _component_m_form_container = vue.resolveComponent("m-form-container");
341
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$o, [
735
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$p, [
342
736
  vue.createElementVNode("div", _hoisted_2$f, [
343
737
  vue.createVNode(_component_m_form_container, {
344
738
  class: "select",
@@ -346,23 +740,35 @@
346
740
  model: _ctx.model,
347
741
  onChange: onParamsChangeHandler
348
742
  }, null, 8, ["model"]),
349
- vue.createVNode(_sfc_main$E, {
743
+ _ctx.model[_ctx.name] ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
744
+ key: 0,
350
745
  class: "icon",
351
- icon: editable.value ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
352
- onClick: editCode
353
- }, null, 8, ["icon"])
746
+ icon: !_ctx.disabled ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
747
+ onClick: _cache[0] || (_cache[0] = ($event) => vue.unref(editCode)(_ctx.model[_ctx.name]))
748
+ }, null, 8, ["icon"])) : vue.createCommentVNode("", true)
354
749
  ]),
355
- vue.createVNode(_component_m_form_container, {
356
- config: codeParamsConfig.value,
750
+ paramsConfig.value.length ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
751
+ key: 0,
752
+ name: "params",
357
753
  model: _ctx.model,
754
+ size: _ctx.size,
755
+ "params-config": paramsConfig.value,
358
756
  onChange: onParamsChangeHandler
359
- }, null, 8, ["config", "model"])
757
+ }, null, 8, ["model", "size", "params-config"])) : vue.createCommentVNode("", true),
758
+ vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
759
+ key: 1,
760
+ ref_key: "codeBlockEditor",
761
+ ref: codeBlockEditor,
762
+ disabled: _ctx.disabled,
763
+ content: vue.unref(codeConfig),
764
+ onSubmit: vue.unref(submitCodeBlockHandler)
765
+ }, null, 8, ["disabled", "content", "onSubmit"])) : vue.createCommentVNode("", true)
360
766
  ]);
361
767
  };
362
768
  }
363
769
  });
364
770
 
365
- const _hoisted_1$n = { class: "m-editor-data-source-fields" };
771
+ const _hoisted_1$o = { class: "m-editor-data-source-fields" };
366
772
  const _hoisted_2$e = { class: "m-editor-data-source-fields-footer" };
367
773
  const _sfc_main$C = /* @__PURE__ */ vue.defineComponent({
368
774
  ...{
@@ -373,6 +779,7 @@
373
779
  config: {},
374
780
  model: {},
375
781
  prop: {},
782
+ lastValues: {},
376
783
  disabled: { type: Boolean, default: false },
377
784
  name: {}
378
785
  },
@@ -383,24 +790,20 @@
383
790
  const fieldValues = vue.ref({});
384
791
  const filedTitle = vue.ref("");
385
792
  const newHandler = () => {
386
- if (!addDialog.value)
387
- return;
388
793
  fieldValues.value = {};
389
794
  filedTitle.value = "新增属性";
390
- addDialog.value.dialogVisible = true;
795
+ addDialog.value?.show();
391
796
  };
392
797
  const fieldChange = ({ index, ...value }) => {
393
- if (!addDialog.value)
394
- return;
395
798
  if (index > -1) {
396
799
  props.model[props.name][index] = value;
397
800
  } else {
398
801
  props.model[props.name].push(value);
399
802
  }
400
- addDialog.value.dialogVisible = false;
803
+ addDialog.value?.hide();
401
804
  emit("change", props.model[props.name]);
402
805
  };
403
- const filedColumns = [
806
+ const fieldColumns = [
404
807
  {
405
808
  label: "属性名称",
406
809
  prop: "title"
@@ -420,14 +823,12 @@
420
823
  {
421
824
  text: "编辑",
422
825
  handler: (row, index) => {
423
- if (!addDialog.value)
424
- return;
425
826
  fieldValues.value = {
426
827
  ...row,
427
828
  index
428
829
  };
429
830
  filedTitle.value = `编辑${row.title}`;
430
- addDialog.value.dialogVisible = true;
831
+ addDialog.value?.show();
431
832
  }
432
833
  },
433
834
  {
@@ -510,10 +911,10 @@
510
911
  }
511
912
  ];
512
913
  return (_ctx, _cache) => {
513
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$n, [
914
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$o, [
514
915
  vue.createVNode(vue.unref(table.MagicTable), {
515
916
  data: _ctx.model[_ctx.name],
516
- columns: filedColumns
917
+ columns: fieldColumns
517
918
  }, null, 8, ["data"]),
518
919
  vue.createElementVNode("div", _hoisted_2$e, [
519
920
  vue.createVNode(vue.unref(design.TMagicButton), {
@@ -536,16 +937,17 @@
536
937
  config: dataSourceFieldsConfig,
537
938
  values: fieldValues.value,
538
939
  parentValues: _ctx.model[_ctx.name],
940
+ disabled: _ctx.disabled,
539
941
  onSubmit: fieldChange
540
- }, null, 8, ["title", "values", "parentValues"])
942
+ }, null, 8, ["title", "values", "parentValues", "disabled"])
541
943
  ]);
542
944
  };
543
945
  }
544
946
  });
545
947
 
546
- const _hoisted_1$m = { style: { "display": "flex", "flex-direction": "column", "line-height": "1.2em" } };
948
+ const _hoisted_1$n = { style: { "display": "flex", "flex-direction": "column", "line-height": "1.2em" } };
547
949
  const _hoisted_2$d = { style: { "font-size": "10px", "color": "rgba(0, 0, 0, 0.6)" } };
548
- const _hoisted_3$6 = { class: "el-input__inner" };
950
+ const _hoisted_3$5 = { class: "el-input__inner" };
549
951
  const _sfc_main$B = /* @__PURE__ */ vue.defineComponent({
550
952
  ...{
551
953
  name: "MEditorDataSourceInput"
@@ -768,50 +1170,333 @@
768
1170
  vue.createVNode(_sfc_main$E, { icon: vue.unref(iconsVue.Coin) }, null, 8, ["icon"])
769
1171
  ]),
770
1172
  default: vue.withCtx(({ item }) => [
771
- vue.createElementVNode("div", _hoisted_1$m, [
1173
+ vue.createElementVNode("div", _hoisted_1$n, [
772
1174
  vue.createElementVNode("div", null, vue.toDisplayString(item.text), 1),
773
1175
  vue.createElementVNode("span", _hoisted_2$d, vue.toDisplayString(item.value), 1)
774
1176
  ])
775
1177
  ]),
776
- _: 1
777
- }, 16, ["modelValue"])) : (vue.openBlock(), vue.createElementBlock("div", {
778
- key: 1,
779
- class: vue.normalizeClass(`tmagic-data-source-input-text el-input el-input--${_ctx.size}`),
780
- onMouseup: mouseupHandler
781
- }, [
782
- vue.createElementVNode("div", {
783
- class: vue.normalizeClass(`tmagic-data-source-input-text-wrapper el-input__wrapper ${isFocused.value ? " is-focus" : ""}`)
784
- }, [
785
- vue.createElementVNode("div", _hoisted_3$6, [
786
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(displayState.value, (item, index) => {
787
- return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
788
- item.type === "text" ? (vue.openBlock(), vue.createElementBlock("span", {
789
- key: index,
790
- style: { "margin-right": "2px" }
791
- }, vue.toDisplayString(item.value), 1)) : vue.createCommentVNode("", true),
792
- item.type === "var" ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTag), {
793
- key: index,
794
- size: _ctx.size
795
- }, {
796
- default: vue.withCtx(() => [
797
- vue.createTextVNode(vue.toDisplayString(item.value), 1)
798
- ]),
799
- _: 2
800
- }, 1032, ["size"])) : vue.createCommentVNode("", true)
801
- ], 64);
802
- }), 256)),
803
- vue.createVNode(_sfc_main$E, {
804
- class: "tmagic-data-source-input-icon",
805
- icon: vue.unref(iconsVue.Coin)
806
- }, null, 8, ["icon"])
807
- ])
808
- ], 2)
809
- ], 34));
1178
+ _: 1
1179
+ }, 16, ["modelValue"])) : (vue.openBlock(), vue.createElementBlock("div", {
1180
+ key: 1,
1181
+ class: vue.normalizeClass(`tmagic-data-source-input-text el-input el-input--${_ctx.size}`),
1182
+ onMouseup: mouseupHandler
1183
+ }, [
1184
+ vue.createElementVNode("div", {
1185
+ class: vue.normalizeClass(`tmagic-data-source-input-text-wrapper el-input__wrapper ${isFocused.value ? " is-focus" : ""}`)
1186
+ }, [
1187
+ vue.createElementVNode("div", _hoisted_3$5, [
1188
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(displayState.value, (item, index) => {
1189
+ return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
1190
+ item.type === "text" ? (vue.openBlock(), vue.createElementBlock("span", {
1191
+ key: index,
1192
+ style: { "margin-right": "2px" }
1193
+ }, vue.toDisplayString(item.value), 1)) : vue.createCommentVNode("", true),
1194
+ item.type === "var" ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTag), {
1195
+ key: index,
1196
+ size: _ctx.size
1197
+ }, {
1198
+ default: vue.withCtx(() => [
1199
+ vue.createTextVNode(vue.toDisplayString(item.value), 1)
1200
+ ]),
1201
+ _: 2
1202
+ }, 1032, ["size"])) : vue.createCommentVNode("", true)
1203
+ ], 64);
1204
+ }), 256)),
1205
+ vue.createVNode(_sfc_main$E, {
1206
+ class: "tmagic-data-source-input-icon",
1207
+ icon: vue.unref(iconsVue.Coin)
1208
+ }, null, 8, ["icon"])
1209
+ ])
1210
+ ], 2)
1211
+ ], 34));
1212
+ };
1213
+ }
1214
+ });
1215
+
1216
+ const useDataSourceMethod = () => {
1217
+ const codeConfig = vue.ref();
1218
+ const codeBlockEditor = vue.ref();
1219
+ const dataSource = vue.ref();
1220
+ const dataSourceMethod = vue.ref("");
1221
+ return {
1222
+ codeConfig,
1223
+ codeBlockEditor,
1224
+ createCode: async (model) => {
1225
+ codeConfig.value = {
1226
+ name: "",
1227
+ content: `({ params, dataSource, app }) => {
1228
+ // place your code here
1229
+ }`,
1230
+ params: []
1231
+ };
1232
+ await vue.nextTick();
1233
+ dataSource.value = model;
1234
+ dataSourceMethod.value = "";
1235
+ codeBlockEditor.value?.show();
1236
+ },
1237
+ editCode: async (model, methodName) => {
1238
+ const method = model.methods?.find((method2) => method2.name === methodName);
1239
+ if (!method) {
1240
+ design.tMagicMessage.error("获取数据源方法失败");
1241
+ return;
1242
+ }
1243
+ let codeContent = method.content;
1244
+ if (typeof codeContent !== "string") {
1245
+ codeContent = codeContent.toString();
1246
+ }
1247
+ codeConfig.value = {
1248
+ ...lodashEs.cloneDeep(method),
1249
+ content: codeContent
1250
+ };
1251
+ await vue.nextTick();
1252
+ dataSource.value = model;
1253
+ dataSourceMethod.value = methodName;
1254
+ codeBlockEditor.value?.show();
1255
+ },
1256
+ deleteCode: async (model, methodName) => {
1257
+ if (!model.methods)
1258
+ return;
1259
+ const index = model.methods.findIndex((method) => method.name === methodName);
1260
+ if (index === -1) {
1261
+ return;
1262
+ }
1263
+ model.methods.splice(index, 1);
1264
+ },
1265
+ submitCode: (values) => {
1266
+ if (!dataSource.value)
1267
+ return;
1268
+ if (!dataSource.value.methods) {
1269
+ dataSource.value.methods = [];
1270
+ }
1271
+ if (values.content) {
1272
+ const parseDSL = getConfig("parseDSL");
1273
+ if (typeof values.content === "string") {
1274
+ values.content = parseDSL(values.content);
1275
+ }
1276
+ }
1277
+ if (dataSourceMethod.value) {
1278
+ const index = dataSource.value.methods.findIndex((method) => method.name === dataSourceMethod.value);
1279
+ dataSource.value.methods.splice(index, 1, values);
1280
+ } else {
1281
+ dataSource.value.methods.push(values);
1282
+ }
1283
+ codeBlockEditor.value?.hide();
1284
+ }
1285
+ };
1286
+ };
1287
+
1288
+ const _hoisted_1$m = { class: "m-editor-data-source-methods" };
1289
+ const _hoisted_2$c = { class: "m-editor-data-source-methods-footer" };
1290
+ const _sfc_main$A = /* @__PURE__ */ vue.defineComponent({
1291
+ ...{
1292
+ name: "MEditorDataSourceMethods"
1293
+ },
1294
+ __name: "DataSourceMethods",
1295
+ props: {
1296
+ config: {},
1297
+ model: {},
1298
+ prop: {},
1299
+ lastValues: {},
1300
+ disabled: { type: Boolean, default: false },
1301
+ name: {}
1302
+ },
1303
+ emits: ["change"],
1304
+ setup(__props, { emit }) {
1305
+ const props = __props;
1306
+ const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
1307
+ const methodColumns = [
1308
+ {
1309
+ label: "名称",
1310
+ prop: "name"
1311
+ },
1312
+ {
1313
+ label: "注释",
1314
+ prop: "desc"
1315
+ },
1316
+ {
1317
+ label: "参数",
1318
+ prop: "params",
1319
+ formatter: (params) => params.map((item) => item.name).join(", ")
1320
+ },
1321
+ {
1322
+ label: "操作",
1323
+ fixed: "right",
1324
+ actions: [
1325
+ {
1326
+ text: "编辑",
1327
+ handler: (row) => {
1328
+ editCode(props.model, row.name);
1329
+ emit("change", props.model[props.name]);
1330
+ }
1331
+ },
1332
+ {
1333
+ text: "删除",
1334
+ buttonType: "danger",
1335
+ handler: (row) => {
1336
+ deleteCode(props.model, row.name);
1337
+ emit("change", props.model[props.name]);
1338
+ }
1339
+ }
1340
+ ]
1341
+ }
1342
+ ];
1343
+ const createCodeHandler = () => {
1344
+ createCode(props.model);
1345
+ emit("change", props.model[props.name]);
1346
+ };
1347
+ const submitCodeHandler = (values) => {
1348
+ submitCode(values);
1349
+ emit("change", props.model[props.name]);
1350
+ };
1351
+ return (_ctx, _cache) => {
1352
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$m, [
1353
+ vue.createVNode(vue.unref(table.MagicTable), {
1354
+ data: _ctx.model[_ctx.name],
1355
+ columns: methodColumns
1356
+ }, null, 8, ["data"]),
1357
+ vue.createElementVNode("div", _hoisted_2$c, [
1358
+ vue.createVNode(vue.unref(design.TMagicButton), {
1359
+ size: "small",
1360
+ type: "primary",
1361
+ disabled: _ctx.disabled,
1362
+ plain: "",
1363
+ onClick: createCodeHandler
1364
+ }, {
1365
+ default: vue.withCtx(() => [
1366
+ vue.createTextVNode("添加")
1367
+ ]),
1368
+ _: 1
1369
+ }, 8, ["disabled"])
1370
+ ]),
1371
+ vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
1372
+ key: 0,
1373
+ ref_key: "codeBlockEditor",
1374
+ ref: codeBlockEditor,
1375
+ disabled: _ctx.disabled,
1376
+ content: vue.unref(codeConfig),
1377
+ onSubmit: submitCodeHandler
1378
+ }, null, 8, ["disabled", "content"])) : vue.createCommentVNode("", true)
1379
+ ]);
1380
+ };
1381
+ }
1382
+ });
1383
+
1384
+ const _hoisted_1$l = { class: "m-fields-data-source-method-select" };
1385
+ const _hoisted_2$b = { class: "data-source-method-select-container" };
1386
+ const _sfc_main$z = /* @__PURE__ */ vue.defineComponent({
1387
+ ...{
1388
+ name: "MEditorDataSourceMethodSelect"
1389
+ },
1390
+ __name: "DataSourceMethodSelect",
1391
+ props: {
1392
+ config: {},
1393
+ model: {},
1394
+ lastValues: {},
1395
+ prop: {},
1396
+ name: {},
1397
+ disabled: { type: Boolean, default: false },
1398
+ size: {}
1399
+ },
1400
+ emits: ["change"],
1401
+ setup(__props, { emit }) {
1402
+ const props = __props;
1403
+ const services = vue.inject("services");
1404
+ const dataSources = vue.computed(() => services?.dataSourceService.get("dataSources"));
1405
+ const getParamItemsConfig = ([dataSourceId, medthodName] = ["", ""]) => {
1406
+ if (!dataSourceId)
1407
+ return [];
1408
+ const paramStatements = dataSources.value?.find((item) => item.id === dataSourceId)?.methods?.find((item) => item.name === medthodName)?.params;
1409
+ if (!paramStatements)
1410
+ return [];
1411
+ return paramStatements.map((paramState) => ({
1412
+ labelWidth: "100px",
1413
+ text: paramState.name,
1414
+ ...paramState
1415
+ }));
1416
+ };
1417
+ const paramsConfig = vue.ref(getParamItemsConfig(props.model.dataSourceMethod));
1418
+ const setParamsConfig = (dataSourceMethod, formState = {}) => {
1419
+ paramsConfig.value = dataSourceMethod ? getParamItemsConfig(dataSourceMethod) : [];
1420
+ if (paramsConfig.value.length) {
1421
+ props.model.params = form.createValues(formState, paramsConfig.value, {}, props.model.params);
1422
+ } else {
1423
+ props.model.params = {};
1424
+ }
1425
+ };
1426
+ const cascaderConfig = {
1427
+ type: "cascader",
1428
+ text: "数据源方法",
1429
+ name: props.name,
1430
+ labelWidth: "80px",
1431
+ options: () => dataSources.value?.filter((ds) => ds.methods?.length)?.map((ds) => ({
1432
+ label: `${ds.title}(${ds.id})`,
1433
+ value: ds.id,
1434
+ children: ds.methods?.map((method) => ({
1435
+ label: method.name,
1436
+ value: method.name
1437
+ }))
1438
+ })) || [],
1439
+ onChange: (formState, dataSourceMethod) => {
1440
+ setParamsConfig(dataSourceMethod, formState);
1441
+ return dataSourceMethod;
1442
+ }
1443
+ };
1444
+ const onChangeHandler = (value) => {
1445
+ props.model.params = value.params;
1446
+ emit("change", props.model);
1447
+ };
1448
+ const { codeBlockEditor, codeConfig, editCode, submitCode } = useDataSourceMethod();
1449
+ const editCodeHandler = () => {
1450
+ const [id, name] = props.model[props.name];
1451
+ const dataSource = services?.dataSourceService.getDataSourceById(id);
1452
+ if (!dataSource)
1453
+ return;
1454
+ editCode(dataSource, name);
1455
+ setParamsConfig([id, name]);
1456
+ };
1457
+ const submitCodeBlockHandler = (value) => {
1458
+ submitCode(value);
1459
+ };
1460
+ return (_ctx, _cache) => {
1461
+ const _component_m_form_container = vue.resolveComponent("m-form-container");
1462
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$l, [
1463
+ vue.createElementVNode("div", _hoisted_2$b, [
1464
+ vue.createVNode(_component_m_form_container, {
1465
+ class: "select",
1466
+ config: cascaderConfig,
1467
+ model: _ctx.model,
1468
+ onChange: onChangeHandler
1469
+ }, null, 8, ["model"]),
1470
+ _ctx.model[_ctx.name] ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
1471
+ key: 0,
1472
+ class: "icon",
1473
+ icon: !_ctx.disabled ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
1474
+ onClick: editCodeHandler
1475
+ }, null, 8, ["icon"])) : vue.createCommentVNode("", true)
1476
+ ]),
1477
+ paramsConfig.value.length ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
1478
+ key: 0,
1479
+ name: "params",
1480
+ model: _ctx.model,
1481
+ size: _ctx.size,
1482
+ disabled: _ctx.disabled,
1483
+ "params-config": paramsConfig.value,
1484
+ onChange: onChangeHandler
1485
+ }, null, 8, ["model", "size", "disabled", "params-config"])) : vue.createCommentVNode("", true),
1486
+ vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
1487
+ key: 1,
1488
+ ref_key: "codeBlockEditor",
1489
+ ref: codeBlockEditor,
1490
+ disabled: _ctx.disabled,
1491
+ content: vue.unref(codeConfig),
1492
+ onSubmit: submitCodeBlockHandler
1493
+ }, null, 8, ["disabled", "content"])) : vue.createCommentVNode("", true)
1494
+ ]);
810
1495
  };
811
1496
  }
812
1497
  });
813
1498
 
814
- const _sfc_main$A = /* @__PURE__ */ vue.defineComponent({
1499
+ const _sfc_main$y = /* @__PURE__ */ vue.defineComponent({
815
1500
  ...{
816
1501
  name: "MEditorDataSourceSelect"
817
1502
  },
@@ -864,12 +1549,12 @@
864
1549
  }
865
1550
  });
866
1551
 
867
- const _hoisted_1$l = { class: "m-fields-event-select" };
868
- const _hoisted_2$c = {
1552
+ const _hoisted_1$k = { class: "m-fields-event-select" };
1553
+ const _hoisted_2$a = {
869
1554
  key: 1,
870
1555
  class: "fullWidth"
871
1556
  };
872
- const _sfc_main$z = /* @__PURE__ */ vue.defineComponent({
1557
+ const _sfc_main$x = /* @__PURE__ */ vue.defineComponent({
873
1558
  ...{
874
1559
  name: "MEditorEventSelect"
875
1560
  },
@@ -902,7 +1587,7 @@
902
1587
  const defaultActionTypeConfig = {
903
1588
  name: "actionType",
904
1589
  text: "联动类型",
905
- labelWidth: "70px",
1590
+ labelWidth: "80px",
906
1591
  type: "select",
907
1592
  defaultValue: schema.ActionType.COMP,
908
1593
  options: () => [
@@ -914,7 +1599,14 @@
914
1599
  {
915
1600
  text: "代码",
916
1601
  label: "代码",
1602
+ disabled: !Object.keys(services?.codeBlockService.getCodeDsl() || {}).length,
917
1603
  value: schema.ActionType.CODE
1604
+ },
1605
+ {
1606
+ text: "数据源",
1607
+ label: "数据源",
1608
+ disabled: !services?.dataSourceService.get("dataSources")?.filter((ds) => ds.methods?.length).length,
1609
+ value: schema.ActionType.DATA_SOURCE
918
1610
  }
919
1611
  ]
920
1612
  };
@@ -924,7 +1616,7 @@
924
1616
  const defaultTargetCompConfig = {
925
1617
  name: "to",
926
1618
  text: "联动组件",
927
- labelWidth: "70px",
1619
+ labelWidth: "80px",
928
1620
  type: "ui-select",
929
1621
  display: (mForm, { model }) => model.actionType === schema.ActionType.COMP
930
1622
  };
@@ -934,7 +1626,7 @@
934
1626
  const defaultCompActionConfig = {
935
1627
  name: "method",
936
1628
  text: "动作",
937
- labelWidth: "70px",
1629
+ labelWidth: "80px",
938
1630
  type: "select",
939
1631
  display: (mForm, { model }) => model.actionType === schema.ActionType.COMP,
940
1632
  options: (mForm, { model }) => {
@@ -953,10 +1645,21 @@
953
1645
  const defaultCodeActionConfig = {
954
1646
  type: "code-select-col",
955
1647
  labelWidth: 0,
1648
+ name: "codeId",
1649
+ disabled: () => !services?.codeBlockService.getEditStatus(),
956
1650
  display: (mForm, { model }) => model.actionType === schema.ActionType.CODE
957
1651
  };
958
1652
  return { ...defaultCodeActionConfig, ...props.config.codeActionConfig };
959
1653
  });
1654
+ const dataSourceActionConfig = vue.computed(() => {
1655
+ const defaultDataSourceActionConfig = {
1656
+ type: "data-source-method-select",
1657
+ name: "dataSourceMethod",
1658
+ labelWidth: 0,
1659
+ display: (mForm, { model }) => model.actionType === schema.ActionType.DATA_SOURCE
1660
+ };
1661
+ return { ...defaultDataSourceActionConfig, ...props.config.dataSourceActionConfig };
1662
+ });
960
1663
  const tableConfig = vue.computed(() => ({
961
1664
  type: "table",
962
1665
  name: "events",
@@ -998,7 +1701,13 @@
998
1701
  name: "actions",
999
1702
  expandAll: true,
1000
1703
  enableToggleMode: false,
1001
- items: [actionTypeConfig.value, targetCompConfig.value, compActionConfig.value, codeActionConfig.value]
1704
+ items: [
1705
+ actionTypeConfig.value,
1706
+ targetCompConfig.value,
1707
+ compActionConfig.value,
1708
+ codeActionConfig.value,
1709
+ dataSourceActionConfig.value
1710
+ ]
1002
1711
  }
1003
1712
  ]
1004
1713
  }));
@@ -1031,7 +1740,7 @@
1031
1740
  const _component_m_form_table = vue.resolveComponent("m-form-table");
1032
1741
  const _component_m_form_container = vue.resolveComponent("m-form-container");
1033
1742
  const _component_m_form_panel = vue.resolveComponent("m-form-panel");
1034
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$l, [
1743
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$k, [
1035
1744
  isOldVersion.value ? (vue.openBlock(), vue.createBlock(_component_m_form_table, {
1036
1745
  key: 0,
1037
1746
  ref: "eventForm",
@@ -1040,7 +1749,7 @@
1040
1749
  name: "events",
1041
1750
  config: tableConfig.value,
1042
1751
  onChange: onChangeHandler
1043
- }, null, 8, ["size", "model", "config"])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$c, [
1752
+ }, null, 8, ["size", "model", "config"])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$a, [
1044
1753
  vue.createVNode(vue.unref(design.TMagicButton), {
1045
1754
  class: "create-button",
1046
1755
  type: "primary",
@@ -1082,9 +1791,9 @@
1082
1791
  }
1083
1792
  });
1084
1793
 
1085
- const _hoisted_1$k = { class: "m-fields-key-value" };
1086
- const _hoisted_2$b = /* @__PURE__ */ vue.createElementVNode("span", { class: "m-fileds-key-value-delimiter" }, ":", -1);
1087
- const _sfc_main$y = /* @__PURE__ */ vue.defineComponent({
1794
+ const _hoisted_1$j = { class: "m-fields-key-value" };
1795
+ const _hoisted_2$9 = /* @__PURE__ */ vue.createElementVNode("span", { class: "m-fileds-key-value-delimiter" }, ":", -1);
1796
+ const _sfc_main$w = /* @__PURE__ */ vue.defineComponent({
1088
1797
  ...{
1089
1798
  name: "MEditorKeyValue"
1090
1799
  },
@@ -1127,7 +1836,7 @@
1127
1836
  records.value.splice(index, 1);
1128
1837
  };
1129
1838
  return (_ctx, _cache) => {
1130
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$k, [
1839
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$j, [
1131
1840
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(records.value, (item, index) => {
1132
1841
  return vue.openBlock(), vue.createElementBlock("div", {
1133
1842
  class: "m-fields-key-value-item",
@@ -1141,7 +1850,7 @@
1141
1850
  size: _ctx.size,
1142
1851
  onChange: keyChangeHandler
1143
1852
  }, null, 8, ["modelValue", "onUpdate:modelValue", "disabled", "size"]),
1144
- _hoisted_2$b,
1853
+ _hoisted_2$9,
1145
1854
  vue.createVNode(vue.unref(design.TMagicInput), {
1146
1855
  placeholder: "value",
1147
1856
  modelValue: records.value[index][1],
@@ -1178,7 +1887,12 @@
1178
1887
  }
1179
1888
  });
1180
1889
 
1181
- const _sfc_main$x = /* @__PURE__ */ vue.defineComponent({
1890
+ const _hoisted_1$i = {
1891
+ key: 1,
1892
+ class: "m-fields-ui-select",
1893
+ style: { "display": "flex" }
1894
+ };
1895
+ const _sfc_main$v = /* @__PURE__ */ vue.defineComponent({
1182
1896
  ...{
1183
1897
  name: "MEditorUISelect"
1184
1898
  },
@@ -1231,6 +1945,18 @@
1231
1945
  mForm?.$emit("field-change", props.prop, "");
1232
1946
  }
1233
1947
  };
1948
+ const selectNode = async (id) => {
1949
+ await services?.editorService.select(id);
1950
+ services?.editorService.get("stage")?.select(id);
1951
+ };
1952
+ const highlight = lodashEs.throttle((id) => {
1953
+ services?.editorService.highlight(id);
1954
+ services?.editorService.get("stage")?.highlight(id);
1955
+ }, 150);
1956
+ const unhightlight = () => {
1957
+ services?.editorService.set("highlightNode", null);
1958
+ services?.editorService.get("stage")?.clearHighlight();
1959
+ };
1234
1960
  return (_ctx, _cache) => {
1235
1961
  return uiSelectMode.value ? (vue.openBlock(), vue.createElementBlock("div", {
1236
1962
  key: 0,
@@ -1248,195 +1974,70 @@
1248
1974
  ]),
1249
1975
  _: 1
1250
1976
  }, 8, ["icon"])
1251
- ])) : (vue.openBlock(), vue.createElementBlock("div", {
1252
- key: 1,
1253
- class: "m-fields-ui-select",
1254
- onClick: startSelect,
1255
- style: { "display": "flex" }
1256
- }, [
1257
- val.value ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTooltip), {
1258
- key: 0,
1259
- content: "清除"
1260
- }, {
1261
- default: vue.withCtx(() => [
1262
- vue.createVNode(vue.unref(design.TMagicButton), {
1263
- style: { "padding": "0" },
1264
- type: "danger",
1265
- icon: vue.unref(iconsVue.Close),
1266
- text: "",
1267
- onClick: vue.withModifiers(deleteHandler, ["stop"])
1268
- }, null, 8, ["icon", "onClick"])
1269
- ]),
1270
- _: 1
1271
- })) : vue.createCommentVNode("", true),
1272
- vue.createVNode(vue.unref(design.TMagicTooltip), {
1273
- content: val.value ? toName.value + "_" + val.value : "点击此处选择"
1977
+ ])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$i, [
1978
+ val.value ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
1979
+ vue.createVNode(vue.unref(design.TMagicTooltip), {
1980
+ content: "清除",
1981
+ placement: "top"
1982
+ }, {
1983
+ default: vue.withCtx(() => [
1984
+ vue.createVNode(vue.unref(design.TMagicButton), {
1985
+ style: { "padding": "0" },
1986
+ type: "danger",
1987
+ icon: vue.unref(iconsVue.Close),
1988
+ text: "",
1989
+ onClick: vue.withModifiers(deleteHandler, ["stop"])
1990
+ }, null, 8, ["icon", "onClick"])
1991
+ ]),
1992
+ _: 1
1993
+ }),
1994
+ vue.createVNode(vue.unref(design.TMagicTooltip), {
1995
+ content: "点击选中组件",
1996
+ placement: "top"
1997
+ }, {
1998
+ default: vue.withCtx(() => [
1999
+ vue.createVNode(vue.unref(design.TMagicButton), {
2000
+ text: "",
2001
+ style: { "padding": "0", "margin": "0" },
2002
+ onClick: _cache[0] || (_cache[0] = ($event) => selectNode(val.value)),
2003
+ onMouseenter: _cache[1] || (_cache[1] = ($event) => vue.unref(highlight)(val.value)),
2004
+ onMouseleave: unhightlight
2005
+ }, {
2006
+ default: vue.withCtx(() => [
2007
+ vue.createTextVNode(vue.toDisplayString(`${toName.value}_${val.value}`), 1)
2008
+ ]),
2009
+ _: 1
2010
+ })
2011
+ ]),
2012
+ _: 1
2013
+ })
2014
+ ], 64)) : (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTooltip), {
2015
+ key: 1,
2016
+ content: "点击此处选择",
2017
+ placement: "top"
1274
2018
  }, {
1275
2019
  default: vue.withCtx(() => [
1276
2020
  vue.createVNode(vue.unref(design.TMagicButton), {
1277
2021
  text: "",
1278
- style: { "padding": "0", "margin": "0" }
2022
+ style: { "padding": "0", "margin": "0" },
2023
+ onClick: startSelect
1279
2024
  }, {
1280
- default: vue.withCtx(() => [
1281
- vue.createTextVNode(vue.toDisplayString(val.value ? toName.value + "_" + val.value : "点击此处选择"), 1)
1282
- ]),
1283
- _: 1
1284
- })
1285
- ]),
1286
- _: 1
1287
- }, 8, ["content"])
1288
- ]));
1289
- };
1290
- }
1291
- });
1292
-
1293
- const UISelect_vue_vue_type_style_index_0_lang = '';
1294
-
1295
- const _sfc_main$w = /* @__PURE__ */ vue.defineComponent({
1296
- ...{
1297
- name: "MEditorCodeEditor"
1298
- },
1299
- __name: "CodeEditor",
1300
- props: {
1301
- initValues: {},
1302
- modifiedValues: {},
1303
- type: {},
1304
- language: { default: "javascript" },
1305
- options: { default: () => ({
1306
- tabSize: 2
1307
- }) },
1308
- autoSave: { type: Boolean, default: true }
1309
- },
1310
- emits: ["initd", "save"],
1311
- setup(__props, { expose: __expose, emit }) {
1312
- const props = __props;
1313
- const toString = (v, language) => {
1314
- let value = "";
1315
- if (typeof v !== "string") {
1316
- if (props.language.toLocaleLowerCase() === "json") {
1317
- value = JSON.stringify(v, null, 2);
1318
- } else {
1319
- value = serialize(v, {
1320
- space: 2,
1321
- unsafe: true
1322
- }).replace(/"(\w+)":\s/g, "$1: ");
1323
- }
1324
- } else {
1325
- value = v;
1326
- }
1327
- if (language === "javascript" && value.startsWith("{") && value.endsWith("}")) {
1328
- value = `(${value})`;
1329
- }
1330
- return value;
1331
- };
1332
- let vsEditor = null;
1333
- let vsDiffEditor = null;
1334
- const values = vue.ref("");
1335
- const loading = vue.ref(false);
1336
- const codeEditor = vue.ref();
1337
- const resizeObserver = new globalThis.ResizeObserver(
1338
- lodashEs.throttle(() => {
1339
- vsEditor?.layout();
1340
- vsDiffEditor?.layout();
1341
- }, 300)
1342
- );
1343
- const setEditorValue = (v, m) => {
1344
- values.value = toString(v, props.language);
1345
- if (props.type === "diff") {
1346
- const originalModel = monaco__namespace.editor.createModel(values.value, "text/javascript");
1347
- const modifiedModel = monaco__namespace.editor.createModel(toString(m, props.language), "text/javascript");
1348
- return vsDiffEditor?.setModel({
1349
- original: originalModel,
1350
- modified: modifiedModel
1351
- });
1352
- }
1353
- return vsEditor?.setValue(values.value);
1354
- };
1355
- const getEditorValue = () => (props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || "";
1356
- const init = async () => {
1357
- if (!codeEditor.value)
1358
- return;
1359
- const options = {
1360
- value: values.value,
1361
- language: props.language,
1362
- theme: "vs-dark",
1363
- ...props.options
1364
- };
1365
- if (props.type === "diff") {
1366
- vsDiffEditor = monaco__namespace.editor.createDiffEditor(codeEditor.value, options);
1367
- } else {
1368
- vsEditor = monaco__namespace.editor.create(codeEditor.value, options);
1369
- }
1370
- setEditorValue(props.initValues, props.modifiedValues);
1371
- loading.value = false;
1372
- emit("initd", vsEditor);
1373
- codeEditor.value.addEventListener("keydown", (e) => {
1374
- if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
1375
- e.preventDefault();
1376
- e.stopPropagation();
1377
- const newValue = getEditorValue();
1378
- values.value = newValue;
1379
- emit("save", newValue);
1380
- }
1381
- });
1382
- if (props.type !== "diff" && props.autoSave) {
1383
- vsEditor?.onDidBlurEditorWidget(() => {
1384
- const newValue = getEditorValue();
1385
- if (values.value !== newValue) {
1386
- values.value = newValue;
1387
- emit("save", newValue);
1388
- }
1389
- });
1390
- }
1391
- resizeObserver.observe(codeEditor.value);
1392
- };
1393
- vue.watch(
1394
- () => props.initValues,
1395
- (v, preV) => {
1396
- if (v !== preV) {
1397
- setEditorValue(props.initValues, props.modifiedValues);
1398
- }
1399
- },
1400
- {
1401
- deep: true,
1402
- immediate: true
1403
- }
1404
- );
1405
- vue.onMounted(async () => {
1406
- loading.value = true;
1407
- init();
1408
- });
1409
- vue.onUnmounted(() => {
1410
- resizeObserver.disconnect();
1411
- });
1412
- __expose({
1413
- values,
1414
- getEditor() {
1415
- return vsEditor || vsDiffEditor;
1416
- },
1417
- getVsEditor() {
1418
- return vsEditor;
1419
- },
1420
- getVsDiffEditor() {
1421
- return vsDiffEditor;
1422
- },
1423
- setEditorValue,
1424
- focus() {
1425
- vsEditor?.focus();
1426
- vsDiffEditor?.focus();
1427
- }
1428
- });
1429
- return (_ctx, _cache) => {
1430
- return vue.openBlock(), vue.createElementBlock("div", {
1431
- ref_key: "codeEditor",
1432
- ref: codeEditor,
1433
- class: "magic-code-editor"
1434
- }, null, 512);
2025
+ default: vue.withCtx(() => [
2026
+ vue.createTextVNode("点击此处选择")
2027
+ ]),
2028
+ _: 1
2029
+ })
2030
+ ]),
2031
+ _: 1
2032
+ }))
2033
+ ]));
1435
2034
  };
1436
2035
  }
1437
2036
  });
1438
2037
 
1439
- const _sfc_main$v = /* @__PURE__ */ vue.defineComponent({
2038
+ const UISelect_vue_vue_type_style_index_0_lang = '';
2039
+
2040
+ const _sfc_main$u = /* @__PURE__ */ vue.defineComponent({
1440
2041
  ...{
1441
2042
  name: "MEditorResizer"
1442
2043
  },
@@ -1478,7 +2079,7 @@
1478
2079
  }
1479
2080
  });
1480
2081
 
1481
- const _sfc_main$u = /* @__PURE__ */ vue.defineComponent({
2082
+ const _sfc_main$t = /* @__PURE__ */ vue.defineComponent({
1482
2083
  ...{
1483
2084
  name: "MEditorLayout"
1484
2085
  },
@@ -1590,7 +2191,7 @@
1590
2191
  }, [
1591
2192
  vue.renderSlot(_ctx.$slots, "left")
1592
2193
  ], 6),
1593
- vue.createVNode(_sfc_main$v, { onChange: changeLeft })
2194
+ vue.createVNode(_sfc_main$u, { onChange: changeLeft })
1594
2195
  ], 64)) : vue.createCommentVNode("", true),
1595
2196
  vue.createElementVNode("div", {
1596
2197
  class: vue.normalizeClass(["m-editor-layout-center", _ctx.centerClass]),
@@ -1599,7 +2200,7 @@
1599
2200
  vue.renderSlot(_ctx.$slots, "center")
1600
2201
  ], 6),
1601
2202
  hasRight.value && _ctx.$slots.right ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 1 }, [
1602
- vue.createVNode(_sfc_main$v, { onChange: changeRight }),
2203
+ vue.createVNode(_sfc_main$u, { onChange: changeRight }),
1603
2204
  vue.createElementVNode("div", {
1604
2205
  class: vue.normalizeClass(["m-editor-layout-right", _ctx.rightClass]),
1605
2206
  style: vue.normalizeStyle(`width: ${_ctx.right}px`)
@@ -3522,10 +4123,10 @@
3522
4123
  return stage;
3523
4124
  };
3524
4125
 
3525
- const _hoisted_1$j = { class: "m-editor-empty-panel" };
3526
- const _hoisted_2$a = { class: "m-editor-empty-content" };
3527
- const _hoisted_3$5 = /* @__PURE__ */ vue.createElementVNode("p", null, "新增页面", -1);
3528
- const _sfc_main$t = /* @__PURE__ */ vue.defineComponent({
4126
+ const _hoisted_1$h = { class: "m-editor-empty-panel" };
4127
+ const _hoisted_2$8 = { class: "m-editor-empty-content" };
4128
+ const _hoisted_3$4 = /* @__PURE__ */ vue.createElementVNode("p", null, "新增页面", -1);
4129
+ const _sfc_main$s = /* @__PURE__ */ vue.defineComponent({
3529
4130
  ...{
3530
4131
  name: "MEditorAddPageBox"
3531
4132
  },
@@ -3545,8 +4146,8 @@
3545
4146
  });
3546
4147
  };
3547
4148
  return (_ctx, _cache) => {
3548
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$j, [
3549
- vue.createElementVNode("div", _hoisted_2$a, [
4149
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$h, [
4150
+ vue.createElementVNode("div", _hoisted_2$8, [
3550
4151
  vue.createElementVNode("div", {
3551
4152
  class: "m-editor-empty-button",
3552
4153
  onClick: clickHandler
@@ -3554,7 +4155,7 @@
3554
4155
  vue.createElementVNode("div", null, [
3555
4156
  vue.createVNode(_sfc_main$E, { icon: vue.unref(iconsVue.Plus) }, null, 8, ["icon"])
3556
4157
  ]),
3557
- _hoisted_3$5
4158
+ _hoisted_3$4
3558
4159
  ])
3559
4160
  ])
3560
4161
  ]);
@@ -3562,12 +4163,11 @@
3562
4163
  }
3563
4164
  });
3564
4165
 
3565
- const _hoisted_1$i = { class: "m-editor" };
3566
4166
  const DEFAULT_LEFT_COLUMN_WIDTH = 310;
3567
4167
  const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
3568
4168
  const LEFT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorLeftColumnWidthData";
3569
4169
  const RIGHT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorRightColumnWidthData";
3570
- const _sfc_main$s = /* @__PURE__ */ vue.defineComponent({
4170
+ const _sfc_main$r = /* @__PURE__ */ vue.defineComponent({
3571
4171
  ...{
3572
4172
  name: "MEditorFramework"
3573
4173
  },
@@ -3575,6 +4175,7 @@
3575
4175
  setup(__props) {
3576
4176
  const codeOptions = vue.inject("codeOptions", {});
3577
4177
  const { editorService, uiService } = vue.inject("services") || {};
4178
+ const content = vue.ref();
3578
4179
  const root = vue.computed(() => editorService?.get("root"));
3579
4180
  const pageLength = vue.computed(() => editorService?.get("pageLength") || 0);
3580
4181
  const showSrc = vue.computed(() => uiService?.get("showSrc"));
@@ -3590,13 +4191,14 @@
3590
4191
  (length) => {
3591
4192
  const left = columnWidth.value.left || DEFAULT_LEFT_COLUMN_WIDTH;
3592
4193
  columnWidth.value.left = left;
4194
+ const container = content.value || document.body;
3593
4195
  if (length <= 0) {
3594
4196
  columnWidth.value.right = void 0;
3595
- columnWidth.value.center = globalThis.document.body.clientWidth - left;
4197
+ columnWidth.value.center = container.clientWidth - left;
3596
4198
  } else {
3597
4199
  const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
3598
4200
  columnWidth.value.right = right;
3599
- columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
4201
+ columnWidth.value.center = container.clientWidth - left - right;
3600
4202
  }
3601
4203
  uiService?.set("columnWidth", columnWidth.value);
3602
4204
  },
@@ -3633,18 +4235,22 @@
3633
4235
  }
3634
4236
  };
3635
4237
  return (_ctx, _cache) => {
3636
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$i, [
4238
+ return vue.openBlock(), vue.createElementBlock("div", {
4239
+ class: "m-editor",
4240
+ ref_key: "content",
4241
+ ref: content
4242
+ }, [
3637
4243
  vue.renderSlot(_ctx.$slots, "header"),
3638
4244
  vue.renderSlot(_ctx.$slots, "nav"),
3639
4245
  vue.renderSlot(_ctx.$slots, "content-before"),
3640
4246
  showSrc.value ? vue.renderSlot(_ctx.$slots, "src-code", { key: 0 }, () => [
3641
- vue.createVNode(_sfc_main$w, {
4247
+ vue.createVNode(_sfc_main$K, {
3642
4248
  class: "m-editor-content",
3643
4249
  "init-values": root.value,
3644
4250
  options: vue.unref(codeOptions),
3645
4251
  onSave: saveCode
3646
4252
  }, null, 8, ["init-values", "options"])
3647
- ]) : (vue.openBlock(), vue.createBlock(_sfc_main$u, {
4253
+ ]) : (vue.openBlock(), vue.createBlock(_sfc_main$t, {
3648
4254
  key: 1,
3649
4255
  class: "m-editor-content",
3650
4256
  "left-class": "m-editor-framework-left",
@@ -3663,7 +4269,7 @@
3663
4269
  ]),
3664
4270
  center: vue.withCtx(() => [
3665
4271
  pageLength.value > 0 ? vue.renderSlot(_ctx.$slots, "workspace", { key: 0 }) : vue.renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
3666
- vue.createVNode(_sfc_main$t)
4272
+ vue.createVNode(_sfc_main$s)
3667
4273
  ])
3668
4274
  ]),
3669
4275
  _: 2
@@ -3683,17 +4289,17 @@
3683
4289
  ]), 1032, ["left", "right"])),
3684
4290
  vue.renderSlot(_ctx.$slots, "content-after"),
3685
4291
  vue.renderSlot(_ctx.$slots, "footer")
3686
- ]);
4292
+ ], 512);
3687
4293
  };
3688
4294
  }
3689
4295
  });
3690
4296
 
3691
- const _hoisted_1$h = {
4297
+ const _hoisted_1$g = {
3692
4298
  key: 1,
3693
4299
  class: "menu-item-text"
3694
4300
  };
3695
- const _hoisted_2$9 = { class: "el-dropdown-link menubar-menu-button" };
3696
- const _sfc_main$r = /* @__PURE__ */ vue.defineComponent({
4301
+ const _hoisted_2$7 = { class: "el-dropdown-link menubar-menu-button" };
4302
+ const _sfc_main$q = /* @__PURE__ */ vue.defineComponent({
3697
4303
  ...{
3698
4304
  name: "MEditorToolButton"
3699
4305
  },
@@ -3772,7 +4378,7 @@
3772
4378
  _ctx.data.type === "divider" ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicDivider), {
3773
4379
  key: 0,
3774
4380
  direction: _ctx.data.direction || "vertical"
3775
- }, null, 8, ["direction"])) : _ctx.data.type === "text" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$h, vue.toDisplayString(_ctx.data.text), 1)) : _ctx.data.type === "button" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 2 }, [
4381
+ }, null, 8, ["direction"])) : _ctx.data.type === "text" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$g, vue.toDisplayString(_ctx.data.text), 1)) : _ctx.data.type === "button" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 2 }, [
3776
4382
  _ctx.data.tooltip ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTooltip), {
3777
4383
  key: 0,
3778
4384
  effect: "dark",
@@ -3836,7 +4442,7 @@
3836
4442
  })) : vue.createCommentVNode("", true)
3837
4443
  ]),
3838
4444
  default: vue.withCtx(() => [
3839
- vue.createElementVNode("span", _hoisted_2$9, [
4445
+ vue.createElementVNode("span", _hoisted_2$7, [
3840
4446
  vue.createTextVNode(vue.toDisplayString(_ctx.data.text), 1),
3841
4447
  vue.createVNode(vue.unref(design.TMagicIcon), { class: "el-icon--right" }, {
3842
4448
  default: vue.withCtx(() => [
@@ -3853,7 +4459,7 @@
3853
4459
  }
3854
4460
  });
3855
4461
 
3856
- const _sfc_main$q = /* @__PURE__ */ vue.defineComponent({
4462
+ const _sfc_main$p = /* @__PURE__ */ vue.defineComponent({
3857
4463
  ...{
3858
4464
  name: "MEditorNavMenu"
3859
4465
  },
@@ -4015,7 +4621,7 @@
4015
4621
  style: vue.normalizeStyle(`width: ${columnWidth.value?.[key]}px`)
4016
4622
  }, [
4017
4623
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(buttons.value[key], (item, index) => {
4018
- return vue.openBlock(), vue.createBlock(_sfc_main$r, {
4624
+ return vue.openBlock(), vue.createBlock(_sfc_main$q, {
4019
4625
  data: item,
4020
4626
  key: index
4021
4627
  }, null, 8, ["data"]);
@@ -4027,8 +4633,8 @@
4027
4633
  }
4028
4634
  });
4029
4635
 
4030
- const _hoisted_1$g = { class: "m-editor-props-panel" };
4031
- const _sfc_main$p = /* @__PURE__ */ vue.defineComponent({
4636
+ const _hoisted_1$f = { class: "m-editor-props-panel" };
4637
+ const _sfc_main$o = /* @__PURE__ */ vue.defineComponent({
4032
4638
  ...{
4033
4639
  name: "MEditorPropsPanel"
4034
4640
  },
@@ -4081,7 +4687,7 @@
4081
4687
  };
4082
4688
  __expose({ configForm, submit });
4083
4689
  return (_ctx, _cache) => {
4084
- return vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", _hoisted_1$g, [
4690
+ return vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", _hoisted_1$f, [
4085
4691
  vue.renderSlot(_ctx.$slots, "props-panel-header"),
4086
4692
  vue.createVNode(vue.unref(form.MForm), {
4087
4693
  ref_key: "configForm",
@@ -4101,7 +4707,7 @@
4101
4707
  }
4102
4708
  });
4103
4709
 
4104
- const _sfc_main$o = /* @__PURE__ */ vue.defineComponent({
4710
+ const _sfc_main$n = /* @__PURE__ */ vue.defineComponent({
4105
4711
  ...{
4106
4712
  name: "MEditorSearchInput"
4107
4713
  },
@@ -4136,8 +4742,8 @@
4136
4742
  }
4137
4743
  });
4138
4744
 
4139
- const _hoisted_1$f = { xmlns: "http://www.w3.org/2000/svg" };
4140
- const _hoisted_2$8 = /* @__PURE__ */ vue.createElementVNode("g", {
4745
+ const _hoisted_1$e = { xmlns: "http://www.w3.org/2000/svg" };
4746
+ const _hoisted_2$6 = /* @__PURE__ */ vue.createElementVNode("g", {
4141
4747
  fill: "#7C878E",
4142
4748
  "fill-rule": "evenodd"
4143
4749
  }, [
@@ -4147,488 +4753,60 @@
4147
4753
  }),
4148
4754
  /* @__PURE__ */ vue.createElementVNode("path", { d: "M8 13.5L2.3 9.2 0.7 10.5 8 16 15.3 10.5 13.7 9.2z" })
4149
4755
  ], -1);
4150
- const _hoisted_3$4 = [
4151
- _hoisted_2$8
4756
+ const _hoisted_3$3 = [
4757
+ _hoisted_2$6
4152
4758
  ];
4153
- const _sfc_main$n = /* @__PURE__ */ vue.defineComponent({
4759
+ const _sfc_main$m = /* @__PURE__ */ vue.defineComponent({
4154
4760
  ...{
4155
4761
  name: "MEditorAppManageIcon"
4156
4762
  },
4157
4763
  __name: "AppManageIcon",
4158
4764
  setup(__props) {
4159
4765
  return (_ctx, _cache) => {
4160
- return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1$f, _hoisted_3$4);
4766
+ return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1$e, _hoisted_3$3);
4161
4767
  };
4162
4768
  }
4163
4769
  });
4164
4770
 
4165
- const _hoisted_1$e = {
4771
+ const _hoisted_1$d = {
4166
4772
  viewBox: "0 0 32 32",
4167
4773
  version: "1.1",
4168
4774
  xmlns: "http://www.w3.org/2000/svg",
4169
4775
  "xmlns:xlink": "http://www.w3.org/1999/xlink"
4170
4776
  };
4171
- const _hoisted_2$7 = /* @__PURE__ */ vue.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);
4172
- const _hoisted_4$4 = [
4173
- _hoisted_2$7
4777
+ const _hoisted_2$5 = /* @__PURE__ */ vue.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);
4778
+ const _hoisted_4$1 = [
4779
+ _hoisted_2$5
4174
4780
  ];
4175
- const _sfc_main$m = /* @__PURE__ */ vue.defineComponent({
4781
+ const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
4176
4782
  ...{
4177
4783
  name: "MEditorCodeIcon"
4178
4784
  },
4179
4785
  __name: "CodeIcon",
4180
4786
  setup(__props) {
4181
4787
  return (_ctx, _cache) => {
4182
- return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1$e, _hoisted_4$4);
4183
- };
4184
- }
4185
- });
4186
-
4187
- const _hoisted_1$d = {
4188
- key: 0,
4189
- class: "m-editor-content-bottom"
4190
- };
4191
- const _hoisted_2$6 = {
4192
- key: 1,
4193
- class: "m-editor-content-bottom"
4194
- };
4195
- const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
4196
- ...{
4197
- name: "MEditorCodeDraftEditor"
4198
- },
4199
- __name: "CodeDraftEditor",
4200
- props: {
4201
- id: {},
4202
- content: {},
4203
- editable: { type: Boolean, default: true },
4204
- autoSaveDraft: { type: Boolean, default: true },
4205
- codeOptions: {},
4206
- language: {}
4207
- },
4208
- emits: ["close", "saveAndClose"],
4209
- setup(__props, { expose: __expose, emit }) {
4210
- const props = __props;
4211
- const services = vue.inject("services");
4212
- const codeContent = vue.ref("");
4213
- const editorContent = vue.ref("");
4214
- const codeEditor = vue.ref();
4215
- const originCodeContent = vue.ref("");
4216
- const isFullScreen = vue.ref(false);
4217
- const codeOptions = vue.computed(() => ({
4218
- ...props.codeOptions,
4219
- readOnly: !props.editable
4220
- }));
4221
- vue.watchEffect(() => {
4222
- codeContent.value = props.content;
4223
- if (!originCodeContent.value) {
4224
- originCodeContent.value = codeContent.value;
4225
- }
4226
- const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
4227
- if (codeDraft) {
4228
- codeContent.value = codeDraft;
4229
- }
4230
- });
4231
- const saveCodeDraft = async (codeValue) => {
4232
- if (!props.autoSaveDraft)
4233
- return;
4234
- if (originCodeContent.value === codeValue) {
4235
- services?.codeBlockService.removeCodeDraft(props.id);
4236
- return;
4237
- }
4238
- services?.codeBlockService.setCodeDraft(props.id, codeValue);
4239
- design.tMagicMessage.success(`代码草稿成功保存到本地 ${utils.datetimeFormatter( new Date())}`);
4240
- };
4241
- const saveAndClose = () => {
4242
- if (!codeEditor.value || !props.editable)
4243
- return;
4244
- editorContent.value = codeEditor.value.getEditor()?.getValue();
4245
- emit("saveAndClose", editorContent.value);
4246
- };
4247
- const close = async () => {
4248
- const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
4249
- if (codeDraft) {
4250
- try {
4251
- await design.tMagicMessageBox.confirm("您有代码修改未保存,是否保存后再关闭?", "提示", {
4252
- confirmButtonText: "保存并关闭",
4253
- cancelButtonText: "直接关闭",
4254
- type: "warning",
4255
- distinguishCancelAndClose: true
4256
- });
4257
- saveAndClose();
4258
- } catch (action) {
4259
- if (action === "cancel") {
4260
- services?.codeBlockService.removeCodeDraft(props.id);
4261
- emit("close");
4262
- }
4263
- }
4264
- } else {
4265
- emit("close");
4266
- }
4267
- };
4268
- const toggleFullScreen = () => {
4269
- isFullScreen.value = !isFullScreen.value;
4270
- if (codeEditor.value) {
4271
- codeEditor.value.focus();
4272
- }
4273
- };
4274
- __expose({
4275
- saveAndClose,
4276
- close
4277
- });
4278
- return (_ctx, _cache) => {
4279
- return vue.openBlock(), vue.createElementBlock("div", {
4280
- class: vue.normalizeClass(["m-editor-wrapper", isFullScreen.value ? "fullScreen" : "normal"])
4281
- }, [
4282
- vue.createVNode(_sfc_main$w, {
4283
- ref_key: "codeEditor",
4284
- ref: codeEditor,
4285
- class: "m-editor-container",
4286
- "init-values": `${codeContent.value}`,
4287
- onSave: saveCodeDraft,
4288
- language: _ctx.language,
4289
- options: codeOptions.value
4290
- }, null, 8, ["init-values", "language", "options"]),
4291
- _ctx.editable ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$d, [
4292
- vue.createVNode(vue.unref(design.TMagicButton), {
4293
- type: "primary",
4294
- class: "button",
4295
- onClick: toggleFullScreen
4296
- }, {
4297
- default: vue.withCtx(() => [
4298
- vue.createTextVNode(vue.toDisplayString(isFullScreen.value ? "退出全屏" : "全屏"), 1)
4299
- ]),
4300
- _: 1
4301
- }),
4302
- vue.createVNode(vue.unref(design.TMagicButton), {
4303
- type: "primary",
4304
- class: "button",
4305
- onClick: saveAndClose
4306
- }, {
4307
- default: vue.withCtx(() => [
4308
- vue.createTextVNode("确认")
4309
- ]),
4310
- _: 1
4311
- }),
4312
- vue.createVNode(vue.unref(design.TMagicButton), {
4313
- class: "button",
4314
- onClick: close
4315
- }, {
4316
- default: vue.withCtx(() => [
4317
- vue.createTextVNode("关闭")
4318
- ]),
4319
- _: 1
4320
- })
4321
- ])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$6, [
4322
- vue.createVNode(vue.unref(design.TMagicButton), {
4323
- type: "primary",
4324
- class: "button",
4325
- onClick: toggleFullScreen
4326
- }, {
4327
- default: vue.withCtx(() => [
4328
- vue.createTextVNode(vue.toDisplayString(isFullScreen.value ? "退出全屏" : "全屏"), 1)
4329
- ]),
4330
- _: 1
4331
- }),
4332
- vue.createVNode(vue.unref(design.TMagicButton), {
4333
- class: "button",
4334
- onClick: close
4335
- }, {
4336
- default: vue.withCtx(() => [
4337
- vue.createTextVNode("关闭")
4338
- ]),
4339
- _: 1
4340
- })
4341
- ]))
4342
- ], 2);
4343
- };
4344
- }
4345
- });
4346
-
4347
- const _hoisted_1$c = { class: "code-name-wrapper" };
4348
- const _hoisted_2$5 = /* @__PURE__ */ vue.createElementVNode("div", { class: "code-name-label" }, "代码块名称", -1);
4349
- const _hoisted_3$3 = { class: "code-name-wrapper" };
4350
- const _hoisted_4$3 = /* @__PURE__ */ vue.createElementVNode("div", { class: "code-name-label" }, "参数", -1);
4351
- const _sfc_main$k = /* @__PURE__ */ vue.defineComponent({
4352
- ...{
4353
- name: "MEditorFunctionEditor"
4354
- },
4355
- __name: "FunctionEditor",
4356
- props: {
4357
- id: {},
4358
- name: {},
4359
- content: {},
4360
- editable: { type: Boolean, default: true },
4361
- autoSaveDraft: { type: Boolean, default: true },
4362
- codeOptions: {},
4363
- paramsColConfig: {}
4364
- },
4365
- setup(__props, { expose: __expose }) {
4366
- const props = __props;
4367
- vue.provide("mForm", null);
4368
- const defaultParamColConfig = {
4369
- type: "row",
4370
- label: "参数类型",
4371
- items: [
4372
- {
4373
- text: "参数类型",
4374
- labelWidth: "70px",
4375
- type: "select",
4376
- name: "type",
4377
- options: [
4378
- {
4379
- text: "数字",
4380
- label: "数字",
4381
- value: "number"
4382
- },
4383
- {
4384
- text: "字符串",
4385
- label: "字符串",
4386
- value: "text"
4387
- }
4388
- ]
4389
- }
4390
- ]
4391
- };
4392
- const paramsColConfig = props.paramsColConfig || defaultParamColConfig;
4393
- const tableConfig = {
4394
- type: "table",
4395
- border: true,
4396
- enableFullscreen: false,
4397
- name: "params",
4398
- maxHeight: "300px",
4399
- dropSort: false,
4400
- items: [
4401
- {
4402
- type: "text",
4403
- label: "参数名",
4404
- name: "name",
4405
- width: 200
4406
- },
4407
- {
4408
- type: "text",
4409
- label: "参数注释",
4410
- name: "tip",
4411
- width: 200
4412
- },
4413
- paramsColConfig
4414
- ]
4415
- };
4416
- const services = vue.inject("services");
4417
- const codeName = vue.ref("");
4418
- const codeContent = vue.ref("");
4419
- const evalRes = vue.ref(true);
4420
- const tableModel = vue.ref();
4421
- vue.watchEffect(() => {
4422
- codeName.value = props.name;
4423
- codeContent.value = props.content;
4424
- });
4425
- const initTableModel = () => {
4426
- const codeDsl = lodashEs.cloneDeep(services?.codeBlockService.getCodeDsl());
4427
- if (!codeDsl)
4428
- return;
4429
- tableModel.value = {
4430
- params: codeDsl[props.id]?.params || []
4431
- };
4432
- };
4433
- initTableModel();
4434
- const beforeSave = (codeValue) => {
4435
- try {
4436
- getConfig("parseDSL")(codeValue);
4437
- return true;
4438
- } catch (e) {
4439
- design.tMagicMessage.error(e.stack);
4440
- return false;
4441
- }
4442
- };
4443
- const saveCode = async (codeValue) => {
4444
- if (!props.editable)
4445
- return;
4446
- evalRes.value = beforeSave(codeValue);
4447
- if (evalRes.value) {
4448
- await services?.codeBlockService.setCodeDslById(props.id, {
4449
- name: codeName.value,
4450
- content: codeValue,
4451
- params: tableModel.value?.params || []
4452
- });
4453
- design.tMagicMessage.success("代码成功保存到本地");
4454
- services?.codeBlockService.removeCodeDraft(props.id);
4455
- }
4456
- };
4457
- const saveAndClose = async (codeValue) => {
4458
- await saveCode(codeValue);
4459
- if (evalRes.value) {
4460
- close();
4461
- }
4462
- };
4463
- const close = () => {
4464
- services?.codeBlockService.setCodeEditorShowStatus(false);
4465
- };
4466
- const codeDraftEditor = vue.ref();
4467
- __expose({
4468
- codeDraftEditor
4469
- });
4470
- return (_ctx, _cache) => {
4471
- const _component_m_form_table = vue.resolveComponent("m-form-table");
4472
- return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicCard), { shadow: "never" }, {
4473
- header: vue.withCtx(() => [
4474
- vue.createElementVNode("div", _hoisted_1$c, [
4475
- _hoisted_2$5,
4476
- vue.createVNode(vue.unref(design.TMagicInput), {
4477
- class: "code-name-input",
4478
- modelValue: codeName.value,
4479
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeName.value = $event),
4480
- disabled: !_ctx.editable
4481
- }, null, 8, ["modelValue", "disabled"])
4482
- ]),
4483
- vue.createElementVNode("div", _hoisted_3$3, [
4484
- _hoisted_4$3,
4485
- vue.createVNode(_component_m_form_table, {
4486
- style: { "width": "800px" },
4487
- config: tableConfig,
4488
- model: tableModel.value,
4489
- enableToggleMode: false,
4490
- name: "params",
4491
- prop: "params",
4492
- size: "small"
4493
- }, null, 8, ["model"])
4494
- ])
4495
- ]),
4496
- default: vue.withCtx(() => [
4497
- vue.createVNode(_sfc_main$l, {
4498
- ref_key: "codeDraftEditor",
4499
- ref: codeDraftEditor,
4500
- id: _ctx.id,
4501
- content: codeContent.value,
4502
- editable: _ctx.editable,
4503
- autoSaveDraft: _ctx.autoSaveDraft,
4504
- codeOptions: _ctx.codeOptions,
4505
- language: "javascript",
4506
- onSaveAndClose: saveAndClose,
4507
- onClose: close
4508
- }, null, 8, ["id", "content", "editable", "autoSaveDraft", "codeOptions"])
4509
- ]),
4510
- _: 1
4511
- });
4512
- };
4513
- }
4514
- });
4515
-
4516
- const _hoisted_1$b = {
4517
- key: 0,
4518
- class: "m-editor-code-block-editor-panel"
4519
- };
4520
- const _sfc_main$j = /* @__PURE__ */ vue.defineComponent({
4521
- ...{
4522
- name: "MEditorCodeBlockEditor"
4523
- },
4524
- __name: "CodeBlockEditor",
4525
- props: {
4526
- paramsColConfig: {}
4527
- },
4528
- setup(__props) {
4529
- const services = vue.inject("services");
4530
- const codeOptions = vue.inject("codeOptions", {});
4531
- const size = vue.computed(() => globalThis.document.body.clientWidth - (services?.uiService.get("columnWidth").left || 0));
4532
- const left = vue.ref(200);
4533
- const currentTitle = vue.ref("");
4534
- const codeConfig = vue.ref(null);
4535
- const state = vue.reactive({
4536
- codeList: []
4537
- });
4538
- const id = vue.computed(() => services?.codeBlockService.getId() || "");
4539
- const editable = vue.computed(() => services?.codeBlockService.getEditStatus());
4540
- const selectedIds = vue.computed(() => services?.codeBlockService.getCombineIds() || []);
4541
- vue.watchEffect(async () => {
4542
- codeConfig.value = lodashEs.cloneDeep(await services?.codeBlockService.getCodeContentById(id.value)) || null;
4543
- if (!codeConfig.value)
4544
- return;
4545
- codeConfig.value.content = serializeConfig(codeConfig.value.content);
4546
- });
4547
- vue.watchEffect(async () => {
4548
- const codeDsl = await services?.codeBlockService.getCodeDslByIds(selectedIds.value) || null;
4549
- if (!codeDsl)
4550
- return;
4551
- state.codeList = [];
4552
- lodashEs.forIn(codeDsl, (value, key) => {
4553
- state.codeList.push({
4554
- id: key,
4555
- name: value.name
4556
- });
4557
- });
4558
- currentTitle.value = state.codeList[0]?.name || "";
4559
- });
4560
- const functionEditor = vue.ref();
4561
- const handleClose = async () => {
4562
- await functionEditor.value?.codeDraftEditor?.close();
4563
- };
4564
- return (_ctx, _cache) => {
4565
- return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicDrawer), {
4566
- class: "code-editor-dialog",
4567
- "model-value": true,
4568
- title: currentTitle.value,
4569
- "close-on-press-escape": true,
4570
- "append-to-body": true,
4571
- "show-close": false,
4572
- "close-on-click-modal": true,
4573
- size: size.value,
4574
- "before-close": handleClose
4575
- }, {
4576
- default: vue.withCtx(() => [
4577
- vue.createVNode(_sfc_main$u, {
4578
- left: left.value,
4579
- "onUpdate:left": _cache[0] || (_cache[0] = ($event) => left.value = $event),
4580
- "min-left": 45,
4581
- class: "code-editor-layout"
4582
- }, {
4583
- center: vue.withCtx(() => [
4584
- !vue.unref(lodashEs.isEmpty)(codeConfig.value) ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$b, [
4585
- vue.renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id: id.value }),
4586
- codeConfig.value ? (vue.openBlock(), vue.createBlock(_sfc_main$k, {
4587
- key: 0,
4588
- ref_key: "functionEditor",
4589
- ref: functionEditor,
4590
- id: id.value,
4591
- name: codeConfig.value.name,
4592
- content: codeConfig.value.content,
4593
- paramsColConfig: _ctx.paramsColConfig,
4594
- editable: !!editable.value,
4595
- autoSaveDraft: true,
4596
- codeOptions: vue.unref(codeOptions)
4597
- }, null, 8, ["id", "name", "content", "paramsColConfig", "editable", "codeOptions"])) : vue.createCommentVNode("", true)
4598
- ])) : vue.createCommentVNode("", true)
4599
- ]),
4600
- _: 3
4601
- }, 8, ["left"])
4602
- ]),
4603
- _: 3
4604
- }, 8, ["title", "size"]);
4788
+ return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1$d, _hoisted_4$1);
4605
4789
  };
4606
4790
  }
4607
4791
  });
4608
4792
 
4609
- const _hoisted_1$a = { class: "search-wrapper" };
4610
- const _hoisted_2$4 = ["id"];
4611
- const _hoisted_3$2 = { class: "list-item" };
4612
- const _hoisted_4$2 = {
4793
+ const _hoisted_1$c = ["id"];
4794
+ const _hoisted_2$4 = { class: "list-item" };
4795
+ const _hoisted_3$2 = {
4613
4796
  key: 2,
4614
4797
  class: "right-tool"
4615
4798
  };
4616
- const _sfc_main$i = /* @__PURE__ */ vue.defineComponent({
4799
+ const _sfc_main$k = /* @__PURE__ */ vue.defineComponent({
4617
4800
  ...{
4618
4801
  name: "MEditorCodeBlockList"
4619
4802
  },
4620
4803
  __name: "CodeBlockList",
4621
4804
  props: {
4622
- customError: { type: Function },
4623
- paramsColConfig: {}
4805
+ customError: { type: Function }
4624
4806
  },
4625
- setup(__props) {
4807
+ emits: ["edit", "remove"],
4808
+ setup(__props, { expose: __expose, emit }) {
4626
4809
  const props = __props;
4627
- const treeProps = {
4628
- children: "children",
4629
- label: "name",
4630
- value: "id"
4631
- };
4632
4810
  const { codeBlockService, depService, editorService } = vue.inject("services") || {};
4633
4811
  const codeList = vue.computed(
4634
4812
  () => Object.values(depService?.targets["code-block"] || {}).map((target) => {
@@ -4645,54 +4823,16 @@
4645
4823
  codeBlockContent: codeBlockService?.getCodeContentById(target.id),
4646
4824
  children: compNodes
4647
4825
  };
4648
- })
4649
- );
4650
- const expandedKeys = vue.computed(() => codeList.value.map((item) => item.id));
4651
- const editable = vue.computed(() => codeBlockService?.getEditStatus());
4652
- const isShowCodeBlockEditor = vue.computed(() => codeBlockService?.getCodeEditorShowStatus() || false);
4653
- const createCodeBlock = async () => {
4654
- if (!codeBlockService) {
4655
- design.tMagicMessage.error("新增代码块失败");
4656
- return;
4657
- }
4658
- const codeConfig = {
4659
- name: "代码块",
4660
- content: `({app, params}) => {
4661
- // place your code here
4662
- }`,
4663
- params: []
4664
- };
4665
- const id = await codeBlockService.getUniqueId();
4666
- await codeBlockService.setCodeDslById(id, codeConfig);
4667
- codeBlockService.setCodeEditorContent(true, id);
4668
- };
4669
- const editCode = async (key) => {
4670
- codeBlockService?.setCodeEditorContent(true, key);
4671
- };
4672
- const deleteCode = (key) => {
4673
- const currentCode = codeList.value.find((codeItem) => codeItem.id === key);
4674
- const existBinds = Boolean(currentCode?.children.length);
4675
- const undeleteableList = codeBlockService?.getUndeletableList() || [];
4676
- if (!existBinds && !undeleteableList.includes(key)) {
4677
- codeBlockService?.deleteCodeDslByIds([key]);
4678
- } else {
4679
- if (typeof props.customError === "function") {
4680
- props.customError(key, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
4681
- } else {
4682
- design.tMagicMessage.error("代码块删除失败");
4683
- }
4684
- }
4685
- };
4686
- const tree = vue.ref();
4826
+ })
4827
+ );
4828
+ const expandedKeys = vue.computed(() => codeList.value.map((item) => item.id));
4829
+ const editable = vue.computed(() => codeBlockService?.getEditStatus());
4687
4830
  const filterNode = (value, data) => {
4688
4831
  if (!value) {
4689
4832
  return true;
4690
4833
  }
4691
4834
  return `${data.name}${data.id}`.toLocaleLowerCase().indexOf(value.toLocaleLowerCase()) !== -1;
4692
4835
  };
4693
- const filterTextChangeHandler = (val) => {
4694
- tree.value?.filter(val);
4695
- };
4696
4836
  const selectComp = (compId) => {
4697
4837
  const stage = editorService?.get("stage");
4698
4838
  editorService?.select(compId);
@@ -4705,106 +4845,166 @@
4705
4845
  selectComp(node.parent.data.id);
4706
4846
  }
4707
4847
  };
4848
+ const editCode = (id) => {
4849
+ emit("edit", id);
4850
+ };
4851
+ const deleteCode = async (id) => {
4852
+ const currentCode = codeList.value.find((codeItem) => codeItem.id === id);
4853
+ const existBinds = Boolean(currentCode?.children.length);
4854
+ const undeleteableList = codeBlockService?.getUndeletableList() || [];
4855
+ if (!existBinds && !undeleteableList.includes(id)) {
4856
+ await design.tMagicMessageBox.confirm("确定删除该代码块吗?", "提示", {
4857
+ confirmButtonText: "确定",
4858
+ cancelButtonText: "取消",
4859
+ type: "warning"
4860
+ });
4861
+ emit("remove", id);
4862
+ } else {
4863
+ if (typeof props.customError === "function") {
4864
+ props.customError(id, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
4865
+ } else {
4866
+ design.tMagicMessage.error("代码块删除失败");
4867
+ }
4868
+ }
4869
+ };
4870
+ const tree = vue.ref();
4871
+ __expose({
4872
+ filter(val) {
4873
+ tree.value?.filter(val);
4874
+ }
4875
+ });
4876
+ return (_ctx, _cache) => {
4877
+ return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTree), {
4878
+ ref_key: "tree",
4879
+ ref: tree,
4880
+ class: "magic-editor-layer-tree",
4881
+ "node-key": "id",
4882
+ "empty-text": "暂无代码块",
4883
+ "default-expanded-keys": expandedKeys.value,
4884
+ "expand-on-click-node": false,
4885
+ data: codeList.value,
4886
+ props: {
4887
+ children: "children",
4888
+ label: "name",
4889
+ value: "id"
4890
+ },
4891
+ "highlight-current": true,
4892
+ "filter-node-method": filterNode,
4893
+ onNodeClick: clickHandler
4894
+ }, {
4895
+ default: vue.withCtx(({ data }) => [
4896
+ vue.createElementVNode("div", {
4897
+ id: data.id,
4898
+ class: "list-container"
4899
+ }, [
4900
+ vue.createElementVNode("div", _hoisted_2$4, [
4901
+ data.type === "code" ? (vue.openBlock(), vue.createBlock(_sfc_main$l, {
4902
+ key: 0,
4903
+ class: "codeIcon"
4904
+ })) : vue.createCommentVNode("", true),
4905
+ data.type === "node" ? (vue.openBlock(), vue.createBlock(_sfc_main$m, {
4906
+ key: 1,
4907
+ class: "compIcon"
4908
+ })) : vue.createCommentVNode("", true),
4909
+ vue.createElementVNode("span", {
4910
+ class: vue.normalizeClass(["name", { code: data.type === "code", hook: data.type === "key" }])
4911
+ }, vue.toDisplayString(data.name) + " (" + vue.toDisplayString(data.id) + ")", 3),
4912
+ data.type === "code" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3$2, [
4913
+ vue.createVNode(vue.unref(design.TMagicTooltip), {
4914
+ effect: "dark",
4915
+ content: editable.value ? "编辑" : "查看",
4916
+ placement: "bottom"
4917
+ }, {
4918
+ default: vue.withCtx(() => [
4919
+ vue.createVNode(_sfc_main$E, {
4920
+ icon: editable.value ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
4921
+ class: "edit-icon",
4922
+ onClick: vue.withModifiers(($event) => editCode(data.id), ["stop"])
4923
+ }, null, 8, ["icon", "onClick"])
4924
+ ]),
4925
+ _: 2
4926
+ }, 1032, ["content"]),
4927
+ editable.value ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTooltip), {
4928
+ key: 0,
4929
+ effect: "dark",
4930
+ content: "删除",
4931
+ placement: "bottom"
4932
+ }, {
4933
+ default: vue.withCtx(() => [
4934
+ vue.createVNode(_sfc_main$E, {
4935
+ icon: vue.unref(iconsVue.Close),
4936
+ class: "edit-icon",
4937
+ onClick: vue.withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
4938
+ }, null, 8, ["icon", "onClick"])
4939
+ ]),
4940
+ _: 2
4941
+ }, 1024)) : vue.createCommentVNode("", true),
4942
+ vue.renderSlot(_ctx.$slots, "code-block-panel-tool", {
4943
+ id: data.id,
4944
+ data: data.codeBlockContent
4945
+ })
4946
+ ])) : vue.createCommentVNode("", true)
4947
+ ])
4948
+ ], 8, _hoisted_1$c)
4949
+ ]),
4950
+ _: 3
4951
+ }, 8, ["default-expanded-keys", "data"]);
4952
+ };
4953
+ }
4954
+ });
4955
+
4956
+ const _hoisted_1$b = { class: "search-wrapper" };
4957
+ const _sfc_main$j = /* @__PURE__ */ vue.defineComponent({
4958
+ ...{
4959
+ name: "MEditorCodeBlockListPanel"
4960
+ },
4961
+ __name: "CodeBlockListPanel",
4962
+ props: {
4963
+ customError: { type: Function }
4964
+ },
4965
+ setup(__props) {
4966
+ const { codeBlockService } = vue.inject("services") || {};
4967
+ const editable = vue.computed(() => codeBlockService?.getEditStatus());
4968
+ const { codeBlockEditor, codeConfig, editCode, deleteCode, createCodeBlock, submitCodeBlockHandler } = useCodeBlockEdit(codeBlockService);
4969
+ const codeBlockList = vue.ref();
4970
+ const filterTextChangeHandler = (val) => {
4971
+ codeBlockList.value?.filter(val);
4972
+ };
4708
4973
  return (_ctx, _cache) => {
4709
4974
  return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicScrollbar), { class: "m-editor-code-block-list m-editor-dep-list-panel" }, {
4710
4975
  default: vue.withCtx(() => [
4711
4976
  vue.renderSlot(_ctx.$slots, "code-block-panel-header", {}, () => [
4712
- vue.createElementVNode("div", _hoisted_1$a, [
4713
- vue.createVNode(_sfc_main$o, { onSearch: filterTextChangeHandler }),
4977
+ vue.createElementVNode("div", _hoisted_1$b, [
4978
+ vue.createVNode(_sfc_main$n, { onSearch: filterTextChangeHandler }),
4714
4979
  editable.value ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
4715
4980
  key: 0,
4716
4981
  class: "create-code-button",
4717
4982
  type: "primary",
4718
4983
  size: "small",
4719
- onClick: createCodeBlock
4984
+ onClick: vue.unref(createCodeBlock)
4720
4985
  }, {
4721
4986
  default: vue.withCtx(() => [
4722
4987
  vue.createTextVNode("新增")
4723
4988
  ]),
4724
4989
  _: 1
4725
- })) : vue.createCommentVNode("", true)
4990
+ }, 8, ["onClick"])) : vue.createCommentVNode("", true)
4726
4991
  ])
4727
4992
  ]),
4728
- vue.createVNode(vue.unref(design.TMagicTree), {
4729
- ref_key: "tree",
4730
- ref: tree,
4731
- class: "magic-editor-layer-tree",
4732
- "node-key": "id",
4733
- "empty-text": "暂无代码块",
4734
- "default-expanded-keys": expandedKeys.value,
4735
- "expand-on-click-node": false,
4736
- data: codeList.value,
4737
- props: treeProps,
4738
- "highlight-current": true,
4739
- "filter-node-method": filterNode,
4740
- onNodeClick: clickHandler
4741
- }, {
4742
- default: vue.withCtx(({ data }) => [
4743
- vue.createElementVNode("div", {
4744
- id: data.id,
4745
- class: "list-container"
4746
- }, [
4747
- vue.createElementVNode("div", _hoisted_3$2, [
4748
- data.type === "code" ? (vue.openBlock(), vue.createBlock(_sfc_main$m, {
4749
- key: 0,
4750
- class: "codeIcon"
4751
- })) : vue.createCommentVNode("", true),
4752
- data.type === "node" ? (vue.openBlock(), vue.createBlock(_sfc_main$n, {
4753
- key: 1,
4754
- class: "compIcon"
4755
- })) : vue.createCommentVNode("", true),
4756
- vue.createElementVNode("span", {
4757
- class: vue.normalizeClass(["name", { code: data.type === "code", hook: data.type === "key" }])
4758
- }, vue.toDisplayString(data.name) + " (" + vue.toDisplayString(data.id) + ")", 3),
4759
- data.type === "code" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4$2, [
4760
- vue.createVNode(vue.unref(design.TMagicTooltip), {
4761
- effect: "dark",
4762
- content: editable.value ? "编辑" : "查看",
4763
- placement: "bottom"
4764
- }, {
4765
- default: vue.withCtx(() => [
4766
- vue.createVNode(_sfc_main$E, {
4767
- icon: editable.value ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
4768
- class: "edit-icon",
4769
- onClick: vue.withModifiers(($event) => editCode(`${data.id}`), ["stop"])
4770
- }, null, 8, ["icon", "onClick"])
4771
- ]),
4772
- _: 2
4773
- }, 1032, ["content"]),
4774
- editable.value ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTooltip), {
4775
- key: 0,
4776
- effect: "dark",
4777
- content: "删除",
4778
- placement: "bottom"
4779
- }, {
4780
- default: vue.withCtx(() => [
4781
- vue.createVNode(_sfc_main$E, {
4782
- icon: vue.unref(iconsVue.Close),
4783
- class: "edit-icon",
4784
- onClick: vue.withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
4785
- }, null, 8, ["icon", "onClick"])
4786
- ]),
4787
- _: 2
4788
- }, 1024)) : vue.createCommentVNode("", true),
4789
- vue.renderSlot(_ctx.$slots, "code-block-panel-tool", {
4790
- id: data.id,
4791
- data: data.codeBlockContent
4792
- })
4793
- ])) : vue.createCommentVNode("", true)
4794
- ])
4795
- ], 8, _hoisted_2$4)
4796
- ]),
4797
- _: 3
4798
- }, 8, ["default-expanded-keys", "data"]),
4799
- isShowCodeBlockEditor.value ? (vue.openBlock(), vue.createBlock(_sfc_main$j, {
4993
+ vue.createVNode(_sfc_main$k, {
4994
+ ref_key: "codeBlockList",
4995
+ ref: codeBlockList,
4996
+ "custom-error": _ctx.customError,
4997
+ onEdit: vue.unref(editCode),
4998
+ onRemove: vue.unref(deleteCode)
4999
+ }, null, 8, ["custom-error", "onEdit", "onRemove"]),
5000
+ vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
4800
5001
  key: 0,
4801
- paramsColConfig: _ctx.paramsColConfig
4802
- }, {
4803
- "code-block-edit-panel-header": vue.withCtx(({ id }) => [
4804
- vue.renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
4805
- ]),
4806
- _: 3
4807
- }, 8, ["paramsColConfig"])) : vue.createCommentVNode("", true)
5002
+ ref_key: "codeBlockEditor",
5003
+ ref: codeBlockEditor,
5004
+ disabled: !editable.value,
5005
+ content: vue.unref(codeConfig),
5006
+ onSubmit: vue.unref(submitCodeBlockHandler)
5007
+ }, null, 8, ["disabled", "content", "onSubmit"])) : vue.createCommentVNode("", true)
4808
5008
  ]),
4809
5009
  _: 3
4810
5010
  });
@@ -4812,14 +5012,15 @@
4812
5012
  }
4813
5013
  });
4814
5014
 
4815
- const _sfc_main$h = /* @__PURE__ */ vue.defineComponent({
5015
+ const _sfc_main$i = /* @__PURE__ */ vue.defineComponent({
4816
5016
  ...{
4817
5017
  name: "MEditorDataSourceConfigPanel"
4818
5018
  },
4819
5019
  __name: "DataSourceConfigPanel",
4820
5020
  props: {
4821
5021
  title: {},
4822
- values: {}
5022
+ values: {},
5023
+ disabled: { type: Boolean }
4823
5024
  },
4824
5025
  emits: ["submit"],
4825
5026
  setup(__props, { expose: __expose, emit }) {
@@ -4828,7 +5029,7 @@
4828
5029
  const services = vue.inject("services");
4829
5030
  const size = vue.computed(() => globalThis.document.body.clientWidth - (services?.uiService.get("columnWidth").left || 0));
4830
5031
  const dataSourceConfig = vue.computed(() => services?.dataSourceService.getFormConfig(type.value) || []);
4831
- const form$1 = vue.ref();
5032
+ const fomDrawer = vue.ref();
4832
5033
  const initValues = vue.ref({});
4833
5034
  vue.watchEffect(() => {
4834
5035
  initValues.value = props.values;
@@ -4841,84 +5042,53 @@
4841
5042
  type.value = value.type || "base";
4842
5043
  initValues.value = value;
4843
5044
  };
4844
- const submitHandler = async () => {
4845
- try {
4846
- const values = await form$1.value?.submitForm();
4847
- emit("submit", values);
4848
- } catch (error) {
4849
- design.tMagicMessage.error(error.message);
4850
- }
5045
+ const submitHandler = (values) => {
5046
+ emit("submit", values);
4851
5047
  };
4852
- const visible = vue.ref(false);
4853
- const hide = () => {
4854
- visible.value = false;
5048
+ const errorHandler = (error) => {
5049
+ design.tMagicMessage.error(error.message);
4855
5050
  };
4856
5051
  __expose({
4857
5052
  show() {
4858
- visible.value = true;
5053
+ fomDrawer.value?.show();
4859
5054
  },
4860
- hide
5055
+ hide() {
5056
+ fomDrawer.value?.hide();
5057
+ }
4861
5058
  });
4862
5059
  return (_ctx, _cache) => {
4863
- return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicDrawer), {
4864
- modelValue: visible.value,
4865
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => visible.value = $event),
5060
+ return vue.openBlock(), vue.createBlock(vue.unref(form.MFormDrawer), {
5061
+ ref_key: "fomDrawer",
5062
+ ref: fomDrawer,
5063
+ "label-width": "80px",
4866
5064
  title: _ctx.title,
4867
- "close-on-press-escape": true,
4868
- "append-to-body": true,
4869
- "show-close": true,
4870
- "close-on-click-modal": true,
4871
- size: size.value
4872
- }, {
4873
- footer: vue.withCtx(() => [
4874
- vue.createElementVNode("div", null, [
4875
- vue.createVNode(vue.unref(design.TMagicButton), {
4876
- type: "primary",
4877
- onClick: submitHandler
4878
- }, {
4879
- default: vue.withCtx(() => [
4880
- vue.createTextVNode("确定")
4881
- ]),
4882
- _: 1
4883
- }),
4884
- vue.createVNode(vue.unref(design.TMagicButton), { onClick: hide }, {
4885
- default: vue.withCtx(() => [
4886
- vue.createTextVNode("关闭")
4887
- ]),
4888
- _: 1
4889
- })
4890
- ])
4891
- ]),
4892
- default: vue.withCtx(() => [
4893
- vue.createVNode(vue.unref(form.MForm), {
4894
- ref_key: "form",
4895
- ref: form$1,
4896
- config: dataSourceConfig.value,
4897
- "init-values": initValues.value,
4898
- onChange: changeHandler
4899
- }, null, 8, ["config", "init-values"])
4900
- ]),
4901
- _: 1
4902
- }, 8, ["modelValue", "title", "size"]);
5065
+ width: size.value,
5066
+ config: dataSourceConfig.value,
5067
+ values: initValues.value,
5068
+ disabled: _ctx.disabled,
5069
+ onChange: changeHandler,
5070
+ onSubmit: submitHandler,
5071
+ onError: errorHandler
5072
+ }, null, 8, ["title", "width", "config", "values", "disabled"]);
4903
5073
  };
4904
5074
  }
4905
5075
  });
4906
5076
 
4907
- const _hoisted_1$9 = { class: "search-wrapper" };
4908
- const _hoisted_2$3 = ["id"];
4909
- const _hoisted_3$1 = { class: "list-item" };
4910
- const _hoisted_4$1 = {
5077
+ const _hoisted_1$a = ["id"];
5078
+ const _hoisted_2$3 = { class: "list-item" };
5079
+ const _hoisted_3$1 = {
4911
5080
  key: 2,
4912
5081
  class: "right-tool"
4913
5082
  };
4914
- const _sfc_main$g = /* @__PURE__ */ vue.defineComponent({
5083
+ const _sfc_main$h = /* @__PURE__ */ vue.defineComponent({
4915
5084
  ...{
4916
- name: "MEditorDataSourceListPanel"
5085
+ name: "MEditorDataSourceList"
4917
5086
  },
4918
- __name: "DataSourceListPanel",
4919
- setup(__props) {
4920
- const services = vue.inject("services", {});
4921
- const { dataSourceService, depService, editorService } = vue.inject("services") || {};
5087
+ __name: "DataSourceList",
5088
+ emits: ["edit", "remove"],
5089
+ setup(__props, { expose: __expose, emit }) {
5090
+ const { depService, editorService, dataSourceService } = vue.inject("services") || {};
5091
+ const editable = vue.computed(() => dataSourceService?.get("editable") ?? true);
4922
5092
  const list = vue.computed(
4923
5093
  () => Object.values(depService?.targets["data-source"] || {}).map((target) => ({
4924
5094
  id: target.id,
@@ -4932,8 +5102,123 @@
4932
5102
  }))
4933
5103
  }))
4934
5104
  );
5105
+ const editHandler = (id) => {
5106
+ emit("edit", id);
5107
+ };
5108
+ const removeHandler = async (id) => {
5109
+ await design.tMagicMessageBox.confirm("确定删除?", "提示", {
5110
+ confirmButtonText: "确定",
5111
+ cancelButtonText: "取消",
5112
+ type: "warning"
5113
+ });
5114
+ emit("remove", id);
5115
+ };
5116
+ const selectComp = (compId) => {
5117
+ const stage = editorService?.get("stage");
5118
+ editorService?.select(compId);
5119
+ stage?.select(compId);
5120
+ };
5121
+ const clickHandler = (data, node) => {
5122
+ if (data.type === "node") {
5123
+ selectComp(data.id);
5124
+ } else if (data.type === "key") {
5125
+ selectComp(node.parent.data.id);
5126
+ }
5127
+ };
5128
+ const tree = vue.ref();
5129
+ __expose({
5130
+ filter(val) {
5131
+ debugger;
5132
+ tree.value?.filter(val);
5133
+ }
5134
+ });
5135
+ return (_ctx, _cache) => {
5136
+ return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTree), {
5137
+ ref_key: "tree",
5138
+ ref: tree,
5139
+ class: "magic-editor-layer-tree",
5140
+ "node-key": "id",
5141
+ "empty-text": "暂无代码块",
5142
+ "default-expand-all": "",
5143
+ "expand-on-click-node": false,
5144
+ data: list.value,
5145
+ "highlight-current": true,
5146
+ onNodeClick: clickHandler
5147
+ }, {
5148
+ default: vue.withCtx(({ data }) => [
5149
+ vue.createElementVNode("div", {
5150
+ id: data.id,
5151
+ class: "list-container"
5152
+ }, [
5153
+ vue.createElementVNode("div", _hoisted_2$3, [
5154
+ data.type === "code" ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
5155
+ key: 0,
5156
+ class: "codeIcon",
5157
+ icon: vue.unref(iconsVue.Coin)
5158
+ }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
5159
+ data.type === "node" ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
5160
+ key: 1,
5161
+ class: "compIcon",
5162
+ icon: vue.unref(iconsVue.Aim)
5163
+ }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
5164
+ vue.createElementVNode("span", {
5165
+ class: vue.normalizeClass(["name", { code: data.type === "code", hook: data.type === "key" }])
5166
+ }, vue.toDisplayString(data.name) + "(" + vue.toDisplayString(data.id) + ")", 3),
5167
+ data.type === "code" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3$1, [
5168
+ vue.createVNode(vue.unref(design.TMagicTooltip), {
5169
+ effect: "dark",
5170
+ content: editable.value ? "编辑" : "查看",
5171
+ placement: "bottom"
5172
+ }, {
5173
+ default: vue.withCtx(() => [
5174
+ vue.createVNode(_sfc_main$E, {
5175
+ icon: editable.value ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
5176
+ class: "edit-icon",
5177
+ onClick: vue.withModifiers(($event) => editHandler(`${data.id}`), ["stop"])
5178
+ }, null, 8, ["icon", "onClick"])
5179
+ ]),
5180
+ _: 2
5181
+ }, 1032, ["content"]),
5182
+ editable.value ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTooltip), {
5183
+ key: 0,
5184
+ effect: "dark",
5185
+ content: "删除",
5186
+ placement: "bottom"
5187
+ }, {
5188
+ default: vue.withCtx(() => [
5189
+ vue.createVNode(_sfc_main$E, {
5190
+ icon: vue.unref(iconsVue.Close),
5191
+ class: "edit-icon",
5192
+ onClick: vue.withModifiers(($event) => removeHandler(`${data.id}`), ["stop"])
5193
+ }, null, 8, ["icon", "onClick"])
5194
+ ]),
5195
+ _: 2
5196
+ }, 1024)) : vue.createCommentVNode("", true),
5197
+ vue.renderSlot(_ctx.$slots, "data-source-panel-tool", {
5198
+ id: data.id,
5199
+ data: data.codeBlockContent
5200
+ })
5201
+ ])) : vue.createCommentVNode("", true)
5202
+ ])
5203
+ ], 8, _hoisted_1$a)
5204
+ ]),
5205
+ _: 3
5206
+ }, 8, ["data"]);
5207
+ };
5208
+ }
5209
+ });
5210
+
5211
+ const _hoisted_1$9 = { class: "search-wrapper" };
5212
+ const _sfc_main$g = /* @__PURE__ */ vue.defineComponent({
5213
+ ...{
5214
+ name: "MEditorDataSourceListPanel"
5215
+ },
5216
+ __name: "DataSourceListPanel",
5217
+ setup(__props) {
5218
+ const { dataSourceService } = vue.inject("services") || {};
4935
5219
  const editDialog = vue.ref();
4936
5220
  const dataSourceValues = vue.ref({});
5221
+ const editable = vue.computed(() => dataSourceService?.get("editable") ?? true);
4937
5222
  const addHandler = () => {
4938
5223
  if (!editDialog.value)
4939
5224
  return;
@@ -4941,24 +5226,17 @@
4941
5226
  editDialog.value.show();
4942
5227
  };
4943
5228
  const editHandler = (id) => {
4944
- if (!editDialog.value || !services)
5229
+ if (!editDialog.value)
4945
5230
  return;
4946
5231
  dataSourceValues.value = {
4947
5232
  ...dataSourceService?.getDataSourceById(id)
4948
5233
  };
4949
5234
  editDialog.value.show();
4950
5235
  };
4951
- const removeHandler = async (id) => {
4952
- await design.tMagicMessageBox.confirm("确定删除?", "提示", {
4953
- confirmButtonText: "确定",
4954
- cancelButtonText: "取消",
4955
- type: "warning"
4956
- });
5236
+ const removeHandler = (id) => {
4957
5237
  dataSourceService?.remove(id);
4958
5238
  };
4959
5239
  const submitDataSourceHandler = (value) => {
4960
- if (!services)
4961
- return;
4962
5240
  if (value.id) {
4963
5241
  dataSourceService?.update(value);
4964
5242
  } else {
@@ -4966,28 +5244,17 @@
4966
5244
  }
4967
5245
  editDialog.value?.hide();
4968
5246
  };
4969
- const tree = vue.ref();
5247
+ const dataSourceList = vue.ref();
4970
5248
  const filterTextChangeHandler = (val) => {
4971
- tree.value?.filter(val);
4972
- };
4973
- const selectComp = (compId) => {
4974
- const stage = editorService?.get("stage");
4975
- editorService?.select(compId);
4976
- stage?.select(compId);
4977
- };
4978
- const clickHandler = (data, node) => {
4979
- if (data.type === "node") {
4980
- selectComp(data.id);
4981
- } else if (data.type === "key") {
4982
- selectComp(node.parent.data.id);
4983
- }
5249
+ dataSourceList.value?.filter(val);
4984
5250
  };
4985
5251
  return (_ctx, _cache) => {
4986
5252
  return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicScrollbar), { class: "data-source-list-panel m-editor-dep-list-panel" }, {
4987
5253
  default: vue.withCtx(() => [
4988
5254
  vue.createElementVNode("div", _hoisted_1$9, [
4989
- vue.createVNode(_sfc_main$o, { onSearch: filterTextChangeHandler }),
4990
- vue.createVNode(vue.unref(design.TMagicButton), {
5255
+ vue.createVNode(_sfc_main$n, { onSearch: filterTextChangeHandler }),
5256
+ editable.value ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
5257
+ key: 0,
4991
5258
  type: "primary",
4992
5259
  size: "small",
4993
5260
  onClick: addHandler
@@ -4996,87 +5263,22 @@
4996
5263
  vue.createTextVNode("新增")
4997
5264
  ]),
4998
5265
  _: 1
4999
- })
5266
+ })) : vue.createCommentVNode("", true)
5000
5267
  ]),
5001
- vue.createVNode(vue.unref(design.TMagicTree), {
5002
- ref_key: "tree",
5003
- ref: tree,
5004
- class: "magic-editor-layer-tree",
5005
- "node-key": "id",
5006
- "empty-text": "暂无代码块",
5007
- "default-expand-all": "",
5008
- "expand-on-click-node": false,
5009
- data: list.value,
5010
- "highlight-current": true,
5011
- onNodeClick: clickHandler
5012
- }, {
5013
- default: vue.withCtx(({ data }) => [
5014
- vue.createElementVNode("div", {
5015
- id: data.id,
5016
- class: "list-container"
5017
- }, [
5018
- vue.createElementVNode("div", _hoisted_3$1, [
5019
- data.type === "code" ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
5020
- key: 0,
5021
- class: "codeIcon",
5022
- icon: vue.unref(iconsVue.Coin)
5023
- }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
5024
- data.type === "node" ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
5025
- key: 1,
5026
- class: "compIcon",
5027
- icon: vue.unref(iconsVue.Aim)
5028
- }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
5029
- vue.createElementVNode("span", {
5030
- class: vue.normalizeClass(["name", { code: data.type === "code", hook: data.type === "key" }])
5031
- }, vue.toDisplayString(data.name) + "(" + vue.toDisplayString(data.id) + ")", 3),
5032
- data.type === "code" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4$1, [
5033
- vue.createVNode(vue.unref(design.TMagicTooltip), {
5034
- effect: "dark",
5035
- content: "编辑",
5036
- placement: "bottom"
5037
- }, {
5038
- default: vue.withCtx(() => [
5039
- vue.createVNode(_sfc_main$E, {
5040
- class: "edit-icon",
5041
- icon: vue.unref(iconsVue.Edit),
5042
- onClick: vue.withModifiers(($event) => editHandler(`${data.id}`), ["stop"])
5043
- }, null, 8, ["icon", "onClick"])
5044
- ]),
5045
- _: 2
5046
- }, 1024),
5047
- vue.createVNode(vue.unref(design.TMagicTooltip), {
5048
- effect: "dark",
5049
- content: "删除",
5050
- placement: "bottom"
5051
- }, {
5052
- default: vue.withCtx(() => [
5053
- vue.createVNode(_sfc_main$E, {
5054
- icon: vue.unref(iconsVue.Close),
5055
- class: "edit-icon",
5056
- onClick: vue.withModifiers(($event) => removeHandler(`${data.id}`), ["stop"])
5057
- }, null, 8, ["icon", "onClick"])
5058
- ]),
5059
- _: 2
5060
- }, 1024),
5061
- vue.renderSlot(_ctx.$slots, "data-source-panel-tool", {
5062
- id: data.id,
5063
- data: data.codeBlockContent
5064
- })
5065
- ])) : vue.createCommentVNode("", true)
5066
- ])
5067
- ], 8, _hoisted_2$3)
5068
- ]),
5069
- _: 3
5070
- }, 8, ["data"]),
5071
5268
  vue.createVNode(_sfc_main$h, {
5269
+ onEdit: editHandler,
5270
+ onRemove: removeHandler
5271
+ }),
5272
+ vue.createVNode(_sfc_main$i, {
5072
5273
  ref_key: "editDialog",
5073
5274
  ref: editDialog,
5275
+ disabled: !editable.value,
5074
5276
  values: dataSourceValues.value,
5075
5277
  title: typeof dataSourceValues.value.id !== "undefined" ? `编辑${dataSourceValues.value.title}` : "新增",
5076
5278
  onSubmit: submitDataSourceHandler
5077
- }, null, 8, ["values", "title"])
5279
+ }, null, 8, ["disabled", "values", "title"])
5078
5280
  ]),
5079
- _: 3
5281
+ _: 1
5080
5282
  });
5081
5283
  };
5082
5284
  }
@@ -5162,7 +5364,7 @@
5162
5364
  "model-value": collapseValue.value
5163
5365
  }, {
5164
5366
  default: vue.withCtx(() => [
5165
- vue.createVNode(_sfc_main$o, { onSearch: filterTextChangeHandler }),
5367
+ vue.createVNode(_sfc_main$n, { onSearch: filterTextChangeHandler }),
5166
5368
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(list.value, (group, index) => {
5167
5369
  return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
5168
5370
  group.items && group.items.length ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicCollapseItem), {
@@ -5319,7 +5521,7 @@
5319
5521
  }, [
5320
5522
  vue.createElementVNode("div", null, [
5321
5523
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.menuData, (item, index) => {
5322
- return vue.openBlock(), vue.createBlock(_sfc_main$r, {
5524
+ return vue.openBlock(), vue.createBlock(_sfc_main$q, {
5323
5525
  "event-type": "mouseup",
5324
5526
  ref_for: true,
5325
5527
  ref_key: "buttons",
@@ -5804,7 +6006,7 @@
5804
6006
  return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicScrollbar), { class: "magic-editor-layer-panel" }, {
5805
6007
  default: vue.withCtx(() => [
5806
6008
  vue.renderSlot(_ctx.$slots, "layer-panel-header"),
5807
- vue.createVNode(_sfc_main$o, { onSearch: filterTextChangeHandler }),
6009
+ vue.createVNode(_sfc_main$n, { onSearch: filterTextChangeHandler }),
5808
6010
  values.value.length ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTree), {
5809
6011
  key: 0,
5810
6012
  class: "magic-editor-layer-tree",
@@ -5908,7 +6110,7 @@
5908
6110
  type: "component",
5909
6111
  icon: iconsVue.EditPen,
5910
6112
  text: "代码编辑",
5911
- component: _sfc_main$i,
6113
+ component: _sfc_main$j,
5912
6114
  slots: {}
5913
6115
  },
5914
6116
  "data-source": {
@@ -6002,16 +6204,6 @@
6002
6204
  ]),
6003
6205
  key: "4"
6004
6206
  } : void 0,
6005
- config.$key === "code-block" || config.slots?.codeBlockEditPanelHeader ? {
6006
- name: "code-block-edit-panel-header",
6007
- fn: vue.withCtx(({ id }) => [
6008
- config.$key === "code-block" ? vue.renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
6009
- key: 0,
6010
- id
6011
- }) : config.slots?.codeBlockEditPanelHeader ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(config.slots.codeBlockEditPanelHeader), { key: 1 })) : vue.createCommentVNode("", true)
6012
- ]),
6013
- key: "5"
6014
- } : void 0,
6015
6207
  config.$key === "layer" || config.slots?.layerNodeContent ? {
6016
6208
  name: "layer-node-content",
6017
6209
  fn: vue.withCtx(({ data: nodeData, node }) => [
@@ -6025,7 +6217,7 @@
6025
6217
  node
6026
6218
  }, null, 8, ["data", "node"])) : vue.createCommentVNode("", true)
6027
6219
  ]),
6028
- key: "6"
6220
+ key: "5"
6029
6221
  } : void 0
6030
6222
  ]), 1040)) : vue.createCommentVNode("", true)
6031
6223
  ]),
@@ -6271,7 +6463,7 @@
6271
6463
  default: vue.withCtx(() => [
6272
6464
  vue.createElementVNode("div", null, [
6273
6465
  vue.renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
6274
- vue.createVNode(_sfc_main$r, {
6466
+ vue.createVNode(_sfc_main$q, {
6275
6467
  data: {
6276
6468
  type: "button",
6277
6469
  text: "复制",
@@ -6279,7 +6471,7 @@
6279
6471
  handler: () => copy(item)
6280
6472
  }
6281
6473
  }, null, 8, ["data"]),
6282
- vue.createVNode(_sfc_main$r, {
6474
+ vue.createVNode(_sfc_main$q, {
6283
6475
  data: {
6284
6476
  type: "button",
6285
6477
  text: "删除",
@@ -7014,22 +7206,14 @@
7014
7206
 
7015
7207
  class CodeBlock extends BaseService {
7016
7208
  state = vue.reactive({
7017
- isShowCodeEditor: false,
7018
7209
  codeDsl: null,
7019
- id: "",
7020
7210
  editable: true,
7021
7211
  combineIds: [],
7022
- undeletableList: []
7212
+ undeletableList: [],
7213
+ paramsColConfig: void 0
7023
7214
  });
7024
7215
  constructor() {
7025
- super([
7026
- "setCodeDslById",
7027
- "setCodeEditorShowStatus",
7028
- "setEditStatus",
7029
- "setCombineIds",
7030
- "setUndeleteableList",
7031
- "deleteCodeDslByIds"
7032
- ]);
7216
+ super(["setCodeDslById", "setEditStatus", "setCombineIds", "setUndeleteableList", "deleteCodeDslByIds"]);
7033
7217
  }
7034
7218
  /**
7035
7219
  * 设置活动的代码块dsl数据源
@@ -7076,7 +7260,10 @@
7076
7260
  const codeConfigProcessed = codeConfig;
7077
7261
  if (codeConfig.content) {
7078
7262
  const parseDSL = getConfig("parseDSL");
7079
- codeConfigProcessed.content = parseDSL(codeConfig.content);
7263
+ if (typeof codeConfig.content === "string") {
7264
+ codeConfig.content = parseDSL(codeConfig.content);
7265
+ }
7266
+ codeConfigProcessed.content = codeConfig.content;
7080
7267
  }
7081
7268
  const existContent = codeDsl[id] || {};
7082
7269
  codeDsl[id] = {
@@ -7094,40 +7281,6 @@
7094
7281
  const codeDsl = this.getCodeDsl();
7095
7282
  return lodashEs.pick(codeDsl, ids);
7096
7283
  }
7097
- /**
7098
- * 设置代码编辑面板展示状态
7099
- * @param {boolean} status 是否展示代码编辑面板
7100
- * @returns {void}
7101
- */
7102
- async setCodeEditorShowStatus(status) {
7103
- this.state.isShowCodeEditor = status;
7104
- }
7105
- /**
7106
- * 获取代码编辑面板展示状态
7107
- * @returns {boolean} 是否展示代码编辑面板
7108
- */
7109
- getCodeEditorShowStatus() {
7110
- return this.state.isShowCodeEditor;
7111
- }
7112
- /**
7113
- * 设置代码编辑面板展示状态及展示内容
7114
- * @param {boolean} status 是否展示代码编辑面板
7115
- * @param {Id} id 代码块id
7116
- * @returns {void}
7117
- */
7118
- setCodeEditorContent(status, id) {
7119
- if (!id)
7120
- return;
7121
- this.setId(id);
7122
- this.state.isShowCodeEditor = status;
7123
- }
7124
- /**
7125
- * 获取当前选中的代码块内容
7126
- * @returns {CodeBlockContent | null}
7127
- */
7128
- getCurrentDsl() {
7129
- return this.getCodeContentById(this.state.id);
7130
- }
7131
7284
  /**
7132
7285
  * 获取编辑状态
7133
7286
  * @returns {boolean} 是否可编辑
@@ -7143,23 +7296,6 @@
7143
7296
  async setEditStatus(status) {
7144
7297
  this.state.editable = status;
7145
7298
  }
7146
- /**
7147
- * 设置当前选中的代码块ID
7148
- * @param {Id} id 代码块id
7149
- * @returns {void}
7150
- */
7151
- setId(id) {
7152
- if (!id)
7153
- return;
7154
- this.state.id = id;
7155
- }
7156
- /**
7157
- * 获取当前选中的代码块ID
7158
- * @returns {Id} id 代码块id
7159
- */
7160
- getId() {
7161
- return this.state.id;
7162
- }
7163
7299
  /**
7164
7300
  * 设置当前选中组件已关联绑定的代码块id数组
7165
7301
  * @param {string[]} ids 代码块id数组
@@ -7221,6 +7357,12 @@
7221
7357
  this.emit("remove", id);
7222
7358
  });
7223
7359
  }
7360
+ setParamsColConfig(config) {
7361
+ this.state.paramsColConfig = config;
7362
+ }
7363
+ getParamsColConfig() {
7364
+ return this.state.paramsColConfig;
7365
+ }
7224
7366
  /**
7225
7367
  * 生成代码块唯一id
7226
7368
  * @returns {Id} 代码块唯一id
@@ -7234,9 +7376,7 @@
7234
7376
  return await this.getUniqueId();
7235
7377
  }
7236
7378
  resetState() {
7237
- this.state.isShowCodeEditor = false;
7238
7379
  this.state.codeDsl = null;
7239
- this.state.id = "";
7240
7380
  this.state.editable = true;
7241
7381
  this.state.combineIds = [];
7242
7382
  this.state.undeletableList = [];
@@ -7369,6 +7509,17 @@
7369
7509
  defaultValue: []
7370
7510
  }
7371
7511
  ]
7512
+ },
7513
+ {
7514
+ type: "panel",
7515
+ title: "方法定义",
7516
+ items: [
7517
+ {
7518
+ name: "methods",
7519
+ type: "data-source-methods",
7520
+ defaultValue: []
7521
+ }
7522
+ ]
7372
7523
  }
7373
7524
  ];
7374
7525
  const getFormConfig = (type, configs) => {
@@ -7385,6 +7536,7 @@
7385
7536
  class DataSource extends BaseService {
7386
7537
  state = vue.reactive({
7387
7538
  dataSources: [],
7539
+ editable: true,
7388
7540
  configs: {}
7389
7541
  });
7390
7542
  set(name, value) {
@@ -8380,11 +8532,11 @@
8380
8532
  const _sfc_main = vue.defineComponent({
8381
8533
  name: "MEditor",
8382
8534
  components: {
8383
- TMagicNavMenu: _sfc_main$q,
8535
+ TMagicNavMenu: _sfc_main$p,
8384
8536
  Sidebar: _sfc_main$a,
8385
8537
  Workspace: _sfc_main$1,
8386
- PropsPanel: _sfc_main$p,
8387
- Framework: _sfc_main$s
8538
+ PropsPanel: _sfc_main$o,
8539
+ Framework: _sfc_main$r
8388
8540
  },
8389
8541
  props: editorProps,
8390
8542
  emits: ["props-panel-mounted", "update:modelValue"],
@@ -8487,9 +8639,6 @@
8487
8639
  data
8488
8640
  })
8489
8641
  ]),
8490
- "code-block-edit-panel-header": vue.withCtx(({ id }) => [
8491
- vue.renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
8492
- ]),
8493
8642
  _: 3
8494
8643
  }, 8, ["data", "layer-content-menu"])
8495
8644
  ])
@@ -8552,49 +8701,55 @@
8552
8701
  app.config.globalProperties.$TMAGIC_EDITOR = option;
8553
8702
  setConfig(option);
8554
8703
  app.component(Editor.name, Editor);
8555
- app.component("m-fields-ui-select", _sfc_main$x);
8556
- app.component("m-fields-code-link", _sfc_main$G);
8557
- app.component("m-fields-vs-code", _sfc_main$H);
8558
- app.component("magic-code-editor", _sfc_main$w);
8559
- app.component("m-fields-code-select", _sfc_main$F);
8704
+ app.component("m-fields-ui-select", _sfc_main$v);
8705
+ app.component("m-fields-code-link", _sfc_main$I);
8706
+ app.component("m-fields-vs-code", _sfc_main$J);
8707
+ app.component("magic-code-editor", _sfc_main$K);
8708
+ app.component("m-fields-code-select", _sfc_main$H);
8560
8709
  app.component("m-fields-code-select-col", _sfc_main$D);
8561
- app.component("m-fields-event-select", _sfc_main$z);
8710
+ app.component("m-fields-event-select", _sfc_main$x);
8562
8711
  app.component("m-fields-data-source-fields", _sfc_main$C);
8563
- app.component("m-fields-key-value", _sfc_main$y);
8712
+ app.component("m-fields-key-value", _sfc_main$w);
8564
8713
  app.component("m-fields-data-source-input", _sfc_main$B);
8565
- app.component("m-fields-data-source-select", _sfc_main$A);
8714
+ app.component("m-fields-data-source-select", _sfc_main$y);
8715
+ app.component("m-fields-data-source-methods", _sfc_main$A);
8716
+ app.component("m-fields-data-source-method-select", _sfc_main$z);
8566
8717
  }
8567
8718
  };
8568
8719
 
8569
8720
  exports.CODE_DRAFT_STORAGE_KEY = CODE_DRAFT_STORAGE_KEY;
8570
8721
  exports.COPY_STORAGE_KEY = COPY_STORAGE_KEY;
8571
- exports.CodeBlockList = _sfc_main$i;
8722
+ exports.CodeBlockEditor = _sfc_main$G;
8723
+ exports.CodeBlockList = _sfc_main$k;
8724
+ exports.CodeBlockListPanel = _sfc_main$j;
8572
8725
  exports.CodeDeleteErrorType = CodeDeleteErrorType;
8573
- exports.CodeSelect = _sfc_main$F;
8726
+ exports.CodeSelect = _sfc_main$H;
8574
8727
  exports.CodeSelectCol = _sfc_main$D;
8575
8728
  exports.ColumnLayout = ColumnLayout;
8576
8729
  exports.ComponentListPanel = _sfc_main$f;
8577
8730
  exports.ContentMenu = _sfc_main$e;
8578
8731
  exports.DataSourceFields = _sfc_main$C;
8579
8732
  exports.DataSourceInput = _sfc_main$B;
8580
- exports.DataSourceSelect = _sfc_main$A;
8581
- exports.EventSelect = _sfc_main$z;
8733
+ exports.DataSourceMethodSelect = _sfc_main$z;
8734
+ exports.DataSourceMethods = _sfc_main$A;
8735
+ exports.DataSourceSelect = _sfc_main$y;
8736
+ exports.EventSelect = _sfc_main$x;
8582
8737
  exports.Fixed2Other = Fixed2Other;
8583
8738
  exports.H_GUIDE_LINE_STORAGE_KEY = H_GUIDE_LINE_STORAGE_KEY;
8584
8739
  exports.Icon = _sfc_main$E;
8585
8740
  exports.KeyBindingCommand = KeyBindingCommand;
8586
- exports.KeyValue = _sfc_main$y;
8741
+ exports.KeyValue = _sfc_main$w;
8587
8742
  exports.Keys = Keys;
8588
8743
  exports.LayerOffset = LayerOffset;
8589
8744
  exports.LayerPanel = _sfc_main$b;
8590
8745
  exports.Layout = Layout;
8591
- exports.LayoutContainer = _sfc_main$u;
8592
- exports.PropsPanel = _sfc_main$p;
8593
- exports.Resizer = _sfc_main$v;
8594
- exports.SplitView = _sfc_main$u;
8595
- exports.TMagicCodeEditor = _sfc_main$w;
8746
+ exports.LayoutContainer = _sfc_main$t;
8747
+ exports.PropsPanel = _sfc_main$o;
8748
+ exports.Resizer = _sfc_main$u;
8749
+ exports.SplitView = _sfc_main$t;
8750
+ exports.TMagicCodeEditor = _sfc_main$K;
8596
8751
  exports.TMagicEditor = Editor;
8597
- exports.ToolButton = _sfc_main$r;
8752
+ exports.ToolButton = _sfc_main$q;
8598
8753
  exports.V_GUIDE_LINE_STORAGE_KEY = V_GUIDE_LINE_STORAGE_KEY;
8599
8754
  exports.beforePaste = beforePaste;
8600
8755
  exports.change2Fixed = change2Fixed;