@tmagic/editor 1.1.6 → 1.2.0-beta.2

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 (45) hide show
  1. package/dist/style.css +177 -0
  2. package/dist/tmagic-editor.mjs +1456 -524
  3. package/dist/tmagic-editor.mjs.map +1 -1
  4. package/dist/tmagic-editor.umd.js +1448 -510
  5. package/dist/tmagic-editor.umd.js.map +1 -1
  6. package/package.json +7 -7
  7. package/src/Editor.vue +18 -1
  8. package/src/fields/Code.vue +4 -1
  9. package/src/fields/CodeLink.vue +19 -11
  10. package/src/fields/CodeSelect.vue +139 -0
  11. package/src/index.ts +6 -2
  12. package/src/layouts/AddPageBox.vue +11 -19
  13. package/src/layouts/CodeEditor.vue +106 -120
  14. package/src/layouts/Layout.vue +1 -1
  15. package/src/layouts/PropsPanel.vue +1 -1
  16. package/src/layouts/sidebar/LayerMenu.vue +86 -91
  17. package/src/layouts/sidebar/Sidebar.vue +30 -24
  18. package/src/layouts/sidebar/TabPane.vue +57 -40
  19. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +164 -0
  20. package/src/layouts/sidebar/code-block/CodeBlockList.vue +267 -0
  21. package/src/services/codeBlock.ts +415 -0
  22. package/src/services/editor.ts +27 -1
  23. package/src/theme/code-block.scss +184 -0
  24. package/src/theme/index.scss +1 -13
  25. package/src/theme/layout.scss +5 -0
  26. package/src/theme/theme.scss +15 -0
  27. package/src/type.ts +87 -1
  28. package/src/utils/props.ts +9 -3
  29. package/types/fields/Code.vue.d.ts +8 -0
  30. package/types/fields/CodeLink.vue.d.ts +4 -0
  31. package/types/fields/CodeSelect.vue.d.ts +96 -0
  32. package/types/index.d.ts +3 -0
  33. package/types/layouts/AddPageBox.vue.d.ts +45 -3
  34. package/types/layouts/CodeEditor.vue.d.ts +160 -45
  35. package/types/layouts/sidebar/LayerMenu.vue.d.ts +16 -64
  36. package/types/layouts/sidebar/LayerPanel.vue.d.ts +8 -196
  37. package/types/layouts/sidebar/Sidebar.vue.d.ts +114 -17
  38. package/types/layouts/sidebar/TabPane.vue.d.ts +80 -12
  39. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +50 -0
  40. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +73 -0
  41. package/types/services/codeBlock.d.ts +155 -0
  42. package/types/services/editor.d.ts +12 -1
  43. package/types/services/props.d.ts +12 -0
  44. package/types/type.d.ts +77 -1
  45. package/types/utils/props.d.ts +12 -0
@@ -1,7 +1,8 @@
1
- import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, inject, ref, createElementBlock, createVNode, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, onMounted, onUnmounted, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, watchEffect, createSlots, resolveDynamicComponent, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, Teleport, nextTick, toHandlers, provide } from 'vue';
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, inject, ref, watchEffect, createElementBlock, createVNode, withCtx, createElementVNode, withModifiers, createCommentVNode, createTextVNode, toDisplayString, onMounted, onUnmounted, toRaw, renderSlot, Fragment, normalizeClass, createSlots, resolveDynamicComponent, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, isRef, Teleport, nextTick, toHandlers, provide } from 'vue';
2
2
  import serialize from 'serialize-javascript';
3
- import { Delete, Close, Plus, Edit, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
4
- import { throttle, cloneDeep, mergeWith, isEmpty, uniq } from 'lodash-es';
3
+ import { ElMessage } from 'element-plus';
4
+ import { cloneDeep, map, xor, throttle, pick, isEmpty, forIn, omit, keys, mergeWith, uniq } from 'lodash-es';
5
+ import { Delete, Close, Plus, Edit, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, View, Link, Files, DocumentCopy, EditPen, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
5
6
  import * as monaco from 'monaco-editor';
6
7
  import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType } from '@tmagic/stage';
7
8
  import { NodeType } from '@tmagic/schema';
@@ -9,10 +10,9 @@ import { isPop, getNodePath, isNumber, isPage, toLine, removeClassNameByClassNam
9
10
  import { EventEmitter } from 'events';
10
11
  import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
11
12
  import Gesto from 'gesto';
12
- import { ElMessage } from 'element-plus';
13
13
  import KeyController from 'keycon';
14
14
 
15
- const _sfc_main$p = /* @__PURE__ */ defineComponent({
15
+ const _sfc_main$s = /* @__PURE__ */ defineComponent({
16
16
  __name: "Code",
17
17
  props: {
18
18
  model: null,
@@ -24,7 +24,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
24
24
  setup(__props, { emit }) {
25
25
  const props = __props;
26
26
  const language = computed(() => props.config.language || "javascript");
27
- const height = computed(() => `${document.body.clientHeight - 168}px`);
27
+ const height = computed(() => props.config.height || `${document.body.clientHeight - 168}px`);
28
28
  const save = (v) => {
29
29
  props.model[props.name] = v;
30
30
  emit("change", v);
@@ -35,13 +35,14 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
35
35
  style: normalizeStyle(`height: ${unref(height)}`),
36
36
  "init-values": __props.model[__props.name],
37
37
  language: unref(language),
38
+ options: __props.config.options,
38
39
  onSave: save
39
- }, null, 8, ["style", "init-values", "language"]);
40
+ }, null, 8, ["style", "init-values", "language", "options"]);
40
41
  };
41
42
  }
42
43
  });
43
44
 
44
- const _sfc_main$o = /* @__PURE__ */ defineComponent({
45
+ const _sfc_main$r = /* @__PURE__ */ defineComponent({
45
46
  __name: "CodeLink",
46
47
  props: {
47
48
  config: null,
@@ -52,17 +53,24 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
52
53
  emits: ["change"],
53
54
  setup(__props, { emit }) {
54
55
  const props = __props;
55
- const formConfig = computed(() => ({
56
- ...props.config,
57
- text: "",
58
- type: "link",
59
- form: [
60
- {
61
- name: props.name,
62
- type: "vs-code"
63
- }
64
- ]
65
- }));
56
+ const formConfig = computed(() => {
57
+ const { codeOptions, ...config } = props.config;
58
+ return {
59
+ ...config,
60
+ text: "",
61
+ type: "link",
62
+ form: [
63
+ {
64
+ name: props.name,
65
+ type: "vs-code",
66
+ options: {
67
+ tabSize: 2,
68
+ ...codeOptions || {}
69
+ }
70
+ }
71
+ ]
72
+ };
73
+ });
66
74
  const modelValue = reactive({
67
75
  form: {
68
76
  [props.name]: ""
@@ -104,8 +112,186 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
104
112
  }
105
113
  });
106
114
 
107
- const _hoisted_1$b = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
108
- const _sfc_main$n = /* @__PURE__ */ defineComponent({
115
+ var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
116
+ ColumnLayout2["LEFT"] = "left";
117
+ ColumnLayout2["CENTER"] = "center";
118
+ ColumnLayout2["RIGHT"] = "right";
119
+ return ColumnLayout2;
120
+ })(ColumnLayout || {});
121
+ var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
122
+ LayerOffset2["TOP"] = "top";
123
+ LayerOffset2["BOTTOM"] = "bottom";
124
+ return LayerOffset2;
125
+ })(LayerOffset || {});
126
+ var Layout = /* @__PURE__ */ ((Layout2) => {
127
+ Layout2["FLEX"] = "flex";
128
+ Layout2["FIXED"] = "fixed";
129
+ Layout2["RELATIVE"] = "relative";
130
+ Layout2["ABSOLUTE"] = "absolute";
131
+ return Layout2;
132
+ })(Layout || {});
133
+ var Keys = /* @__PURE__ */ ((Keys2) => {
134
+ Keys2["ESCAPE"] = "Space";
135
+ return Keys2;
136
+ })(Keys || {});
137
+ const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
138
+ const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
139
+ var CodeEditorMode = /* @__PURE__ */ ((CodeEditorMode2) => {
140
+ CodeEditorMode2["LIST"] = "list";
141
+ CodeEditorMode2["EDITOR"] = "editor";
142
+ return CodeEditorMode2;
143
+ })(CodeEditorMode || {});
144
+ var CodeDeleteErrorType = /* @__PURE__ */ ((CodeDeleteErrorType2) => {
145
+ CodeDeleteErrorType2["UNDELETEABLE"] = "undeleteable";
146
+ CodeDeleteErrorType2["BIND"] = "bind";
147
+ return CodeDeleteErrorType2;
148
+ })(CodeDeleteErrorType || {});
149
+ var CodeSelectOp = /* @__PURE__ */ ((CodeSelectOp2) => {
150
+ CodeSelectOp2["ADD"] = "add";
151
+ CodeSelectOp2["DELETE"] = "delete";
152
+ CodeSelectOp2["CHANGE"] = "change";
153
+ return CodeSelectOp2;
154
+ })(CodeSelectOp || {});
155
+
156
+ const _hoisted_1$d = { class: "tool-bar" };
157
+ const _hoisted_2$6 = /* @__PURE__ */ createElementVNode("path", {
158
+ fill: "currentColor",
159
+ d: "m23 12l-7.071 7.071l-1.414-1.414L20.172 12l-5.657-5.657l1.414-1.414L23 12zM3.828 12l5.657 5.657l-1.414 1.414L1 12l7.071-7.071l1.414 1.414L3.828 12z"
160
+ }, null, -1);
161
+ const _hoisted_3$3 = [
162
+ _hoisted_2$6
163
+ ];
164
+ const _sfc_main$q = /* @__PURE__ */ defineComponent({
165
+ __name: "CodeSelect",
166
+ props: {
167
+ config: null,
168
+ model: null,
169
+ prop: null,
170
+ name: null,
171
+ size: null
172
+ },
173
+ emits: ["change"],
174
+ setup(__props, { emit }) {
175
+ const props = __props;
176
+ const services = inject("services");
177
+ const selectConfig = computed(() => {
178
+ const defaultConfig = {
179
+ multiple: true,
180
+ options: async () => {
181
+ const codeDsl = await services?.codeBlockService.getCodeDsl();
182
+ if (codeDsl) {
183
+ return map(codeDsl, (value, key) => ({
184
+ text: `${value.name}\uFF08${key}\uFF09`,
185
+ label: `${value.name}\uFF08${key}\uFF09`,
186
+ value: key
187
+ }));
188
+ }
189
+ return [];
190
+ }
191
+ };
192
+ return {
193
+ ...defaultConfig,
194
+ ...props.config.selectConfig
195
+ };
196
+ });
197
+ const fieldKey = ref("");
198
+ const multiple = ref(true);
199
+ const combineIds = ref([]);
200
+ let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
201
+ watchEffect(async () => {
202
+ const combineNames = await Promise.all(
203
+ combineIds.value.map(async (id) => {
204
+ const { name = "" } = await services?.codeBlockService.getCodeContentById(id) || {};
205
+ return name;
206
+ })
207
+ );
208
+ fieldKey.value = combineNames.join("-");
209
+ });
210
+ const changeHandler = async (value) => {
211
+ let codeIds = value;
212
+ if (typeof value === "string") {
213
+ multiple.value = false;
214
+ lastTagSnapshot = [lastTagSnapshot];
215
+ codeIds = value ? [value] : [];
216
+ }
217
+ await setCombineRelation(codeIds);
218
+ emit("change", value);
219
+ };
220
+ const setCombineRelation = async (codeIds) => {
221
+ const { id = "" } = services?.editorService.get("node") || {};
222
+ let opFlag = CodeSelectOp.CHANGE;
223
+ let diffValues = codeIds;
224
+ if (multiple.value) {
225
+ opFlag = codeIds.length < lastTagSnapshot.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
226
+ diffValues = xor(codeIds, lastTagSnapshot);
227
+ }
228
+ await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
229
+ lastTagSnapshot = codeIds;
230
+ await setCombineIds(codeIds);
231
+ };
232
+ const setCombineIds = async (codeIds) => {
233
+ combineIds.value = codeIds;
234
+ await services?.codeBlockService.setCombineIds(codeIds);
235
+ };
236
+ const viewHandler = async () => {
237
+ if (props.model[props.name].length === 0) {
238
+ ElMessage.error("\u8BF7\u5148\u7ED1\u5B9A\u4EE3\u7801\u5757");
239
+ return;
240
+ }
241
+ await setCombineIds(props.model[props.name]);
242
+ await services?.codeBlockService.setMode(CodeEditorMode.LIST);
243
+ services?.codeBlockService.setCodeEditorContent(true, combineIds.value[0]);
244
+ };
245
+ return (_ctx, _cache) => {
246
+ const _component_m_fields_select = resolveComponent("m-fields-select");
247
+ const _component_el_tooltip = resolveComponent("el-tooltip");
248
+ const _component_el_card = resolveComponent("el-card");
249
+ return openBlock(), createElementBlock("div", {
250
+ class: "m-fields-code-select",
251
+ key: fieldKey.value
252
+ }, [
253
+ createVNode(_component_el_card, { shadow: "never" }, {
254
+ header: withCtx(() => [
255
+ createVNode(_component_m_fields_select, {
256
+ config: unref(selectConfig),
257
+ model: __props.model,
258
+ prop: __props.prop,
259
+ name: __props.name,
260
+ size: __props.size,
261
+ onChange: changeHandler
262
+ }, null, 8, ["config", "model", "prop", "name", "size"])
263
+ ]),
264
+ default: withCtx(() => [
265
+ createElementVNode("div", _hoisted_1$d, [
266
+ createVNode(_component_el_tooltip, {
267
+ class: "tool-item",
268
+ effect: "dark",
269
+ content: "\u67E5\u770B\u4EE3\u7801\u5757",
270
+ placement: "top"
271
+ }, {
272
+ default: withCtx(() => [
273
+ (openBlock(), createElementBlock("svg", {
274
+ onClick: viewHandler,
275
+ preserveAspectRatio: "xMidYMid meet",
276
+ viewBox: "0 0 24 24",
277
+ width: "15px",
278
+ height: "15px",
279
+ "data-v-65a7fb6c": ""
280
+ }, _hoisted_3$3))
281
+ ]),
282
+ _: 1
283
+ })
284
+ ])
285
+ ]),
286
+ _: 1
287
+ })
288
+ ]);
289
+ };
290
+ }
291
+ });
292
+
293
+ const _hoisted_1$c = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
294
+ const _sfc_main$p = /* @__PURE__ */ defineComponent({
109
295
  __name: "UISelect",
110
296
  props: {
111
297
  config: null,
@@ -170,7 +356,7 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
170
356
  style: { "padding": "0" }
171
357
  }, {
172
358
  default: withCtx(() => [
173
- _hoisted_1$b
359
+ _hoisted_1$c
174
360
  ]),
175
361
  _: 1
176
362
  }, 8, ["icon"])
@@ -218,45 +404,36 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
218
404
 
219
405
  const UISelect_vue_vue_type_style_index_0_lang = '';
220
406
 
221
- const toString = (v, language) => {
222
- let value = "";
223
- if (typeof v !== "string") {
224
- value = serialize(v, {
225
- space: 2,
226
- unsafe: true
227
- }).replace(/"(\w+)":\s/g, "$1: ");
228
- } else {
229
- value = v;
230
- }
231
- if (language === "javascript" && value.startsWith("{") && value.endsWith("}")) {
232
- value = `(${value})`;
233
- }
234
- return value;
235
- };
236
- const _sfc_main$m = defineComponent({
237
- name: "magic-code-editor",
407
+ const _sfc_main$o = /* @__PURE__ */ defineComponent({
408
+ __name: "CodeEditor",
238
409
  props: {
239
- initValues: {
240
- type: [String, Object]
241
- },
242
- modifiedValues: {
243
- type: [String, Object]
244
- },
245
- type: {
246
- type: String,
247
- default: () => ""
248
- },
249
- language: {
250
- type: String,
251
- default: () => "javascript"
252
- },
253
- options: {
254
- type: Object,
255
- default: () => ({})
256
- }
410
+ initValues: null,
411
+ modifiedValues: null,
412
+ type: { default: "" },
413
+ language: { default: "javascript" },
414
+ options: { default: () => ({
415
+ tabSize: 2
416
+ }) },
417
+ autoSave: { type: Boolean, default: true }
257
418
  },
258
419
  emits: ["initd", "save"],
259
- setup(props, { emit }) {
420
+ setup(__props, { expose, emit }) {
421
+ const props = __props;
422
+ const toString = (v, language) => {
423
+ let value = "";
424
+ if (typeof v !== "string") {
425
+ value = serialize(v, {
426
+ space: 2,
427
+ unsafe: true
428
+ }).replace(/"(\w+)":\s/g, "$1: ");
429
+ } else {
430
+ value = v;
431
+ }
432
+ if (language === "javascript" && value.startsWith("{") && value.endsWith("}")) {
433
+ value = `(${value})`;
434
+ }
435
+ return value;
436
+ };
260
437
  let vsEditor = null;
261
438
  let vsDiffEditor = null;
262
439
  const values = ref("");
@@ -305,7 +482,7 @@ const _sfc_main$m = defineComponent({
305
482
  emit("save", getEditorValue());
306
483
  }
307
484
  });
308
- if (props.type !== "diff") {
485
+ if (props.type !== "diff" && props.autoSave) {
309
486
  vsEditor?.onDidBlurEditorWidget(() => {
310
487
  emit("save", getEditorValue());
311
488
  });
@@ -331,10 +508,7 @@ const _sfc_main$m = defineComponent({
331
508
  onUnmounted(() => {
332
509
  resizeObserver.disconnect();
333
510
  });
334
- return {
335
- values,
336
- loading,
337
- codeEditor,
511
+ expose({
338
512
  getEditor() {
339
513
  return vsEditor || vsDiffEditor;
340
514
  },
@@ -343,78 +517,48 @@ const _sfc_main$m = defineComponent({
343
517
  vsEditor?.focus();
344
518
  vsDiffEditor?.focus();
345
519
  }
520
+ });
521
+ return (_ctx, _cache) => {
522
+ return openBlock(), createElementBlock("div", {
523
+ ref_key: "codeEditor",
524
+ ref: codeEditor,
525
+ class: "magic-code-editor"
526
+ }, null, 512);
346
527
  };
347
528
  }
348
529
  });
349
530
 
350
- const _export_sfc = (sfc, props) => {
351
- const target = sfc.__vccOpts || sfc;
352
- for (const [key, val] of props) {
353
- target[key] = val;
354
- }
355
- return target;
356
- };
357
-
358
- const _hoisted_1$a = {
359
- ref: "codeEditor",
360
- class: "magic-code-editor"
361
- };
362
- function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
363
- return openBlock(), createElementBlock("div", _hoisted_1$a, null, 512);
364
- }
365
- const CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$6]]);
366
-
367
531
  let $TMAGIC_EDITOR = {};
368
532
  const setConfig = (option) => {
369
533
  $TMAGIC_EDITOR = option;
370
534
  };
371
535
  const getConfig = (key) => $TMAGIC_EDITOR[key];
372
536
 
373
- class UndoRedo {
374
- elementList;
375
- listCursor;
376
- listMaxSize;
377
- constructor(listMaxSize = 200) {
378
- const minListMaxSize = 2;
379
- this.elementList = [];
380
- this.listCursor = 0;
381
- this.listMaxSize = listMaxSize > minListMaxSize ? listMaxSize : minListMaxSize;
382
- }
383
- pushElement(element) {
384
- this.elementList.splice(this.listCursor, this.elementList.length - this.listCursor, cloneDeep(element));
385
- this.listCursor += 1;
386
- if (this.elementList.length > this.listMaxSize) {
387
- this.elementList.shift();
388
- this.listCursor -= 1;
389
- }
390
- }
391
- canUndo() {
392
- return this.listCursor > 1;
537
+ const log = (...args) => {
538
+ if (process.env.NODE_ENV === "development") {
539
+ console.log("magic editor: ", ...args);
393
540
  }
394
- undo() {
395
- if (!this.canUndo()) {
396
- return null;
397
- }
398
- this.listCursor -= 1;
399
- return this.getCurrentElement();
541
+ };
542
+ const info = (...args) => {
543
+ if (process.env.NODE_ENV === "development") {
544
+ console.info("magic editor: ", ...args);
400
545
  }
401
- canRedo() {
402
- return this.elementList.length > this.listCursor;
546
+ };
547
+ const warn = (...args) => {
548
+ if (process.env.NODE_ENV === "development") {
549
+ console.warn("magic editor: ", ...args);
403
550
  }
404
- redo() {
405
- if (!this.canRedo()) {
406
- return null;
407
- }
408
- this.listCursor += 1;
409
- return this.getCurrentElement();
551
+ };
552
+ const debug = (...args) => {
553
+ if (process.env.NODE_ENV === "development") {
554
+ console.debug("magic editor: ", ...args);
410
555
  }
411
- getCurrentElement() {
412
- if (this.listCursor < 1) {
413
- return null;
414
- }
415
- return cloneDeep(this.elementList[this.listCursor - 1]);
556
+ };
557
+ const error = (...args) => {
558
+ if (process.env.NODE_ENV === "development") {
559
+ console.error("magic editor: ", ...args);
416
560
  }
417
- }
561
+ };
418
562
 
419
563
  const compose = (middleware) => {
420
564
  if (!Array.isArray(middleware))
@@ -507,26 +651,289 @@ class BaseService extends EventEmitter {
507
651
  });
508
652
  });
509
653
  }
510
- use(options) {
511
- Object.entries(options).forEach(([methodName2, method]) => {
512
- if (typeof method === "function")
513
- this.middleware[methodName2].push(method);
514
- });
654
+ use(options) {
655
+ Object.entries(options).forEach(([methodName2, method]) => {
656
+ if (typeof method === "function")
657
+ this.middleware[methodName2].push(method);
658
+ });
659
+ }
660
+ usePlugin(options) {
661
+ Object.entries(options).forEach(([methodName2, method]) => {
662
+ if (typeof method === "function")
663
+ this.pluginOptionsList[methodName2].push(method);
664
+ });
665
+ }
666
+ async doTask() {
667
+ this.doingTask = true;
668
+ let task = this.taskList.shift();
669
+ while (task) {
670
+ await task();
671
+ task = this.taskList.shift();
672
+ }
673
+ this.doingTask = false;
674
+ }
675
+ }
676
+
677
+ class CodeBlock extends BaseService {
678
+ state = reactive({
679
+ isShowCodeEditor: false,
680
+ codeDsl: null,
681
+ id: "",
682
+ editable: true,
683
+ mode: CodeEditorMode.EDITOR,
684
+ combineIds: [],
685
+ undeletableList: []
686
+ });
687
+ constructor() {
688
+ super([
689
+ "setCodeDsl",
690
+ "getCodeDsl",
691
+ "getCodeContentById",
692
+ "getCodeDslByIds",
693
+ "getCurrentDsl",
694
+ "setCodeDslById",
695
+ "setCodeEditorShowStatus",
696
+ "setEditStatus",
697
+ "setMode",
698
+ "setCombineIds",
699
+ "setUndeleteableList",
700
+ "deleteCodeDslByIds"
701
+ ]);
702
+ }
703
+ async setCodeDsl(codeDsl) {
704
+ this.state.codeDsl = codeDsl;
705
+ await editorService.setCodeDsl(this.state.codeDsl);
706
+ info("[code-block]:code-dsl-change", this.state.codeDsl);
707
+ this.emit("code-dsl-change", this.state.codeDsl);
708
+ }
709
+ async getCodeDsl(forceRefresh = false) {
710
+ if (!this.state.codeDsl || forceRefresh) {
711
+ this.state.codeDsl = await editorService.getCodeDsl();
712
+ }
713
+ return this.state.codeDsl;
714
+ }
715
+ async getCodeContentById(id) {
716
+ if (!id)
717
+ return null;
718
+ const totalCodeDsl = await this.getCodeDsl();
719
+ if (!totalCodeDsl)
720
+ return null;
721
+ return totalCodeDsl[id] ?? null;
722
+ }
723
+ async setCodeDslById(id, codeConfig) {
724
+ let codeDsl = await this.getCodeDsl();
725
+ if (!codeDsl) {
726
+ codeDsl = {
727
+ [id]: codeConfig
728
+ };
729
+ } else {
730
+ const existContent = codeDsl[id] || {};
731
+ codeDsl = {
732
+ ...codeDsl,
733
+ [id]: {
734
+ ...existContent,
735
+ ...codeConfig
736
+ }
737
+ };
738
+ }
739
+ await this.setCodeDsl(codeDsl);
740
+ }
741
+ async getCodeDslByIds(ids) {
742
+ const codeDsl = await this.getCodeDsl();
743
+ return pick(codeDsl, ids);
744
+ }
745
+ async setCodeEditorShowStatus(status) {
746
+ this.state.isShowCodeEditor = status;
747
+ }
748
+ getCodeEditorShowStatus() {
749
+ return this.state.isShowCodeEditor;
750
+ }
751
+ setCodeEditorContent(status, id) {
752
+ if (!id)
753
+ return;
754
+ this.setId(id);
755
+ this.state.isShowCodeEditor = status;
756
+ }
757
+ async getCurrentDsl() {
758
+ return await this.getCodeContentById(this.state.id);
759
+ }
760
+ getEditStatus() {
761
+ return this.state.editable;
762
+ }
763
+ async setEditStatus(status) {
764
+ this.state.editable = status;
765
+ }
766
+ setId(id) {
767
+ if (!id)
768
+ return;
769
+ this.state.id = id;
770
+ }
771
+ getId() {
772
+ return this.state.id;
773
+ }
774
+ getMode() {
775
+ return this.state.mode;
776
+ }
777
+ async setMode(mode) {
778
+ this.state.mode = mode;
779
+ }
780
+ async setCombineIds(ids) {
781
+ this.state.combineIds = ids;
782
+ }
783
+ getCombineIds() {
784
+ return this.state.combineIds;
785
+ }
786
+ async setCombineRelation(compId, diffCodeIds, opFlag, hook) {
787
+ const codeDsl = cloneDeep(await this.getCodeDsl());
788
+ if (!codeDsl)
789
+ return;
790
+ if (opFlag === CodeSelectOp.DELETE) {
791
+ try {
792
+ diffCodeIds.forEach((codeId) => {
793
+ const compsContent = codeDsl[codeId].comps;
794
+ const index = compsContent?.[compId].findIndex((item) => item === hook);
795
+ if (typeof index !== "undefined" && index !== -1) {
796
+ compsContent?.[compId].splice(index, 1);
797
+ }
798
+ });
799
+ } catch (e) {
800
+ error(e);
801
+ throw new Error("\u89E3\u7ED1\u4EE3\u7801\u5757\u5931\u8D25");
802
+ }
803
+ } else if (opFlag === CodeSelectOp.ADD) {
804
+ try {
805
+ diffCodeIds.forEach((codeId) => {
806
+ const compsContent = codeDsl[codeId].comps;
807
+ const existHooks = compsContent?.[compId];
808
+ if (isEmpty(existHooks)) {
809
+ codeDsl[codeId].comps = {
810
+ ...codeDsl[codeId].comps || {},
811
+ [compId]: [hook]
812
+ };
813
+ } else {
814
+ existHooks?.push(hook);
815
+ }
816
+ });
817
+ } catch (e) {
818
+ error(e);
819
+ throw new Error("\u7ED1\u5B9A\u4EE3\u7801\u5757\u5931\u8D25");
820
+ }
821
+ } else if (opFlag === CodeSelectOp.CHANGE) {
822
+ forIn(codeDsl, (codeBlockContent, codeId) => {
823
+ if (codeId === diffCodeIds[0]) {
824
+ codeBlockContent.comps = {
825
+ ...codeBlockContent?.comps || {},
826
+ [compId]: [hook]
827
+ };
828
+ } else if (isEmpty(diffCodeIds) || codeId !== diffCodeIds[0]) {
829
+ const compHooks = codeBlockContent?.comps?.[compId];
830
+ if (!compHooks)
831
+ return true;
832
+ const index = compHooks.findIndex((hookName) => hookName === hook);
833
+ if (index !== -1) {
834
+ compHooks.splice(index, 1);
835
+ return false;
836
+ }
837
+ }
838
+ });
839
+ }
840
+ this.setCodeDsl(codeDsl);
841
+ }
842
+ getUndeletableList() {
843
+ return this.state.undeletableList;
844
+ }
845
+ async setUndeleteableList(codeIds) {
846
+ this.state.undeletableList = codeIds;
847
+ }
848
+ async deleteCodeDslByIds(codeIds) {
849
+ const currentDsl = await this.getCodeDsl();
850
+ const newDsl = omit(currentDsl, codeIds);
851
+ await this.setCodeDsl(newDsl);
852
+ return newDsl;
853
+ }
854
+ async getUniqueId() {
855
+ const newId = `code_${Math.random().toString(10).substring(2).substring(0, 4)}`;
856
+ const dsl = await this.getCodeDsl();
857
+ const existedIds = keys(dsl);
858
+ if (!existedIds.includes(newId))
859
+ return newId;
860
+ return await this.getUniqueId();
861
+ }
862
+ async deleteCompsInRelation(node) {
863
+ const codeDsl = cloneDeep(await this.getCodeDsl());
864
+ if (!codeDsl)
865
+ return;
866
+ this.recurseNodes(node, codeDsl);
867
+ this.setCodeDsl(codeDsl);
868
+ }
869
+ destroy() {
870
+ this.state.isShowCodeEditor = false;
871
+ this.state.codeDsl = null;
872
+ this.state.id = "";
873
+ this.state.editable = true;
874
+ this.state.mode = CodeEditorMode.EDITOR;
875
+ this.state.combineIds = [];
876
+ this.state.undeletableList = [];
877
+ }
878
+ recurseNodes(node, codeDsl) {
879
+ if (!node.id)
880
+ return;
881
+ forIn(codeDsl, (codeBlockContent) => {
882
+ const compsContent = codeBlockContent.comps || {};
883
+ codeBlockContent.comps = omit(compsContent, node.id);
884
+ });
885
+ if (!isEmpty(node.items)) {
886
+ node.items.forEach((item) => {
887
+ this.recurseNodes(item, codeDsl);
888
+ });
889
+ }
890
+ }
891
+ }
892
+ const codeBlockService = new CodeBlock();
893
+
894
+ class UndoRedo {
895
+ elementList;
896
+ listCursor;
897
+ listMaxSize;
898
+ constructor(listMaxSize = 200) {
899
+ const minListMaxSize = 2;
900
+ this.elementList = [];
901
+ this.listCursor = 0;
902
+ this.listMaxSize = listMaxSize > minListMaxSize ? listMaxSize : minListMaxSize;
903
+ }
904
+ pushElement(element) {
905
+ this.elementList.splice(this.listCursor, this.elementList.length - this.listCursor, cloneDeep(element));
906
+ this.listCursor += 1;
907
+ if (this.elementList.length > this.listMaxSize) {
908
+ this.elementList.shift();
909
+ this.listCursor -= 1;
910
+ }
911
+ }
912
+ canUndo() {
913
+ return this.listCursor > 1;
515
914
  }
516
- usePlugin(options) {
517
- Object.entries(options).forEach(([methodName2, method]) => {
518
- if (typeof method === "function")
519
- this.pluginOptionsList[methodName2].push(method);
520
- });
915
+ undo() {
916
+ if (!this.canUndo()) {
917
+ return null;
918
+ }
919
+ this.listCursor -= 1;
920
+ return this.getCurrentElement();
521
921
  }
522
- async doTask() {
523
- this.doingTask = true;
524
- let task = this.taskList.shift();
525
- while (task) {
526
- await task();
527
- task = this.taskList.shift();
922
+ canRedo() {
923
+ return this.elementList.length > this.listCursor;
924
+ }
925
+ redo() {
926
+ if (!this.canRedo()) {
927
+ return null;
528
928
  }
529
- this.doingTask = false;
929
+ this.listCursor += 1;
930
+ return this.getCurrentElement();
931
+ }
932
+ getCurrentElement() {
933
+ if (this.listCursor < 1) {
934
+ return null;
935
+ }
936
+ return cloneDeep(this.elementList[this.listCursor - 1]);
530
937
  }
531
938
  }
532
939
 
@@ -695,31 +1102,6 @@ class WebStorage extends BaseService {
695
1102
  }
696
1103
  const storageService = new WebStorage();
697
1104
 
698
- var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
699
- ColumnLayout2["LEFT"] = "left";
700
- ColumnLayout2["CENTER"] = "center";
701
- ColumnLayout2["RIGHT"] = "right";
702
- return ColumnLayout2;
703
- })(ColumnLayout || {});
704
- var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
705
- LayerOffset2["TOP"] = "top";
706
- LayerOffset2["BOTTOM"] = "bottom";
707
- return LayerOffset2;
708
- })(LayerOffset || {});
709
- var Layout = /* @__PURE__ */ ((Layout2) => {
710
- Layout2["FLEX"] = "flex";
711
- Layout2["FIXED"] = "fixed";
712
- Layout2["RELATIVE"] = "relative";
713
- Layout2["ABSOLUTE"] = "absolute";
714
- return Layout2;
715
- })(Layout || {});
716
- var Keys = /* @__PURE__ */ ((Keys2) => {
717
- Keys2["ESCAPE"] = "Space";
718
- return Keys2;
719
- })(Keys || {});
720
- const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
721
- const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
722
-
723
1105
  const COPY_STORAGE_KEY = "$MagicEditorCopyData";
724
1106
  const getPageList = (app) => {
725
1107
  if (app.items && Array.isArray(app.items)) {
@@ -1080,7 +1462,9 @@ class Editor$1 extends BaseService {
1080
1462
  "move",
1081
1463
  "undo",
1082
1464
  "redo",
1083
- "highlight"
1465
+ "highlight",
1466
+ "getCodeDsl",
1467
+ "setCodeDsl"
1084
1468
  ],
1085
1469
  ["select", "update", "moveLayer"]
1086
1470
  );
@@ -1305,6 +1689,7 @@ class Editor$1 extends BaseService {
1305
1689
  stage?.select(parent.id);
1306
1690
  }
1307
1691
  this.addModifiedNodeId(parent.id);
1692
+ codeBlockService.deleteCompsInRelation(node);
1308
1693
  }
1309
1694
  async remove(nodeOrNodeList) {
1310
1695
  const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
@@ -1530,6 +1915,17 @@ class Editor$1 extends BaseService {
1530
1915
  resetModifiedNodeId() {
1531
1916
  this.get("modifiedNodeIds").clear();
1532
1917
  }
1918
+ async getCodeDsl() {
1919
+ const root = this.get("root");
1920
+ if (!root)
1921
+ return null;
1922
+ return root.codeBlocks || null;
1923
+ }
1924
+ async setCodeDsl(codeDsl) {
1925
+ if (!this.state.root)
1926
+ return;
1927
+ this.state.root.codeBlocks = codeDsl;
1928
+ }
1533
1929
  addModifiedNodeId(id) {
1534
1930
  if (!this.isHistoryStateChange) {
1535
1931
  this.get("modifiedNodeIds").set(id, id);
@@ -1834,13 +2230,19 @@ const fillConfig = (config = []) => [
1834
2230
  },
1835
2231
  {
1836
2232
  title: "\u9AD8\u7EA7",
1837
- labelWidth: "80px",
2233
+ lazy: true,
1838
2234
  items: [
1839
2235
  {
1840
- type: "code-link",
1841
2236
  name: "created",
1842
2237
  text: "created",
1843
- formTitle: "created"
2238
+ type: "code-select",
2239
+ labelWidth: "100px"
2240
+ },
2241
+ {
2242
+ name: "mounted",
2243
+ text: "mounted",
2244
+ type: "code-select",
2245
+ labelWidth: "100px"
1844
2246
  }
1845
2247
  ]
1846
2248
  }
@@ -1848,32 +2250,6 @@ const fillConfig = (config = []) => [
1848
2250
  }
1849
2251
  ];
1850
2252
 
1851
- const log = (...args) => {
1852
- if (process.env.NODE_ENV === "development") {
1853
- console.log("magic editor: ", ...args);
1854
- }
1855
- };
1856
- const info = (...args) => {
1857
- if (process.env.NODE_ENV === "development") {
1858
- console.info("magic editor: ", ...args);
1859
- }
1860
- };
1861
- const warn = (...args) => {
1862
- if (process.env.NODE_ENV === "development") {
1863
- console.warn("magic editor: ", ...args);
1864
- }
1865
- };
1866
- const debug = (...args) => {
1867
- if (process.env.NODE_ENV === "development") {
1868
- console.debug("magic editor: ", ...args);
1869
- }
1870
- };
1871
- const error = (...args) => {
1872
- if (process.env.NODE_ENV === "development") {
1873
- console.error("magic editor: ", ...args);
1874
- }
1875
- };
1876
-
1877
2253
  const state = reactive({
1878
2254
  uiSelectMode: false,
1879
2255
  showSrc: false,
@@ -2014,52 +2390,47 @@ const useStage = (stageOptions) => {
2014
2390
  return stage;
2015
2391
  };
2016
2392
 
2017
- const _sfc_main$l = defineComponent({
2018
- components: { Plus },
2019
- setup() {
2393
+ const _hoisted_1$b = { class: "m-editor-empty-panel" };
2394
+ const _hoisted_2$5 = { class: "m-editor-empty-content" };
2395
+ const _hoisted_3$2 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2396
+ const _sfc_main$n = /* @__PURE__ */ defineComponent({
2397
+ __name: "AddPageBox",
2398
+ setup(__props) {
2020
2399
  const services = inject("services");
2021
- return {
2022
- clickHandler() {
2023
- const { editorService } = services || {};
2024
- if (!editorService)
2025
- return;
2026
- editorService.add({
2027
- type: NodeType.PAGE,
2028
- name: generatePageNameByApp(toRaw(editorService.get("root")))
2029
- });
2030
- }
2400
+ const clickHandler = () => {
2401
+ const { editorService } = services || {};
2402
+ if (!editorService)
2403
+ return;
2404
+ editorService.add({
2405
+ type: NodeType.PAGE,
2406
+ name: generatePageNameByApp(toRaw(editorService.get("root")))
2407
+ });
2408
+ };
2409
+ return (_ctx, _cache) => {
2410
+ const _component_el_icon = resolveComponent("el-icon");
2411
+ return openBlock(), createElementBlock("div", _hoisted_1$b, [
2412
+ createElementVNode("div", _hoisted_2$5, [
2413
+ createElementVNode("div", {
2414
+ class: "m-editor-empty-button",
2415
+ onClick: clickHandler
2416
+ }, [
2417
+ createElementVNode("div", null, [
2418
+ createVNode(_component_el_icon, null, {
2419
+ default: withCtx(() => [
2420
+ createVNode(unref(Plus))
2421
+ ]),
2422
+ _: 1
2423
+ })
2424
+ ]),
2425
+ _hoisted_3$2
2426
+ ])
2427
+ ])
2428
+ ]);
2031
2429
  };
2032
2430
  }
2033
2431
  });
2034
2432
 
2035
- const _hoisted_1$9 = { class: "m-editor-empty-panel" };
2036
- const _hoisted_2$3 = { class: "m-editor-empty-content" };
2037
- const _hoisted_3 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2038
- function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2039
- const _component_plus = resolveComponent("plus");
2040
- const _component_el_icon = resolveComponent("el-icon");
2041
- return openBlock(), createElementBlock("div", _hoisted_1$9, [
2042
- createElementVNode("div", _hoisted_2$3, [
2043
- createElementVNode("div", {
2044
- class: "m-editor-empty-button",
2045
- onClick: _cache[0] || (_cache[0] = (...args) => _ctx.clickHandler && _ctx.clickHandler(...args))
2046
- }, [
2047
- createElementVNode("div", null, [
2048
- createVNode(_component_el_icon, null, {
2049
- default: withCtx(() => [
2050
- createVNode(_component_plus)
2051
- ]),
2052
- _: 1
2053
- })
2054
- ]),
2055
- _hoisted_3
2056
- ])
2057
- ])
2058
- ]);
2059
- }
2060
- const AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$5]]);
2061
-
2062
- const _sfc_main$k = /* @__PURE__ */ defineComponent({
2433
+ const _sfc_main$m = /* @__PURE__ */ defineComponent({
2063
2434
  __name: "Resizer",
2064
2435
  emits: ["change"],
2065
2436
  setup(__props, { emit }) {
@@ -2092,7 +2463,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2092
2463
  }
2093
2464
  });
2094
2465
 
2095
- const _sfc_main$j = /* @__PURE__ */ defineComponent({
2466
+ const _sfc_main$l = /* @__PURE__ */ defineComponent({
2096
2467
  __name: "Layout",
2097
2468
  props: {
2098
2469
  left: null,
@@ -2155,7 +2526,8 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2155
2526
  return (_ctx, _cache) => {
2156
2527
  return openBlock(), createElementBlock("div", {
2157
2528
  ref_key: "el",
2158
- ref: el
2529
+ ref: el,
2530
+ class: "m-editor-layout"
2159
2531
  }, [
2160
2532
  typeof props.left !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2161
2533
  createElementVNode("div", {
@@ -2164,7 +2536,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2164
2536
  }, [
2165
2537
  renderSlot(_ctx.$slots, "left")
2166
2538
  ], 6),
2167
- createVNode(_sfc_main$k, { onChange: changeLeft })
2539
+ createVNode(_sfc_main$m, { onChange: changeLeft })
2168
2540
  ], 64)) : createCommentVNode("", true),
2169
2541
  createElementVNode("div", {
2170
2542
  class: normalizeClass(["m-editor-layout-center", __props.centerClass]),
@@ -2173,7 +2545,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2173
2545
  renderSlot(_ctx.$slots, "center")
2174
2546
  ], 6),
2175
2547
  typeof props.right !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
2176
- createVNode(_sfc_main$k, { onChange: changeRight }),
2548
+ createVNode(_sfc_main$m, { onChange: changeRight }),
2177
2549
  createElementVNode("div", {
2178
2550
  class: normalizeClass(["m-editor-layout-right", __props.rightClass]),
2179
2551
  style: normalizeStyle(`width: ${__props.right}px`)
@@ -2186,8 +2558,8 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2186
2558
  }
2187
2559
  });
2188
2560
 
2189
- const _hoisted_1$8 = { class: "m-editor" };
2190
- const _sfc_main$i = /* @__PURE__ */ defineComponent({
2561
+ const _hoisted_1$a = { class: "m-editor" };
2562
+ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2191
2563
  __name: "Framework",
2192
2564
  props: {
2193
2565
  codeOptions: { default: () => ({}) }
@@ -2238,7 +2610,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2238
2610
  return (_ctx, _cache) => {
2239
2611
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
2240
2612
  const _component_el_scrollbar = resolveComponent("el-scrollbar");
2241
- return openBlock(), createElementBlock("div", _hoisted_1$8, [
2613
+ return openBlock(), createElementBlock("div", _hoisted_1$a, [
2242
2614
  renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2243
2615
  unref(showSrc) ? (openBlock(), createBlock(_component_magic_code_editor, {
2244
2616
  key: 0,
@@ -2246,7 +2618,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2246
2618
  "init-values": unref(root),
2247
2619
  options: __props.codeOptions,
2248
2620
  onSave: saveCode
2249
- }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$j, {
2621
+ }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$l, {
2250
2622
  key: 1,
2251
2623
  class: "m-editor-content",
2252
2624
  "left-class": "m-editor-framework-left",
@@ -2265,7 +2637,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2265
2637
  ]),
2266
2638
  center: withCtx(() => [
2267
2639
  unref(pageLength) > 0 ? renderSlot(_ctx.$slots, "workspace", { key: 0 }) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
2268
- createVNode(AddPageBox)
2640
+ createVNode(_sfc_main$n)
2269
2641
  ])
2270
2642
  ]),
2271
2643
  _: 2
@@ -2287,8 +2659,8 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2287
2659
  }
2288
2660
  });
2289
2661
 
2290
- const _hoisted_1$7 = ["src"];
2291
- const _sfc_main$h = /* @__PURE__ */ defineComponent({
2662
+ const _hoisted_1$9 = ["src"];
2663
+ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2292
2664
  __name: "Icon",
2293
2665
  props: {
2294
2666
  icon: null
@@ -2309,7 +2681,7 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2309
2681
  class: "magic-editor-icon"
2310
2682
  }, {
2311
2683
  default: withCtx(() => [
2312
- createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$7)
2684
+ createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$9)
2313
2685
  ]),
2314
2686
  _: 1
2315
2687
  })) : typeof __props.icon === "string" ? (openBlock(), createElementBlock("i", {
@@ -2328,12 +2700,12 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2328
2700
  }
2329
2701
  });
2330
2702
 
2331
- const _hoisted_1$6 = {
2703
+ const _hoisted_1$8 = {
2332
2704
  key: 1,
2333
2705
  class: "menu-item-text"
2334
2706
  };
2335
- const _hoisted_2$2 = { class: "el-dropdown-link menubar-menu-button" };
2336
- const _sfc_main$g = /* @__PURE__ */ defineComponent({
2707
+ const _hoisted_2$4 = { class: "el-dropdown-link menubar-menu-button" };
2708
+ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2337
2709
  __name: "ToolButton",
2338
2710
  props: {
2339
2711
  data: { default: () => ({
@@ -2416,7 +2788,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2416
2788
  __props.data.type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
2417
2789
  key: 0,
2418
2790
  direction: __props.data.direction || "vertical"
2419
- }, null, 8, ["direction"])) : __props.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$6, toDisplayString(__props.data.text), 1)) : __props.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2791
+ }, null, 8, ["direction"])) : __props.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$8, toDisplayString(__props.data.text), 1)) : __props.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2420
2792
  __props.data.tooltip ? (openBlock(), createBlock(_component_el_tooltip, {
2421
2793
  key: 0,
2422
2794
  effect: "dark",
@@ -2430,7 +2802,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2430
2802
  disabled: unref(disabled)
2431
2803
  }, {
2432
2804
  default: withCtx(() => [
2433
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$h, {
2805
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$j, {
2434
2806
  key: 0,
2435
2807
  icon: __props.data.icon
2436
2808
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2447,7 +2819,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2447
2819
  disabled: unref(disabled)
2448
2820
  }, {
2449
2821
  default: withCtx(() => [
2450
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$h, {
2822
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$j, {
2451
2823
  key: 0,
2452
2824
  icon: __props.data.icon
2453
2825
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2480,7 +2852,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2480
2852
  })) : createCommentVNode("", true)
2481
2853
  ]),
2482
2854
  default: withCtx(() => [
2483
- createElementVNode("span", _hoisted_2$2, [
2855
+ createElementVNode("span", _hoisted_2$4, [
2484
2856
  createTextVNode(toDisplayString(__props.data.text), 1),
2485
2857
  createVNode(_component_el_icon, { class: "el-icon--right" }, {
2486
2858
  default: withCtx(() => [
@@ -2497,7 +2869,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2497
2869
  }
2498
2870
  });
2499
2871
 
2500
- const _sfc_main$f = /* @__PURE__ */ defineComponent({
2872
+ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2501
2873
  __name: "NavMenu",
2502
2874
  props: {
2503
2875
  data: { default: () => ({}) },
@@ -2653,7 +3025,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2653
3025
  style: normalizeStyle(`width: ${unref(columnWidth)?.[key]}px`)
2654
3026
  }, [
2655
3027
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(buttons)[key], (item, index) => {
2656
- return openBlock(), createBlock(_sfc_main$g, {
3028
+ return openBlock(), createBlock(_sfc_main$i, {
2657
3029
  data: item,
2658
3030
  key: index
2659
3031
  }, null, 8, ["data"]);
@@ -2665,8 +3037,8 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2665
3037
  }
2666
3038
  });
2667
3039
 
2668
- const _hoisted_1$5 = { class: "`m-editor-props-panel" };
2669
- const _sfc_main$e = /* @__PURE__ */ defineComponent({
3040
+ const _hoisted_1$7 = { class: "m-editor-props-panel" };
3041
+ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2670
3042
  __name: "PropsPanel",
2671
3043
  emits: ["mounted"],
2672
3044
  setup(__props, { expose, emit }) {
@@ -2683,50 +3055,545 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
2683
3055
  curFormConfig.value = [];
2684
3056
  return;
2685
3057
  }
2686
- const type = node.value.type || (node.value.items ? "container" : "text");
2687
- curFormConfig.value = await services?.propsService.getPropsConfig(type) || [];
2688
- values.value = node.value;
3058
+ const type = node.value.type || (node.value.items ? "container" : "text");
3059
+ curFormConfig.value = await services?.propsService.getPropsConfig(type) || [];
3060
+ values.value = node.value;
3061
+ };
3062
+ watchEffect(init);
3063
+ services?.propsService.on("props-configs-change", init);
3064
+ onMounted(() => {
3065
+ emit("mounted", internalInstance);
3066
+ });
3067
+ watchEffect(() => {
3068
+ if (configForm.value && stage.value) {
3069
+ configForm.value.formState.stage = stage.value;
3070
+ }
3071
+ });
3072
+ const submit = async () => {
3073
+ try {
3074
+ const values2 = await configForm.value?.submitForm();
3075
+ services?.editorService.update(values2);
3076
+ } catch (e) {
3077
+ console.error(e);
3078
+ ElMessage.closeAll();
3079
+ ElMessage.error({
3080
+ duration: 1e4,
3081
+ showClose: true,
3082
+ message: e.message,
3083
+ dangerouslyUseHTMLString: true
3084
+ });
3085
+ }
3086
+ };
3087
+ expose({ submit });
3088
+ return (_ctx, _cache) => {
3089
+ const _component_m_form = resolveComponent("m-form");
3090
+ return openBlock(), createElementBlock("div", _hoisted_1$7, [
3091
+ renderSlot(_ctx.$slots, "props-panel-header"),
3092
+ createVNode(_component_m_form, {
3093
+ ref_key: "configForm",
3094
+ ref: configForm,
3095
+ class: normalizeClass(`m-editor-props-panel ${unref(propsPanelSize)}`),
3096
+ "popper-class": `m-editor-props-panel-popper ${unref(propsPanelSize)}`,
3097
+ size: unref(propsPanelSize),
3098
+ "init-values": values.value,
3099
+ config: curFormConfig.value,
3100
+ onChange: submit
3101
+ }, null, 8, ["class", "popper-class", "size", "init-values", "config"])
3102
+ ]);
3103
+ };
3104
+ }
3105
+ });
3106
+
3107
+ const _hoisted_1$6 = ["id"];
3108
+ const _hoisted_2$3 = { class: "list-item" };
3109
+ const _hoisted_3$1 = { class: "code-name" };
3110
+ const _hoisted_4$1 = { class: "code-name-wrapper" };
3111
+ const _hoisted_5$1 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u4EE3\u7801\u5757\u540D\u79F0", -1);
3112
+ const _hoisted_6$1 = { class: "m-editor-wrapper" };
3113
+ const _hoisted_7$1 = {
3114
+ key: 1,
3115
+ class: "m-editor-content-bottom"
3116
+ };
3117
+ const _hoisted_8$1 = /* @__PURE__ */ createTextVNode("\u4FDD\u5B58");
3118
+ const _hoisted_9$1 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3119
+ const _hoisted_10 = {
3120
+ key: 2,
3121
+ class: "m-editor-content-bottom"
3122
+ };
3123
+ const _hoisted_11 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3124
+ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3125
+ __name: "CodeBlockEditor",
3126
+ setup(__props) {
3127
+ const services = inject("services");
3128
+ const codeEditor = ref();
3129
+ const left = ref(200);
3130
+ const currentTitle = ref("");
3131
+ const codeConfig = ref(null);
3132
+ const state = reactive({
3133
+ codeList: []
3134
+ });
3135
+ const isShowCodeBlockEditor = computed(
3136
+ () => codeConfig.value && services?.codeBlockService.getCodeEditorShowStatus() || false
3137
+ );
3138
+ const mode = computed(() => services?.codeBlockService.getMode());
3139
+ const id = computed(() => services?.codeBlockService.getId() || "");
3140
+ const editable = computed(() => services?.codeBlockService.getEditStatus());
3141
+ const selectedIds = computed(() => services?.codeBlockService.getCombineIds() || []);
3142
+ watchEffect(async () => {
3143
+ codeConfig.value = await services?.codeBlockService.getCodeContentById(id.value) || null;
3144
+ });
3145
+ watchEffect(async () => {
3146
+ const codeDsl = await services?.codeBlockService.getCodeDslByIds(selectedIds.value) || null;
3147
+ if (!codeDsl)
3148
+ return;
3149
+ state.codeList = [];
3150
+ forIn(codeDsl, (value, key) => {
3151
+ state.codeList.push({
3152
+ id: key,
3153
+ name: value.name
3154
+ });
3155
+ });
3156
+ currentTitle.value = state.codeList[0]?.name || "";
3157
+ });
3158
+ const saveCode = async () => {
3159
+ if (!codeEditor.value || !codeConfig.value || !editable.value)
3160
+ return true;
3161
+ try {
3162
+ const codeContent = codeEditor.value.getEditor()?.getValue();
3163
+ codeConfig.value.content = eval(codeContent);
3164
+ } catch (e) {
3165
+ ElMessage.error(e.stack);
3166
+ return false;
3167
+ }
3168
+ await services?.codeBlockService.setCodeDslById(id.value, {
3169
+ name: codeConfig.value.name,
3170
+ content: codeConfig.value.content
3171
+ });
3172
+ ElMessage.success("\u4EE3\u7801\u4FDD\u5B58\u6210\u529F");
3173
+ return true;
3174
+ };
3175
+ const saveAndClose = async () => {
3176
+ const saveRes = await saveCode();
3177
+ if (saveRes) {
3178
+ await services?.codeBlockService.setCodeEditorShowStatus(false);
3179
+ }
3180
+ };
3181
+ const selectHandler = (data) => {
3182
+ services?.codeBlockService.setId(data.id);
3183
+ currentTitle.value = data.name;
3184
+ };
3185
+ return (_ctx, _cache) => {
3186
+ const _component_el_tree = resolveComponent("el-tree");
3187
+ const _component_el_input = resolveComponent("el-input");
3188
+ const _component_el_button = resolveComponent("el-button");
3189
+ const _component_el_card = resolveComponent("el-card");
3190
+ const _component_el_dialog = resolveComponent("el-dialog");
3191
+ return openBlock(), createBlock(_component_el_dialog, {
3192
+ modelValue: unref(isShowCodeBlockEditor),
3193
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(isShowCodeBlockEditor) ? isShowCodeBlockEditor.value = $event : null),
3194
+ class: "code-editor-dialog",
3195
+ title: currentTitle.value,
3196
+ fullscreen: true,
3197
+ "before-close": saveAndClose,
3198
+ "append-to-body": true
3199
+ }, {
3200
+ default: withCtx(() => [
3201
+ createVNode(_sfc_main$l, {
3202
+ left: left.value,
3203
+ "onUpdate:left": _cache[1] || (_cache[1] = ($event) => left.value = $event),
3204
+ "min-left": 45,
3205
+ class: "code-editor-layout"
3206
+ }, createSlots({
3207
+ center: withCtx(() => [
3208
+ !unref(isEmpty)(codeConfig.value) ? (openBlock(), createElementBlock("div", {
3209
+ key: 0,
3210
+ class: normalizeClass([
3211
+ unref(mode) === unref(CodeEditorMode).LIST ? "m-editor-code-block-editor-panel-list-mode" : "m-editor-code-block-editor-panel"
3212
+ ])
3213
+ }, [
3214
+ renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id: unref(id) }),
3215
+ createVNode(_component_el_card, { shadow: "never" }, {
3216
+ header: withCtx(() => [
3217
+ createElementVNode("div", _hoisted_4$1, [
3218
+ _hoisted_5$1,
3219
+ codeConfig.value ? (openBlock(), createBlock(_component_el_input, {
3220
+ key: 0,
3221
+ class: "code-name-input",
3222
+ modelValue: codeConfig.value.name,
3223
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeConfig.value.name = $event),
3224
+ disabled: !unref(editable)
3225
+ }, null, 8, ["modelValue", "disabled"])) : createCommentVNode("", true)
3226
+ ])
3227
+ ]),
3228
+ default: withCtx(() => [
3229
+ createElementVNode("div", _hoisted_6$1, [
3230
+ codeConfig.value ? (openBlock(), createBlock(_sfc_main$o, {
3231
+ key: 0,
3232
+ ref_key: "codeEditor",
3233
+ ref: codeEditor,
3234
+ class: "m-editor-container",
3235
+ "init-values": `${codeConfig.value.content}`,
3236
+ onSave: saveCode,
3237
+ options: {
3238
+ tabSize: 2,
3239
+ fontSize: 16,
3240
+ formatOnPaste: true,
3241
+ readOnly: !unref(editable)
3242
+ }
3243
+ }, null, 8, ["init-values", "options"])) : createCommentVNode("", true),
3244
+ unref(editable) ? (openBlock(), createElementBlock("div", _hoisted_7$1, [
3245
+ createVNode(_component_el_button, {
3246
+ type: "primary",
3247
+ class: "button",
3248
+ onClick: saveCode
3249
+ }, {
3250
+ default: withCtx(() => [
3251
+ _hoisted_8$1
3252
+ ]),
3253
+ _: 1
3254
+ }),
3255
+ createVNode(_component_el_button, {
3256
+ type: "primary",
3257
+ class: "button",
3258
+ onClick: saveAndClose
3259
+ }, {
3260
+ default: withCtx(() => [
3261
+ _hoisted_9$1
3262
+ ]),
3263
+ _: 1
3264
+ })
3265
+ ])) : (openBlock(), createElementBlock("div", _hoisted_10, [
3266
+ createVNode(_component_el_button, {
3267
+ type: "primary",
3268
+ class: "button",
3269
+ onClick: saveAndClose
3270
+ }, {
3271
+ default: withCtx(() => [
3272
+ _hoisted_11
3273
+ ]),
3274
+ _: 1
3275
+ })
3276
+ ]))
3277
+ ])
3278
+ ]),
3279
+ _: 1
3280
+ })
3281
+ ], 2)) : createCommentVNode("", true)
3282
+ ]),
3283
+ _: 2
3284
+ }, [
3285
+ unref(mode) === unref(CodeEditorMode).LIST ? {
3286
+ name: "left",
3287
+ fn: withCtx(() => [
3288
+ !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(_component_el_tree, {
3289
+ key: 0,
3290
+ ref: "tree",
3291
+ "node-key": "id",
3292
+ "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3293
+ data: state.codeList,
3294
+ "highlight-current": true,
3295
+ onNodeClick: selectHandler,
3296
+ "current-node-key": state.codeList[0].id,
3297
+ class: "side-tree"
3298
+ }, {
3299
+ default: withCtx(({ data }) => [
3300
+ createElementVNode("div", {
3301
+ id: data.id,
3302
+ class: "list-container"
3303
+ }, [
3304
+ createElementVNode("div", _hoisted_2$3, [
3305
+ createElementVNode("div", _hoisted_3$1, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1)
3306
+ ])
3307
+ ], 8, _hoisted_1$6)
3308
+ ]),
3309
+ _: 1
3310
+ }, 8, ["data", "current-node-key"])) : createCommentVNode("", true)
3311
+ ])
3312
+ } : void 0
3313
+ ]), 1032, ["left"])
3314
+ ]),
3315
+ _: 3
3316
+ }, 8, ["modelValue", "title"]);
3317
+ };
3318
+ }
3319
+ });
3320
+
3321
+ const _hoisted_1$5 = { class: "m-editor-code-block-list" };
3322
+ const _hoisted_2$2 = { class: "code-header-wrapper" };
3323
+ const _hoisted_3 = /* @__PURE__ */ createTextVNode("\u65B0\u589E");
3324
+ const _hoisted_4 = ["id"];
3325
+ const _hoisted_5 = { class: "list-item" };
3326
+ const _hoisted_6 = { class: "code-name" };
3327
+ const _hoisted_7 = { class: "right-tool" };
3328
+ const _hoisted_8 = {
3329
+ key: 0,
3330
+ class: "code-comp-map-wrapper"
3331
+ };
3332
+ const _hoisted_9 = /* @__PURE__ */ createElementVNode("svg", {
3333
+ class: "arrow-left",
3334
+ viewBox: "0 0 1024 1024",
3335
+ xmlns: "http://www.w3.org/2000/svg",
3336
+ "data-v-029747aa": ""
3337
+ }, [
3338
+ /* @__PURE__ */ createElementVNode("path", {
3339
+ fill: "currentColor",
3340
+ d: "M609.408 149.376 277.76 489.6a32 32 0 0 0 0 44.672l331.648 340.352a29.12 29.12 0 0 0 41.728 0 30.592 30.592 0 0 0 0-42.752L339.264 511.936l311.872-319.872a30.592 30.592 0 0 0 0-42.688 29.12 29.12 0 0 0-41.728 0z"
3341
+ })
3342
+ ], -1);
3343
+ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3344
+ __name: "CodeBlockList",
3345
+ props: {
3346
+ customError: null
3347
+ },
3348
+ setup(__props) {
3349
+ const props = __props;
3350
+ const services = inject("services");
3351
+ const state = reactive({
3352
+ codeList: [],
3353
+ bindComps: {}
3354
+ });
3355
+ const editable = computed(() => services?.codeBlockService.getEditStatus());
3356
+ const getBindCompsByCodeId = (codeId, codeBlockContent) => {
3357
+ if (isEmpty(codeBlockContent) || isEmpty(codeBlockContent.comps)) {
3358
+ state.bindComps[codeId] = [];
3359
+ return;
3360
+ }
3361
+ const compsField = codeBlockContent.comps;
3362
+ const bindCompIds = Object.keys(compsField);
3363
+ const bindCompsFiltered = bindCompIds.filter((compId) => !isEmpty(compsField[compId]));
3364
+ const compsInfo = bindCompsFiltered.map((compId) => ({
3365
+ id: compId,
3366
+ name: getCompName(compId)
3367
+ }));
3368
+ state.bindComps[codeId] = compsInfo;
3369
+ };
3370
+ const initList = async () => {
3371
+ const codeDsl = await services?.codeBlockService.getCodeDsl() || null;
3372
+ if (!codeDsl)
3373
+ return;
3374
+ state.codeList = [];
3375
+ forIn(codeDsl, (value, codeId) => {
3376
+ getBindCompsByCodeId(codeId, value);
3377
+ state.codeList.push({
3378
+ id: codeId,
3379
+ name: value.name,
3380
+ codeBlockContent: value,
3381
+ showRelation: true
3382
+ });
3383
+ });
3384
+ };
3385
+ watch(
3386
+ () => services?.codeBlockService.getCodeDsl(),
3387
+ () => {
3388
+ initList();
3389
+ },
3390
+ {
3391
+ immediate: true,
3392
+ deep: true
3393
+ }
3394
+ );
3395
+ watch(
3396
+ () => services?.editorService.get("node"),
3397
+ (curNode) => {
3398
+ if (!curNode?.id)
3399
+ return;
3400
+ forIn(state.bindComps, (bindCompInfo) => {
3401
+ bindCompInfo.forEach((comp) => {
3402
+ if (comp.id === curNode.id) {
3403
+ comp.name = curNode.name;
3404
+ }
3405
+ });
3406
+ });
3407
+ }
3408
+ );
3409
+ const createCodeBlock = async () => {
3410
+ const { codeBlockService } = services || {};
3411
+ if (!codeBlockService) {
3412
+ ElMessage.error("\u65B0\u589E\u4EE3\u7801\u5757\u5931\u8D25");
3413
+ return;
3414
+ }
3415
+ const codeConfig = {
3416
+ name: "\u4EE3\u7801\u5757",
3417
+ content: `() => {
3418
+ // place your code here
3419
+ }`
3420
+ };
3421
+ await codeBlockService.setMode(CodeEditorMode.EDITOR);
3422
+ const id = await codeBlockService.getUniqueId();
3423
+ await codeBlockService.setCodeDslById(id, codeConfig);
3424
+ codeBlockService.setCodeEditorContent(true, id);
2689
3425
  };
2690
- watchEffect(init);
2691
- services?.propsService.on("props-configs-change", init);
2692
- onMounted(() => {
2693
- emit("mounted", internalInstance);
2694
- });
2695
- watchEffect(() => {
2696
- if (configForm.value && stage.value) {
2697
- configForm.value.formState.stage = stage.value;
3426
+ const editCode = async (key) => {
3427
+ await services?.codeBlockService.setMode(CodeEditorMode.EDITOR);
3428
+ services?.codeBlockService.setCodeEditorContent(true, key);
3429
+ };
3430
+ const deleteCode = (key) => {
3431
+ const existBinds = !!(state.bindComps[key]?.length > 0);
3432
+ const undeleteableList = services?.codeBlockService.getUndeletableList() || [];
3433
+ if (!existBinds && !undeleteableList.includes(key)) {
3434
+ services?.codeBlockService.deleteCodeDslByIds([key]);
3435
+ } else {
3436
+ if (typeof props.customError === "function") {
3437
+ props.customError(key, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
3438
+ } else {
3439
+ ElMessage.error("\u4EE3\u7801\u5757\u5220\u9664\u5931\u8D25");
3440
+ }
2698
3441
  }
2699
- });
2700
- const submit = async () => {
2701
- try {
2702
- const values2 = await configForm.value?.submitForm();
2703
- services?.editorService.update(values2);
2704
- } catch (e) {
2705
- console.error(e);
2706
- ElMessage.closeAll();
2707
- ElMessage.error({
2708
- duration: 1e4,
2709
- showClose: true,
2710
- message: e.message,
2711
- dangerouslyUseHTMLString: true
2712
- });
3442
+ };
3443
+ const filterText = ref("");
3444
+ const tree = ref();
3445
+ const filterNode = (value, data) => {
3446
+ if (!value) {
3447
+ return true;
2713
3448
  }
3449
+ return `${data.name}${data.id}`.indexOf(value) !== -1;
3450
+ };
3451
+ const filterTextChangeHandler = (val) => {
3452
+ tree.value?.filter(val);
3453
+ };
3454
+ const toggleCombineRelation = (data) => {
3455
+ const { id } = data;
3456
+ const currentCode = state.codeList.find((item) => item.id === id);
3457
+ if (!currentCode)
3458
+ return;
3459
+ currentCode.showRelation = !currentCode?.showRelation;
3460
+ };
3461
+ const getCompName = (compId) => {
3462
+ const node = services?.editorService.getNodeById(compId);
3463
+ return node?.name || String(compId);
3464
+ };
3465
+ const selectComp = (compId) => {
3466
+ const stage = services?.editorService.get("stage");
3467
+ services?.editorService.select(compId);
3468
+ stage?.select(compId);
2714
3469
  };
2715
- expose({ submit });
2716
3470
  return (_ctx, _cache) => {
2717
- const _component_m_form = resolveComponent("m-form");
3471
+ const _component_el_input = resolveComponent("el-input");
3472
+ const _component_el_button = resolveComponent("el-button");
3473
+ const _component_el_tooltip = resolveComponent("el-tooltip");
3474
+ const _component_el_tree = resolveComponent("el-tree");
2718
3475
  return openBlock(), createElementBlock("div", _hoisted_1$5, [
2719
- renderSlot(_ctx.$slots, "props-panel-header"),
2720
- createVNode(_component_m_form, {
2721
- ref_key: "configForm",
2722
- ref: configForm,
2723
- class: normalizeClass(`m-editor-props-panel ${unref(propsPanelSize)}`),
2724
- "popper-class": `m-editor-props-panel-popper ${unref(propsPanelSize)}`,
2725
- size: unref(propsPanelSize),
2726
- "init-values": values.value,
2727
- config: curFormConfig.value,
2728
- onChange: submit
2729
- }, null, 8, ["class", "popper-class", "size", "init-values", "config"])
3476
+ renderSlot(_ctx.$slots, "code-block-panel-header", {}, () => [
3477
+ createElementVNode("div", _hoisted_2$2, [
3478
+ createVNode(_component_el_input, {
3479
+ class: normalizeClass([unref(editable) ? "code-filter-input" : "code-filter-input-no-btn"]),
3480
+ size: "small",
3481
+ placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
3482
+ clearable: "",
3483
+ modelValue: filterText.value,
3484
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => filterText.value = $event),
3485
+ onInput: filterTextChangeHandler
3486
+ }, null, 8, ["class", "modelValue"]),
3487
+ unref(editable) ? (openBlock(), createBlock(_component_el_button, {
3488
+ key: 0,
3489
+ class: "create-code-button",
3490
+ type: "primary",
3491
+ size: "small",
3492
+ onClick: createCodeBlock
3493
+ }, {
3494
+ default: withCtx(() => [
3495
+ _hoisted_3
3496
+ ]),
3497
+ _: 1
3498
+ })) : createCommentVNode("", true)
3499
+ ])
3500
+ ]),
3501
+ !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(_component_el_tree, {
3502
+ key: 0,
3503
+ ref_key: "tree",
3504
+ ref: tree,
3505
+ "node-key": "id",
3506
+ "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3507
+ data: state.codeList,
3508
+ "highlight-current": true,
3509
+ "filter-node-method": filterNode,
3510
+ onNodeClick: toggleCombineRelation
3511
+ }, {
3512
+ default: withCtx(({ data }) => [
3513
+ createElementVNode("div", {
3514
+ id: data.id,
3515
+ class: "list-container"
3516
+ }, [
3517
+ createElementVNode("div", _hoisted_5, [
3518
+ createElementVNode("div", _hoisted_6, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1),
3519
+ createElementVNode("div", _hoisted_7, [
3520
+ createVNode(_component_el_tooltip, {
3521
+ effect: "dark",
3522
+ content: unref(editable) ? "\u7F16\u8F91" : "\u67E5\u770B",
3523
+ placement: "bottom"
3524
+ }, {
3525
+ default: withCtx(() => [
3526
+ createVNode(_sfc_main$j, {
3527
+ icon: unref(editable) ? unref(Edit) : unref(View),
3528
+ class: "edit-icon",
3529
+ onClick: withModifiers(($event) => editCode(`${data.id}`), ["stop"])
3530
+ }, null, 8, ["icon", "onClick"])
3531
+ ]),
3532
+ _: 2
3533
+ }, 1032, ["content"]),
3534
+ state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createBlock(_component_el_tooltip, {
3535
+ key: 0,
3536
+ effect: "dark",
3537
+ content: "\u67E5\u770B\u7ED1\u5B9A\u5173\u7CFB",
3538
+ placement: "bottom"
3539
+ }, {
3540
+ default: withCtx(() => [
3541
+ createVNode(_sfc_main$j, {
3542
+ icon: unref(Link),
3543
+ class: "edit-icon",
3544
+ onClick: withModifiers(($event) => toggleCombineRelation(data), ["stop"])
3545
+ }, null, 8, ["icon", "onClick"])
3546
+ ]),
3547
+ _: 2
3548
+ }, 1024)) : createCommentVNode("", true),
3549
+ unref(editable) ? (openBlock(), createBlock(_component_el_tooltip, {
3550
+ key: 1,
3551
+ effect: "dark",
3552
+ content: "\u5220\u9664",
3553
+ placement: "bottom"
3554
+ }, {
3555
+ default: withCtx(() => [
3556
+ createVNode(_sfc_main$j, {
3557
+ icon: unref(Close),
3558
+ class: "edit-icon",
3559
+ onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
3560
+ }, null, 8, ["icon", "onClick"])
3561
+ ]),
3562
+ _: 2
3563
+ }, 1024)) : createCommentVNode("", true),
3564
+ renderSlot(_ctx.$slots, "code-block-panel-tool", {
3565
+ id: data.id,
3566
+ data: data.codeBlockContent
3567
+ })
3568
+ ])
3569
+ ]),
3570
+ data.showRelation && state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
3571
+ _hoisted_9,
3572
+ (openBlock(true), createElementBlock(Fragment, null, renderList(state.bindComps[data.id], (comp, index) => {
3573
+ return openBlock(), createBlock(_component_el_button, {
3574
+ key: index,
3575
+ class: "code-comp",
3576
+ size: "small",
3577
+ plain: true,
3578
+ onClick: withModifiers(($event) => selectComp(comp.id), ["stop"])
3579
+ }, {
3580
+ default: withCtx(() => [
3581
+ createTextVNode(toDisplayString(comp.name), 1)
3582
+ ]),
3583
+ _: 2
3584
+ }, 1032, ["onClick"]);
3585
+ }), 128))
3586
+ ])) : createCommentVNode("", true)
3587
+ ], 8, _hoisted_4)
3588
+ ]),
3589
+ _: 3
3590
+ }, 8, ["data"])) : createCommentVNode("", true),
3591
+ createVNode(_sfc_main$f, null, {
3592
+ "code-block-edit-panel-header": withCtx(({ id }) => [
3593
+ renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
3594
+ ]),
3595
+ _: 3
3596
+ })
2730
3597
  ]);
2731
3598
  };
2732
3599
  }
@@ -2844,7 +3711,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2844
3711
  onDrag: dragHandler
2845
3712
  }, [
2846
3713
  renderSlot(_ctx.$slots, "component-list-item", { component: item }, () => [
2847
- createVNode(_sfc_main$h, {
3714
+ createVNode(_sfc_main$j, {
2848
3715
  icon: item.icon
2849
3716
  }, null, 8, ["icon"]),
2850
3717
  createVNode(_component_el_tooltip, {
@@ -2964,7 +3831,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
2964
3831
  }, [
2965
3832
  createElementVNode("div", null, [
2966
3833
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.menuData, (item, index) => {
2967
- return openBlock(), createBlock(_sfc_main$g, {
3834
+ return openBlock(), createBlock(_sfc_main$i, {
2968
3835
  "event-type": "mouseup",
2969
3836
  data: item,
2970
3837
  key: index,
@@ -2988,9 +3855,9 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
2988
3855
  }
2989
3856
  });
2990
3857
 
2991
- const _sfc_main$b = defineComponent({
2992
- components: { ContentMenu: _sfc_main$c },
2993
- setup() {
3858
+ const _sfc_main$b = /* @__PURE__ */ defineComponent({
3859
+ __name: "LayerMenu",
3860
+ setup(__props, { expose }) {
2994
3861
  const services = inject("services");
2995
3862
  const menu = ref();
2996
3863
  const node = computed(() => services?.editorService.get("node"));
@@ -3041,53 +3908,51 @@ const _sfc_main$b = defineComponent({
3041
3908
  }
3042
3909
  return [];
3043
3910
  });
3044
- return {
3045
- menu,
3046
- menuData: computed(() => [
3047
- {
3048
- type: "button",
3049
- text: "\u65B0\u589E",
3050
- icon: markRaw(Plus),
3051
- display: () => node.value?.items,
3052
- items: getSubMenuData.value
3053
- },
3054
- {
3055
- type: "button",
3056
- text: "\u590D\u5236",
3057
- icon: markRaw(DocumentCopy),
3058
- display: () => !isRoot.value,
3059
- handler: () => {
3060
- node.value && services?.editorService.copy(node.value);
3061
- }
3062
- },
3063
- {
3064
- type: "button",
3065
- text: "\u5220\u9664",
3066
- icon: markRaw(Delete),
3067
- display: () => !isRoot.value && !isPage.value,
3068
- handler: () => {
3069
- node.value && services?.editorService.remove(node.value);
3070
- }
3071
- },
3072
- ...layerContentMenu
3073
- ]),
3074
- show(e) {
3075
- menu.value?.show(e);
3076
- }
3911
+ const menuData = computed(() => [
3912
+ {
3913
+ type: "button",
3914
+ text: "\u65B0\u589E",
3915
+ icon: markRaw(Plus),
3916
+ display: () => node.value?.items,
3917
+ items: getSubMenuData.value
3918
+ },
3919
+ {
3920
+ type: "button",
3921
+ text: "\u590D\u5236",
3922
+ icon: markRaw(DocumentCopy),
3923
+ display: () => !isRoot.value,
3924
+ handler: () => {
3925
+ node.value && services?.editorService.copy(node.value);
3926
+ }
3927
+ },
3928
+ {
3929
+ type: "button",
3930
+ text: "\u5220\u9664",
3931
+ icon: markRaw(Delete),
3932
+ display: () => !isRoot.value && !isPage.value,
3933
+ handler: () => {
3934
+ node.value && services?.editorService.remove(node.value);
3935
+ }
3936
+ },
3937
+ ...layerContentMenu
3938
+ ]);
3939
+ const show = (e) => {
3940
+ menu.value?.show(e);
3941
+ };
3942
+ expose({
3943
+ show
3944
+ });
3945
+ return (_ctx, _cache) => {
3946
+ return openBlock(), createBlock(_sfc_main$c, {
3947
+ "menu-data": unref(menuData),
3948
+ ref_key: "menu",
3949
+ ref: menu,
3950
+ style: { "overflow": "initial" }
3951
+ }, null, 8, ["menu-data"]);
3077
3952
  };
3078
3953
  }
3079
3954
  });
3080
3955
 
3081
- function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3082
- const _component_content_menu = resolveComponent("content-menu");
3083
- return openBlock(), createBlock(_component_content_menu, {
3084
- "menu-data": _ctx.menuData,
3085
- ref: "menu",
3086
- style: { "overflow": "initial" }
3087
- }, null, 8, ["menu-data"]);
3088
- }
3089
- const LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$4]]);
3090
-
3091
3956
  const throttleTime = 150;
3092
3957
  const select = async (data, editorService) => {
3093
3958
  if (!data.id) {
@@ -3215,7 +4080,7 @@ const useFilter = (tree) => ({
3215
4080
  });
3216
4081
  const _sfc_main$a = defineComponent({
3217
4082
  name: "magic-editor-layer-panel",
3218
- components: { LayerMenu },
4083
+ components: { LayerMenu: _sfc_main$b },
3219
4084
  setup() {
3220
4085
  const services = inject("services");
3221
4086
  const tree = ref();
@@ -3263,8 +4128,16 @@ const _sfc_main$a = defineComponent({
3263
4128
  }
3264
4129
  });
3265
4130
 
4131
+ const _export_sfc = (sfc, props) => {
4132
+ const target = sfc.__vccOpts || sfc;
4133
+ for (const [key, val] of props) {
4134
+ target[key] = val;
4135
+ }
4136
+ return target;
4137
+ };
4138
+
3266
4139
  const _hoisted_1$3 = ["id", "onMouseenter"];
3267
- function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
4140
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
3268
4141
  const _component_el_input = resolveComponent("el-input");
3269
4142
  const _component_el_tree = resolveComponent("el-tree");
3270
4143
  const _component_layer_menu = resolveComponent("layer-menu");
@@ -3328,190 +4201,232 @@ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3328
4201
  _: 3
3329
4202
  });
3330
4203
  }
3331
- const LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$3]]);
3332
-
3333
- const _sfc_main$9 = defineComponent({
3334
- components: { MIcon: _sfc_main$h },
3335
- props: {
3336
- data: {
3337
- type: [Object, String]
3338
- }
3339
- },
3340
- setup(props) {
3341
- return {
3342
- config: computed(() => {
3343
- if (typeof props.data !== "string") {
3344
- return props.data;
3345
- }
3346
- switch (props.data) {
3347
- case "component-list":
3348
- return {
3349
- type: "component",
3350
- icon: Coin,
3351
- text: "\u7EC4\u4EF6",
3352
- component: _sfc_main$d,
3353
- slots: {}
3354
- };
3355
- case "layer":
3356
- return {
3357
- type: "component",
3358
- icon: Files,
3359
- text: "\u5DF2\u9009\u7EC4\u4EF6",
3360
- component: LayerPanel,
3361
- slots: {}
3362
- };
3363
- default:
3364
- return void 0;
3365
- }
3366
- })
3367
- };
3368
- }
3369
- });
4204
+ const LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$1]]);
3370
4205
 
3371
4206
  const _hoisted_1$2 = {
3372
4207
  key: 1,
3373
4208
  class: "magic-editor-tab-panel-title"
3374
4209
  };
3375
- function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
3376
- const _component_m_icon = resolveComponent("m-icon");
3377
- const _component_el_tab_pane = resolveComponent("el-tab-pane");
3378
- return _ctx.config ? (openBlock(), createBlock(_component_el_tab_pane, {
3379
- key: 0,
3380
- name: _ctx.config.text
3381
- }, {
3382
- label: withCtx(() => [
3383
- (openBlock(), createElementBlock("div", {
3384
- key: _ctx.config.text
3385
- }, [
3386
- _ctx.config.icon ? (openBlock(), createBlock(_component_m_icon, {
3387
- key: 0,
3388
- icon: _ctx.config.icon
3389
- }, null, 8, ["icon"])) : createCommentVNode("", true),
3390
- _ctx.config.text ? (openBlock(), createElementBlock("div", _hoisted_1$2, toDisplayString(_ctx.config.text), 1)) : createCommentVNode("", true)
3391
- ]))
3392
- ]),
3393
- default: withCtx(() => [
3394
- (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.component), mergeProps(_ctx.config.props || {}, toHandlers(_ctx.config?.listeners || {})), createSlots({ _: 2 }, [
3395
- _ctx.data === "component-list" || _ctx.config.slots?.componentListPanelHeader ? {
3396
- name: "component-list-panel-header",
3397
- fn: withCtx(() => [
3398
- _ctx.data === "component-list" ? renderSlot(_ctx.$slots, "component-list-panel-header", { key: 0 }) : _ctx.config.slots?.componentListPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots.componentListPanelHeader), { key: 1 })) : createCommentVNode("", true)
3399
- ])
3400
- } : void 0,
3401
- _ctx.data === "component-list" || _ctx.config.slots?.componentListItem ? {
3402
- name: "component-list-item",
3403
- fn: withCtx(({ component }) => [
3404
- _ctx.data === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
3405
- key: 0,
3406
- component
3407
- }) : _ctx.config.slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots.componentListItem), {
3408
- key: 1,
3409
- component
3410
- }, null, 8, ["component"])) : createCommentVNode("", true)
3411
- ])
3412
- } : void 0,
3413
- _ctx.data === "layer" || _ctx.config.slots?.layerPanelHeader ? {
3414
- name: "layer-panel-header",
3415
- fn: withCtx(() => [
3416
- _ctx.data === "layer" ? renderSlot(_ctx.$slots, "layer-panel-header", { key: 0 }) : _ctx.config.slots?.layerPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots.layerPanelHeader), { key: 1 })) : createCommentVNode("", true)
3417
- ])
3418
- } : void 0,
3419
- _ctx.data === "layer" || _ctx.config.slots?.layerNodeContent ? {
3420
- name: "layer-node-content",
3421
- fn: withCtx(({ data: nodeData, node }) => [
3422
- _ctx.data === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
4210
+ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
4211
+ __name: "TabPane",
4212
+ props: {
4213
+ data: null
4214
+ },
4215
+ setup(__props) {
4216
+ const props = __props;
4217
+ const config = computed(() => {
4218
+ if (typeof props.data !== "string") {
4219
+ return props.data;
4220
+ }
4221
+ switch (props.data) {
4222
+ case "component-list":
4223
+ return {
4224
+ type: "component",
4225
+ icon: Coin,
4226
+ text: "\u7EC4\u4EF6",
4227
+ component: _sfc_main$d,
4228
+ slots: {}
4229
+ };
4230
+ case "layer":
4231
+ return {
4232
+ type: "component",
4233
+ icon: Files,
4234
+ text: "\u5DF2\u9009\u7EC4\u4EF6",
4235
+ component: LayerPanel,
4236
+ slots: {}
4237
+ };
4238
+ case "code-block":
4239
+ return {
4240
+ type: "component",
4241
+ icon: EditPen,
4242
+ text: "\u4EE3\u7801\u7F16\u8F91",
4243
+ component: _sfc_main$e,
4244
+ slots: {}
4245
+ };
4246
+ default:
4247
+ return void 0;
4248
+ }
4249
+ });
4250
+ return (_ctx, _cache) => {
4251
+ const _component_el_tab_pane = resolveComponent("el-tab-pane");
4252
+ return unref(config) ? (openBlock(), createBlock(_component_el_tab_pane, {
4253
+ key: 0,
4254
+ name: unref(config).text
4255
+ }, {
4256
+ label: withCtx(() => [
4257
+ (openBlock(), createElementBlock("div", {
4258
+ key: unref(config).text
4259
+ }, [
4260
+ unref(config).icon ? (openBlock(), createBlock(_sfc_main$j, {
3423
4261
  key: 0,
3424
- data: nodeData,
3425
- node
3426
- }) : _ctx.config.slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots.layerNodeContent), {
3427
- key: 1,
3428
- data: nodeData,
3429
- node
3430
- }, null, 8, ["data", "node"])) : createCommentVNode("", true)
3431
- ])
3432
- } : void 0
3433
- ]), 1040))
3434
- ]),
3435
- _: 3
3436
- }, 8, ["name"])) : createCommentVNode("", true);
3437
- }
3438
- const TabPane = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$2]]);
4262
+ icon: unref(config).icon
4263
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
4264
+ unref(config).text ? (openBlock(), createElementBlock("div", _hoisted_1$2, toDisplayString(unref(config).text), 1)) : createCommentVNode("", true)
4265
+ ]))
4266
+ ]),
4267
+ default: withCtx(() => [
4268
+ (openBlock(), createBlock(resolveDynamicComponent(unref(config).component), mergeProps(unref(config).props || {}, toHandlers(unref(config)?.listeners || {})), createSlots({ _: 2 }, [
4269
+ __props.data === "component-list" || unref(config).slots?.componentListPanelHeader ? {
4270
+ name: "component-list-panel-header",
4271
+ fn: withCtx(() => [
4272
+ __props.data === "component-list" ? renderSlot(_ctx.$slots, "component-list-panel-header", { key: 0 }) : unref(config).slots?.componentListPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.componentListPanelHeader), { key: 1 })) : createCommentVNode("", true)
4273
+ ])
4274
+ } : void 0,
4275
+ __props.data === "component-list" || unref(config).slots?.componentListItem ? {
4276
+ name: "component-list-item",
4277
+ fn: withCtx(({ component }) => [
4278
+ __props.data === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
4279
+ key: 0,
4280
+ component
4281
+ }) : unref(config).slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.componentListItem), {
4282
+ key: 1,
4283
+ component
4284
+ }, null, 8, ["component"])) : createCommentVNode("", true)
4285
+ ])
4286
+ } : void 0,
4287
+ __props.data === "layer" || unref(config).slots?.layerPanelHeader ? {
4288
+ name: "layer-panel-header",
4289
+ fn: withCtx(() => [
4290
+ __props.data === "layer" ? renderSlot(_ctx.$slots, "layer-panel-header", { key: 0 }) : unref(config).slots?.layerPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.layerPanelHeader), { key: 1 })) : createCommentVNode("", true)
4291
+ ])
4292
+ } : void 0,
4293
+ __props.data === "code-block" || unref(config).slots?.codeBlockPanelHeader ? {
4294
+ name: "code-block-panel-header",
4295
+ fn: withCtx(() => [
4296
+ __props.data === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-header", { key: 0 }) : unref(config).slots?.codeBlockPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockPanelHeader), { key: 1 })) : createCommentVNode("", true)
4297
+ ])
4298
+ } : void 0,
4299
+ __props.data === "code-block" || unref(config).slots?.codeBlockPanelTool ? {
4300
+ name: "code-block-panel-tool",
4301
+ fn: withCtx(({ id, data }) => [
4302
+ data === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
4303
+ key: 0,
4304
+ id,
4305
+ data
4306
+ }) : unref(config).slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
4307
+ ])
4308
+ } : void 0,
4309
+ __props.data === "code-block" || unref(config).slots?.codeBlockEditPanelHeader ? {
4310
+ name: "code-block-edit-panel-header",
4311
+ fn: withCtx(({ id }) => [
4312
+ __props.data === "code-block" ? renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
4313
+ key: 0,
4314
+ id
4315
+ }) : unref(config).slots?.codeBlockEditPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockEditPanelHeader), { key: 1 })) : createCommentVNode("", true)
4316
+ ])
4317
+ } : void 0,
4318
+ __props.data === "layer" || unref(config).slots?.layerNodeContent ? {
4319
+ name: "layer-node-content",
4320
+ fn: withCtx(({ data: nodeData, node }) => [
4321
+ __props.data === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
4322
+ key: 0,
4323
+ data: nodeData,
4324
+ node
4325
+ }) : unref(config).slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.layerNodeContent), {
4326
+ key: 1,
4327
+ data: nodeData,
4328
+ node
4329
+ }, null, 8, ["data", "node"])) : createCommentVNode("", true)
4330
+ ])
4331
+ } : void 0
4332
+ ]), 1040))
4333
+ ]),
4334
+ _: 3
4335
+ }, 8, ["name"])) : createCommentVNode("", true);
4336
+ };
4337
+ }
4338
+ });
3439
4339
 
3440
- const _sfc_main$8 = defineComponent({
3441
- components: { TabPane },
3442
- name: "m-sidebar",
4340
+ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
4341
+ __name: "Sidebar",
3443
4342
  props: {
3444
- data: {
3445
- type: Object,
3446
- default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer"] })
3447
- }
4343
+ data: { default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer", "code-block"] }) }
3448
4344
  },
3449
- setup(props) {
4345
+ setup(__props, { expose }) {
4346
+ const props = __props;
3450
4347
  const activeTabName = ref(props.data?.status);
3451
4348
  watch(
3452
- () => props.data?.status,
4349
+ () => props.data.status,
3453
4350
  (status) => {
3454
4351
  activeTabName.value = status || "0";
3455
4352
  }
3456
4353
  );
3457
- return {
4354
+ expose({
3458
4355
  activeTabName
4356
+ });
4357
+ return (_ctx, _cache) => {
4358
+ const _component_el_tabs = resolveComponent("el-tabs");
4359
+ return __props.data.type === "tabs" && __props.data.items.length ? (openBlock(), createBlock(_component_el_tabs, {
4360
+ key: 0,
4361
+ class: "m-editor-sidebar",
4362
+ modelValue: activeTabName.value,
4363
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => activeTabName.value = $event),
4364
+ type: "card",
4365
+ "tab-position": "left"
4366
+ }, {
4367
+ default: withCtx(() => [
4368
+ (openBlock(true), createElementBlock(Fragment, null, renderList(__props.data.items, (item, index) => {
4369
+ return openBlock(), createBlock(_sfc_main$9, {
4370
+ key: index,
4371
+ data: item
4372
+ }, createSlots({ _: 2 }, [
4373
+ item === "layer" ? {
4374
+ name: "layer-panel-header",
4375
+ fn: withCtx(() => [
4376
+ renderSlot(_ctx.$slots, "layer-panel-header")
4377
+ ])
4378
+ } : void 0,
4379
+ item === "layer" ? {
4380
+ name: "layer-node-content",
4381
+ fn: withCtx(({ node, data }) => [
4382
+ renderSlot(_ctx.$slots, "layer-node-content", {
4383
+ data,
4384
+ node
4385
+ })
4386
+ ])
4387
+ } : void 0,
4388
+ item === "component-list" ? {
4389
+ name: "component-list-panel-header",
4390
+ fn: withCtx(() => [
4391
+ renderSlot(_ctx.$slots, "component-list-panel-header")
4392
+ ])
4393
+ } : void 0,
4394
+ item === "component-list" ? {
4395
+ name: "component-list-item",
4396
+ fn: withCtx(({ component }) => [
4397
+ renderSlot(_ctx.$slots, "component-list-item", { component })
4398
+ ])
4399
+ } : void 0,
4400
+ item === "code-block" ? {
4401
+ name: "code-block-panel-header",
4402
+ fn: withCtx(() => [
4403
+ renderSlot(_ctx.$slots, "code-block-panel-header")
4404
+ ])
4405
+ } : void 0,
4406
+ item === "code-block" ? {
4407
+ name: "code-block-panel-tool",
4408
+ fn: withCtx(({ id, data }) => [
4409
+ renderSlot(_ctx.$slots, "code-block-panel-tool", {
4410
+ id,
4411
+ data
4412
+ })
4413
+ ])
4414
+ } : void 0,
4415
+ item === "code-block" ? {
4416
+ name: "code-block-edit-panel-header",
4417
+ fn: withCtx(({ id }) => [
4418
+ renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
4419
+ ])
4420
+ } : void 0
4421
+ ]), 1032, ["data"]);
4422
+ }), 128))
4423
+ ]),
4424
+ _: 3
4425
+ }, 8, ["modelValue"])) : createCommentVNode("", true);
3459
4426
  };
3460
4427
  }
3461
4428
  });
3462
4429
 
3463
- function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
3464
- const _component_tab_pane = resolveComponent("tab-pane");
3465
- const _component_el_tabs = resolveComponent("el-tabs");
3466
- return _ctx.data.type === "tabs" && _ctx.data.items.length ? (openBlock(), createBlock(_component_el_tabs, {
3467
- key: 0,
3468
- class: "m-editor-sidebar",
3469
- modelValue: _ctx.activeTabName,
3470
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.activeTabName = $event),
3471
- type: "card",
3472
- "tab-position": "left"
3473
- }, {
3474
- default: withCtx(() => [
3475
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.data.items, (item, index) => {
3476
- return openBlock(), createBlock(_component_tab_pane, {
3477
- key: index,
3478
- data: item
3479
- }, createSlots({ _: 2 }, [
3480
- item === "layer" ? {
3481
- name: "layer-panel-header",
3482
- fn: withCtx(() => [
3483
- renderSlot(_ctx.$slots, "layer-panel-header")
3484
- ])
3485
- } : void 0,
3486
- item === "layer" ? {
3487
- name: "layer-node-content",
3488
- fn: withCtx(({ node, data }) => [
3489
- renderSlot(_ctx.$slots, "layer-node-content", {
3490
- data,
3491
- node
3492
- })
3493
- ])
3494
- } : void 0,
3495
- item === "component-list" ? {
3496
- name: "component-list-panel-header",
3497
- fn: withCtx(() => [
3498
- renderSlot(_ctx.$slots, "component-list-panel-header")
3499
- ])
3500
- } : void 0,
3501
- item === "component-list" ? {
3502
- name: "component-list-item",
3503
- fn: withCtx(({ component }) => [
3504
- renderSlot(_ctx.$slots, "component-list-item", { component })
3505
- ])
3506
- } : void 0
3507
- ]), 1032, ["data"]);
3508
- }), 128))
3509
- ]),
3510
- _: 3
3511
- }, 8, ["modelValue"])) : createCommentVNode("", true);
3512
- }
3513
- const Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$1]]);
3514
-
3515
4430
  const _hoisted_1$1 = {
3516
4431
  key: 1,
3517
4432
  style: { "width": "21px" }
@@ -3598,14 +4513,14 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3598
4513
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3599
4514
  onClick: addPage
3600
4515
  }, [
3601
- createVNode(_sfc_main$h, { icon: unref(Plus) }, null, 8, ["icon"])
4516
+ createVNode(_sfc_main$j, { icon: unref(Plus) }, null, 8, ["icon"])
3602
4517
  ])) : (openBlock(), createElementBlock("div", _hoisted_1$1)),
3603
4518
  canScroll.value ? (openBlock(), createElementBlock("div", {
3604
4519
  key: 2,
3605
4520
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3606
4521
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
3607
4522
  }, [
3608
- createVNode(_sfc_main$h, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
4523
+ createVNode(_sfc_main$j, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
3609
4524
  ])) : createCommentVNode("", true),
3610
4525
  unref(pageLength) ? (openBlock(), createElementBlock("div", {
3611
4526
  key: 3,
@@ -3621,7 +4536,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3621
4536
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3622
4537
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
3623
4538
  }, [
3624
- createVNode(_sfc_main$h, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
4539
+ createVNode(_sfc_main$j, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
3625
4540
  ])) : createCommentVNode("", true)
3626
4541
  ], 512);
3627
4542
  };
@@ -3693,7 +4608,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
3693
4608
  default: withCtx(() => [
3694
4609
  createElementVNode("div", null, [
3695
4610
  renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
3696
- createVNode(_sfc_main$g, {
4611
+ createVNode(_sfc_main$i, {
3697
4612
  data: {
3698
4613
  type: "button",
3699
4614
  text: "\u590D\u5236",
@@ -3701,7 +4616,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
3701
4616
  handler: () => copy(item)
3702
4617
  }
3703
4618
  }, null, 8, ["data"]),
3704
- createVNode(_sfc_main$g, {
4619
+ createVNode(_sfc_main$i, {
3705
4620
  data: {
3706
4621
  type: "button",
3707
4622
  text: "\u5220\u9664",
@@ -4475,11 +5390,11 @@ const componentListService = new ComponentList();
4475
5390
  const _sfc_main = defineComponent({
4476
5391
  name: "m-editor",
4477
5392
  components: {
4478
- NavMenu: _sfc_main$f,
4479
- Sidebar,
5393
+ NavMenu: _sfc_main$h,
5394
+ Sidebar: _sfc_main$8,
4480
5395
  Workspace: _sfc_main$1,
4481
- PropsPanel: _sfc_main$e,
4482
- Framework: _sfc_main$i
5396
+ PropsPanel: _sfc_main$g,
5397
+ Framework: _sfc_main$k
4483
5398
  },
4484
5399
  props: {
4485
5400
  modelValue: {
@@ -4574,7 +5489,9 @@ const _sfc_main = defineComponent({
4574
5489
  });
4575
5490
  watch(
4576
5491
  () => props.modelValue,
4577
- (modelValue) => editorService.set("root", modelValue),
5492
+ (modelValue) => {
5493
+ editorService.set("root", modelValue);
5494
+ },
4578
5495
  {
4579
5496
  immediate: true
4580
5497
  }
@@ -4637,6 +5554,7 @@ const _sfc_main = defineComponent({
4637
5554
  uiService.destroy();
4638
5555
  componentListService.destroy();
4639
5556
  storageService.destroy();
5557
+ codeBlockService.destroy();
4640
5558
  });
4641
5559
  const services = {
4642
5560
  componentListService,
@@ -4645,7 +5563,8 @@ const _sfc_main = defineComponent({
4645
5563
  propsService,
4646
5564
  editorService,
4647
5565
  uiService,
4648
- storageService
5566
+ storageService,
5567
+ codeBlockService
4649
5568
  };
4650
5569
  provide("services", services);
4651
5570
  provide("layerContentMenu", props.layerContentMenu);
@@ -4699,6 +5618,18 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
4699
5618
  "component-list-item": withCtx(({ component }) => [
4700
5619
  renderSlot(_ctx.$slots, "component-list-item", { component })
4701
5620
  ]),
5621
+ "code-block-panel-header": withCtx(() => [
5622
+ renderSlot(_ctx.$slots, "code-block-panel-header")
5623
+ ]),
5624
+ "code-block-panel-tool": withCtx(({ id, data }) => [
5625
+ renderSlot(_ctx.$slots, "code-block-panel-tool", {
5626
+ id,
5627
+ data
5628
+ })
5629
+ ]),
5630
+ "code-block-edit-panel-header": withCtx(({ id }) => [
5631
+ renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
5632
+ ]),
4702
5633
  _: 3
4703
5634
  }, 8, ["data"])
4704
5635
  ])
@@ -4751,12 +5682,13 @@ const index = {
4751
5682
  app.config.globalProperties.$TMAGIC_EDITOR = option;
4752
5683
  setConfig(option);
4753
5684
  app.component(Editor.name, Editor);
4754
- app.component("m-fields-ui-select", _sfc_main$n);
4755
- app.component("m-fields-code-link", _sfc_main$o);
4756
- app.component("m-fields-vs-code", _sfc_main$p);
4757
- app.component(CodeEditor.name, CodeEditor);
5685
+ app.component("m-fields-ui-select", _sfc_main$p);
5686
+ app.component("m-fields-code-link", _sfc_main$r);
5687
+ app.component("m-fields-vs-code", _sfc_main$s);
5688
+ app.component("magic-code-editor", _sfc_main$o);
5689
+ app.component("m-fields-code-select", _sfc_main$q);
4758
5690
  }
4759
5691
  };
4760
5692
 
4761
- export { COPY_STORAGE_KEY, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$h as Icon, Keys, LayerOffset, LayerPanel, Layout, _sfc_main$e as PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$g as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, useStage, warn };
5693
+ export { COPY_STORAGE_KEY, _sfc_main$e as CodeBlockList, CodeDeleteErrorType, CodeEditorMode, _sfc_main$q as CodeSelect, CodeSelectOp, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$j as Icon, Keys, LayerOffset, LayerPanel, Layout, _sfc_main$g as PropsPanel, _sfc_main$o as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$i as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, codeBlockService, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, useStage, warn };
4762
5694
  //# sourceMappingURL=tmagic-editor.mjs.map