@tmagic/editor 1.1.6 → 1.2.0-beta.1

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.
@@ -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,
@@ -41,7 +41,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
41
41
  }
42
42
  });
43
43
 
44
- const _sfc_main$o = /* @__PURE__ */ defineComponent({
44
+ const _sfc_main$r = /* @__PURE__ */ defineComponent({
45
45
  __name: "CodeLink",
46
46
  props: {
47
47
  config: null,
@@ -104,8 +104,186 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
104
104
  }
105
105
  });
106
106
 
107
- const _hoisted_1$b = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
108
- const _sfc_main$n = /* @__PURE__ */ defineComponent({
107
+ var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
108
+ ColumnLayout2["LEFT"] = "left";
109
+ ColumnLayout2["CENTER"] = "center";
110
+ ColumnLayout2["RIGHT"] = "right";
111
+ return ColumnLayout2;
112
+ })(ColumnLayout || {});
113
+ var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
114
+ LayerOffset2["TOP"] = "top";
115
+ LayerOffset2["BOTTOM"] = "bottom";
116
+ return LayerOffset2;
117
+ })(LayerOffset || {});
118
+ var Layout = /* @__PURE__ */ ((Layout2) => {
119
+ Layout2["FLEX"] = "flex";
120
+ Layout2["FIXED"] = "fixed";
121
+ Layout2["RELATIVE"] = "relative";
122
+ Layout2["ABSOLUTE"] = "absolute";
123
+ return Layout2;
124
+ })(Layout || {});
125
+ var Keys = /* @__PURE__ */ ((Keys2) => {
126
+ Keys2["ESCAPE"] = "Space";
127
+ return Keys2;
128
+ })(Keys || {});
129
+ const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
130
+ const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
131
+ var CodeEditorMode = /* @__PURE__ */ ((CodeEditorMode2) => {
132
+ CodeEditorMode2["LIST"] = "list";
133
+ CodeEditorMode2["EDITOR"] = "editor";
134
+ return CodeEditorMode2;
135
+ })(CodeEditorMode || {});
136
+ var CodeDeleteErrorType = /* @__PURE__ */ ((CodeDeleteErrorType2) => {
137
+ CodeDeleteErrorType2["UNDELETEABLE"] = "undeleteable";
138
+ CodeDeleteErrorType2["BIND"] = "bind";
139
+ return CodeDeleteErrorType2;
140
+ })(CodeDeleteErrorType || {});
141
+ var CodeSelectOp = /* @__PURE__ */ ((CodeSelectOp2) => {
142
+ CodeSelectOp2["ADD"] = "add";
143
+ CodeSelectOp2["DELETE"] = "delete";
144
+ CodeSelectOp2["CHANGE"] = "change";
145
+ return CodeSelectOp2;
146
+ })(CodeSelectOp || {});
147
+
148
+ const _hoisted_1$e = { class: "tool-bar" };
149
+ const _hoisted_2$6 = /* @__PURE__ */ createElementVNode("path", {
150
+ fill: "currentColor",
151
+ 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"
152
+ }, null, -1);
153
+ const _hoisted_3$3 = [
154
+ _hoisted_2$6
155
+ ];
156
+ const _sfc_main$q = /* @__PURE__ */ defineComponent({
157
+ __name: "CodeSelect",
158
+ props: {
159
+ config: null,
160
+ model: null,
161
+ prop: null,
162
+ name: null,
163
+ size: null
164
+ },
165
+ emits: ["change"],
166
+ setup(__props, { emit }) {
167
+ const props = __props;
168
+ const services = inject("services");
169
+ const selectConfig = computed(() => {
170
+ const defaultConfig = {
171
+ multiple: true,
172
+ options: async () => {
173
+ const codeDsl = await services?.codeBlockService.getCodeDsl();
174
+ if (codeDsl) {
175
+ return map(codeDsl, (value, key) => ({
176
+ text: `${value.name}\uFF08${key}\uFF09`,
177
+ label: `${value.name}\uFF08${key}\uFF09`,
178
+ value: key
179
+ }));
180
+ }
181
+ return [];
182
+ }
183
+ };
184
+ return {
185
+ ...defaultConfig,
186
+ ...props.config.selectConfig
187
+ };
188
+ });
189
+ const fieldKey = ref("");
190
+ const multiple = ref(true);
191
+ const combineIds = ref([]);
192
+ let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
193
+ watchEffect(async () => {
194
+ const combineNames = await Promise.all(
195
+ combineIds.value.map(async (id) => {
196
+ const { name = "" } = await services?.codeBlockService.getCodeContentById(id) || {};
197
+ return name;
198
+ })
199
+ );
200
+ fieldKey.value = combineNames.join("-");
201
+ });
202
+ const changeHandler = async (value) => {
203
+ let codeIds = value;
204
+ if (typeof value === "string") {
205
+ multiple.value = false;
206
+ lastTagSnapshot = [lastTagSnapshot];
207
+ codeIds = value ? [value] : [];
208
+ }
209
+ await setCombineRelation(codeIds);
210
+ emit("change", value);
211
+ };
212
+ const setCombineRelation = async (codeIds) => {
213
+ const { id = "" } = services?.editorService.get("node") || {};
214
+ let opFlag = CodeSelectOp.CHANGE;
215
+ let diffValues = codeIds;
216
+ if (multiple.value) {
217
+ opFlag = codeIds.length < lastTagSnapshot.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
218
+ diffValues = xor(codeIds, lastTagSnapshot);
219
+ }
220
+ await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
221
+ lastTagSnapshot = codeIds;
222
+ await setCombineIds(codeIds);
223
+ };
224
+ const setCombineIds = async (codeIds) => {
225
+ combineIds.value = codeIds;
226
+ await services?.codeBlockService.setCombineIds(codeIds);
227
+ };
228
+ const viewHandler = async () => {
229
+ if (props.model[props.name].length === 0) {
230
+ ElMessage.error("\u8BF7\u5148\u7ED1\u5B9A\u4EE3\u7801\u5757");
231
+ return;
232
+ }
233
+ await setCombineIds(props.model[props.name]);
234
+ await services?.codeBlockService.setMode(CodeEditorMode.LIST);
235
+ services?.codeBlockService.setCodeEditorContent(true, combineIds.value[0]);
236
+ };
237
+ return (_ctx, _cache) => {
238
+ const _component_m_fields_select = resolveComponent("m-fields-select");
239
+ const _component_el_tooltip = resolveComponent("el-tooltip");
240
+ const _component_el_card = resolveComponent("el-card");
241
+ return openBlock(), createElementBlock("div", {
242
+ class: "m-fields-code-select",
243
+ key: fieldKey.value
244
+ }, [
245
+ createVNode(_component_el_card, { shadow: "never" }, {
246
+ header: withCtx(() => [
247
+ createVNode(_component_m_fields_select, {
248
+ config: unref(selectConfig),
249
+ model: __props.model,
250
+ prop: __props.prop,
251
+ name: __props.name,
252
+ size: __props.size,
253
+ onChange: changeHandler
254
+ }, null, 8, ["config", "model", "prop", "name", "size"])
255
+ ]),
256
+ default: withCtx(() => [
257
+ createElementVNode("div", _hoisted_1$e, [
258
+ createVNode(_component_el_tooltip, {
259
+ class: "tool-item",
260
+ effect: "dark",
261
+ content: "\u67E5\u770B\u4EE3\u7801\u5757",
262
+ placement: "top"
263
+ }, {
264
+ default: withCtx(() => [
265
+ (openBlock(), createElementBlock("svg", {
266
+ onClick: viewHandler,
267
+ preserveAspectRatio: "xMidYMid meet",
268
+ viewBox: "0 0 24 24",
269
+ width: "15px",
270
+ height: "15px",
271
+ "data-v-65a7fb6c": ""
272
+ }, _hoisted_3$3))
273
+ ]),
274
+ _: 1
275
+ })
276
+ ])
277
+ ]),
278
+ _: 1
279
+ })
280
+ ]);
281
+ };
282
+ }
283
+ });
284
+
285
+ const _hoisted_1$d = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
286
+ const _sfc_main$p = /* @__PURE__ */ defineComponent({
109
287
  __name: "UISelect",
110
288
  props: {
111
289
  config: null,
@@ -170,7 +348,7 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
170
348
  style: { "padding": "0" }
171
349
  }, {
172
350
  default: withCtx(() => [
173
- _hoisted_1$b
351
+ _hoisted_1$d
174
352
  ]),
175
353
  _: 1
176
354
  }, 8, ["icon"])
@@ -233,7 +411,7 @@ const toString = (v, language) => {
233
411
  }
234
412
  return value;
235
413
  };
236
- const _sfc_main$m = defineComponent({
414
+ const _sfc_main$o = defineComponent({
237
415
  name: "magic-code-editor",
238
416
  props: {
239
417
  initValues: {
@@ -355,14 +533,14 @@ const _export_sfc = (sfc, props) => {
355
533
  return target;
356
534
  };
357
535
 
358
- const _hoisted_1$a = {
536
+ const _hoisted_1$c = {
359
537
  ref: "codeEditor",
360
538
  class: "magic-code-editor"
361
539
  };
362
540
  function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
363
- return openBlock(), createElementBlock("div", _hoisted_1$a, null, 512);
541
+ return openBlock(), createElementBlock("div", _hoisted_1$c, null, 512);
364
542
  }
365
- const CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$6]]);
543
+ const CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$o, [["render", _sfc_render$6]]);
366
544
 
367
545
  let $TMAGIC_EDITOR = {};
368
546
  const setConfig = (option) => {
@@ -370,51 +548,31 @@ const setConfig = (option) => {
370
548
  };
371
549
  const getConfig = (key) => $TMAGIC_EDITOR[key];
372
550
 
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;
551
+ const log = (...args) => {
552
+ if (process.env.NODE_ENV === "development") {
553
+ console.log("magic editor: ", ...args);
393
554
  }
394
- undo() {
395
- if (!this.canUndo()) {
396
- return null;
397
- }
398
- this.listCursor -= 1;
399
- return this.getCurrentElement();
555
+ };
556
+ const info = (...args) => {
557
+ if (process.env.NODE_ENV === "development") {
558
+ console.info("magic editor: ", ...args);
400
559
  }
401
- canRedo() {
402
- return this.elementList.length > this.listCursor;
560
+ };
561
+ const warn = (...args) => {
562
+ if (process.env.NODE_ENV === "development") {
563
+ console.warn("magic editor: ", ...args);
403
564
  }
404
- redo() {
405
- if (!this.canRedo()) {
406
- return null;
407
- }
408
- this.listCursor += 1;
409
- return this.getCurrentElement();
565
+ };
566
+ const debug = (...args) => {
567
+ if (process.env.NODE_ENV === "development") {
568
+ console.debug("magic editor: ", ...args);
410
569
  }
411
- getCurrentElement() {
412
- if (this.listCursor < 1) {
413
- return null;
414
- }
415
- return cloneDeep(this.elementList[this.listCursor - 1]);
570
+ };
571
+ const error = (...args) => {
572
+ if (process.env.NODE_ENV === "development") {
573
+ console.error("magic editor: ", ...args);
416
574
  }
417
- }
575
+ };
418
576
 
419
577
  const compose = (middleware) => {
420
578
  if (!Array.isArray(middleware))
@@ -530,6 +688,265 @@ class BaseService extends EventEmitter {
530
688
  }
531
689
  }
532
690
 
691
+ class CodeBlock extends BaseService {
692
+ state = reactive({
693
+ isShowCodeEditor: false,
694
+ codeDsl: null,
695
+ id: "",
696
+ editable: true,
697
+ mode: CodeEditorMode.EDITOR,
698
+ combineIds: [],
699
+ undeletableList: []
700
+ });
701
+ constructor() {
702
+ super([
703
+ "setCodeDsl",
704
+ "getCodeDsl",
705
+ "getCodeContentById",
706
+ "getCodeDslByIds",
707
+ "getCurrentDsl",
708
+ "setCodeDslById",
709
+ "setCodeEditorShowStatus",
710
+ "setEditStatus",
711
+ "setMode",
712
+ "setCombineIds",
713
+ "setUndeleteableList",
714
+ "deleteCodeDslByIds"
715
+ ]);
716
+ }
717
+ async setCodeDsl(codeDsl) {
718
+ this.state.codeDsl = codeDsl;
719
+ await editorService.setCodeDsl(this.state.codeDsl);
720
+ info("[code-block]:code-dsl-change", this.state.codeDsl);
721
+ this.emit("code-dsl-change", this.state.codeDsl);
722
+ }
723
+ async getCodeDsl(forceRefresh = false) {
724
+ if (!this.state.codeDsl || forceRefresh) {
725
+ this.state.codeDsl = await editorService.getCodeDsl();
726
+ }
727
+ return this.state.codeDsl;
728
+ }
729
+ async getCodeContentById(id) {
730
+ if (!id)
731
+ return null;
732
+ const totalCodeDsl = await this.getCodeDsl();
733
+ if (!totalCodeDsl)
734
+ return null;
735
+ return totalCodeDsl[id] ?? null;
736
+ }
737
+ async setCodeDslById(id, codeConfig) {
738
+ let codeDsl = await this.getCodeDsl();
739
+ if (!codeDsl)
740
+ return;
741
+ const existContent = codeDsl[id] || {};
742
+ codeDsl = {
743
+ ...codeDsl,
744
+ [id]: {
745
+ ...existContent,
746
+ ...codeConfig
747
+ }
748
+ };
749
+ await this.setCodeDsl(codeDsl);
750
+ }
751
+ async getCodeDslByIds(ids) {
752
+ const codeDsl = await this.getCodeDsl();
753
+ return pick(codeDsl, ids);
754
+ }
755
+ async setCodeEditorShowStatus(status) {
756
+ this.state.isShowCodeEditor = status;
757
+ }
758
+ getCodeEditorShowStatus() {
759
+ return this.state.isShowCodeEditor;
760
+ }
761
+ setCodeEditorContent(status, id) {
762
+ if (!id)
763
+ return;
764
+ this.setId(id);
765
+ this.state.isShowCodeEditor = status;
766
+ }
767
+ async getCurrentDsl() {
768
+ return await this.getCodeContentById(this.state.id);
769
+ }
770
+ getEditStatus() {
771
+ return this.state.editable;
772
+ }
773
+ async setEditStatus(status) {
774
+ this.state.editable = status;
775
+ }
776
+ setId(id) {
777
+ if (!id)
778
+ return;
779
+ this.state.id = id;
780
+ }
781
+ getId() {
782
+ return this.state.id;
783
+ }
784
+ getMode() {
785
+ return this.state.mode;
786
+ }
787
+ async setMode(mode) {
788
+ this.state.mode = mode;
789
+ }
790
+ async setCombineIds(ids) {
791
+ this.state.combineIds = ids;
792
+ }
793
+ getCombineIds() {
794
+ return this.state.combineIds;
795
+ }
796
+ async setCombineRelation(compId, diffCodeIds, opFlag, hook) {
797
+ const codeDsl = cloneDeep(await this.getCodeDsl());
798
+ if (!codeDsl)
799
+ return;
800
+ if (opFlag === CodeSelectOp.DELETE) {
801
+ try {
802
+ diffCodeIds.forEach((codeId) => {
803
+ const compsContent = codeDsl[codeId].comps;
804
+ const index = compsContent?.[compId].findIndex((item) => item === hook);
805
+ if (typeof index !== "undefined" && index !== -1) {
806
+ compsContent?.[compId].splice(index, 1);
807
+ }
808
+ });
809
+ } catch (e) {
810
+ error(e);
811
+ throw new Error("\u89E3\u7ED1\u4EE3\u7801\u5757\u5931\u8D25");
812
+ }
813
+ } else if (opFlag === CodeSelectOp.ADD) {
814
+ try {
815
+ diffCodeIds.forEach((codeId) => {
816
+ const compsContent = codeDsl[codeId].comps;
817
+ const existHooks = compsContent?.[compId];
818
+ if (isEmpty(existHooks)) {
819
+ codeDsl[codeId].comps = {
820
+ ...codeDsl[codeId].comps || {},
821
+ [compId]: [hook]
822
+ };
823
+ } else {
824
+ existHooks?.push(hook);
825
+ }
826
+ });
827
+ } catch (e) {
828
+ error(e);
829
+ throw new Error("\u7ED1\u5B9A\u4EE3\u7801\u5757\u5931\u8D25");
830
+ }
831
+ } else if (opFlag === CodeSelectOp.CHANGE) {
832
+ forIn(codeDsl, (codeBlockContent, codeId) => {
833
+ if (codeId === diffCodeIds[0]) {
834
+ codeBlockContent.comps = {
835
+ ...codeBlockContent?.comps || {},
836
+ [compId]: [hook]
837
+ };
838
+ } else if (isEmpty(diffCodeIds) || codeId !== diffCodeIds[0]) {
839
+ const compHooks = codeBlockContent?.comps?.[compId];
840
+ if (!compHooks)
841
+ return true;
842
+ const index = compHooks.findIndex((hookName) => hookName === hook);
843
+ if (index !== -1) {
844
+ compHooks.splice(index, 1);
845
+ return false;
846
+ }
847
+ }
848
+ });
849
+ }
850
+ this.setCodeDsl(codeDsl);
851
+ }
852
+ getUndeletableList() {
853
+ return this.state.undeletableList;
854
+ }
855
+ async setUndeleteableList(codeIds) {
856
+ this.state.undeletableList = codeIds;
857
+ }
858
+ async deleteCodeDslByIds(codeIds) {
859
+ const currentDsl = await this.getCodeDsl();
860
+ const newDsl = omit(currentDsl, codeIds);
861
+ await this.setCodeDsl(newDsl);
862
+ return newDsl;
863
+ }
864
+ async getUniqueId() {
865
+ const newId = `code_${Math.random().toString(10).substring(2).substring(0, 4)}`;
866
+ const dsl = await this.getCodeDsl();
867
+ const existedIds = keys(dsl);
868
+ if (!existedIds.includes(newId))
869
+ return newId;
870
+ return await this.getUniqueId();
871
+ }
872
+ async deleteCompsInRelation(node) {
873
+ const codeDsl = cloneDeep(await this.getCodeDsl());
874
+ if (!codeDsl)
875
+ return;
876
+ this.recurseNodes(node, codeDsl);
877
+ this.setCodeDsl(codeDsl);
878
+ }
879
+ destroy() {
880
+ this.state.isShowCodeEditor = false;
881
+ this.state.codeDsl = null;
882
+ this.state.id = "";
883
+ this.state.editable = true;
884
+ this.state.mode = CodeEditorMode.EDITOR;
885
+ this.state.combineIds = [];
886
+ this.state.undeletableList = [];
887
+ }
888
+ recurseNodes(node, codeDsl) {
889
+ if (!node.id)
890
+ return;
891
+ forIn(codeDsl, (codeBlockContent) => {
892
+ const compsContent = codeBlockContent.comps || {};
893
+ codeBlockContent.comps = omit(compsContent, node.id);
894
+ });
895
+ if (!isEmpty(node.items)) {
896
+ node.items.forEach((item) => {
897
+ this.recurseNodes(item, codeDsl);
898
+ });
899
+ }
900
+ }
901
+ }
902
+ const codeBlockService = new CodeBlock();
903
+
904
+ class UndoRedo {
905
+ elementList;
906
+ listCursor;
907
+ listMaxSize;
908
+ constructor(listMaxSize = 200) {
909
+ const minListMaxSize = 2;
910
+ this.elementList = [];
911
+ this.listCursor = 0;
912
+ this.listMaxSize = listMaxSize > minListMaxSize ? listMaxSize : minListMaxSize;
913
+ }
914
+ pushElement(element) {
915
+ this.elementList.splice(this.listCursor, this.elementList.length - this.listCursor, cloneDeep(element));
916
+ this.listCursor += 1;
917
+ if (this.elementList.length > this.listMaxSize) {
918
+ this.elementList.shift();
919
+ this.listCursor -= 1;
920
+ }
921
+ }
922
+ canUndo() {
923
+ return this.listCursor > 1;
924
+ }
925
+ undo() {
926
+ if (!this.canUndo()) {
927
+ return null;
928
+ }
929
+ this.listCursor -= 1;
930
+ return this.getCurrentElement();
931
+ }
932
+ canRedo() {
933
+ return this.elementList.length > this.listCursor;
934
+ }
935
+ redo() {
936
+ if (!this.canRedo()) {
937
+ return null;
938
+ }
939
+ this.listCursor += 1;
940
+ return this.getCurrentElement();
941
+ }
942
+ getCurrentElement() {
943
+ if (this.listCursor < 1) {
944
+ return null;
945
+ }
946
+ return cloneDeep(this.elementList[this.listCursor - 1]);
947
+ }
948
+ }
949
+
533
950
  class History extends BaseService {
534
951
  state = reactive({
535
952
  pageSteps: {},
@@ -695,31 +1112,6 @@ class WebStorage extends BaseService {
695
1112
  }
696
1113
  const storageService = new WebStorage();
697
1114
 
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
1115
  const COPY_STORAGE_KEY = "$MagicEditorCopyData";
724
1116
  const getPageList = (app) => {
725
1117
  if (app.items && Array.isArray(app.items)) {
@@ -1080,7 +1472,9 @@ class Editor$1 extends BaseService {
1080
1472
  "move",
1081
1473
  "undo",
1082
1474
  "redo",
1083
- "highlight"
1475
+ "highlight",
1476
+ "getCodeDsl",
1477
+ "setCodeDsl"
1084
1478
  ],
1085
1479
  ["select", "update", "moveLayer"]
1086
1480
  );
@@ -1305,6 +1699,7 @@ class Editor$1 extends BaseService {
1305
1699
  stage?.select(parent.id);
1306
1700
  }
1307
1701
  this.addModifiedNodeId(parent.id);
1702
+ codeBlockService.deleteCompsInRelation(node);
1308
1703
  }
1309
1704
  async remove(nodeOrNodeList) {
1310
1705
  const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
@@ -1530,6 +1925,17 @@ class Editor$1 extends BaseService {
1530
1925
  resetModifiedNodeId() {
1531
1926
  this.get("modifiedNodeIds").clear();
1532
1927
  }
1928
+ async getCodeDsl() {
1929
+ const root = this.get("root");
1930
+ if (!root)
1931
+ return null;
1932
+ return root.codeBlock || null;
1933
+ }
1934
+ async setCodeDsl(codeDsl) {
1935
+ if (!this.state.root)
1936
+ return;
1937
+ this.state.root.codeBlock = codeDsl;
1938
+ }
1533
1939
  addModifiedNodeId(id) {
1534
1940
  if (!this.isHistoryStateChange) {
1535
1941
  this.get("modifiedNodeIds").set(id, id);
@@ -1834,13 +2240,19 @@ const fillConfig = (config = []) => [
1834
2240
  },
1835
2241
  {
1836
2242
  title: "\u9AD8\u7EA7",
1837
- labelWidth: "80px",
2243
+ lazy: true,
1838
2244
  items: [
1839
2245
  {
1840
- type: "code-link",
1841
2246
  name: "created",
1842
2247
  text: "created",
1843
- formTitle: "created"
2248
+ type: "code-select",
2249
+ labelWidth: "100px"
2250
+ },
2251
+ {
2252
+ name: "mounted",
2253
+ text: "mounted",
2254
+ type: "code-select",
2255
+ labelWidth: "100px"
1844
2256
  }
1845
2257
  ]
1846
2258
  }
@@ -1848,32 +2260,6 @@ const fillConfig = (config = []) => [
1848
2260
  }
1849
2261
  ];
1850
2262
 
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
2263
  const state = reactive({
1878
2264
  uiSelectMode: false,
1879
2265
  showSrc: false,
@@ -2014,7 +2400,7 @@ const useStage = (stageOptions) => {
2014
2400
  return stage;
2015
2401
  };
2016
2402
 
2017
- const _sfc_main$l = defineComponent({
2403
+ const _sfc_main$n = defineComponent({
2018
2404
  components: { Plus },
2019
2405
  setup() {
2020
2406
  const services = inject("services");
@@ -2032,14 +2418,14 @@ const _sfc_main$l = defineComponent({
2032
2418
  }
2033
2419
  });
2034
2420
 
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);
2421
+ const _hoisted_1$b = { class: "m-editor-empty-panel" };
2422
+ const _hoisted_2$5 = { class: "m-editor-empty-content" };
2423
+ const _hoisted_3$2 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2038
2424
  function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2039
2425
  const _component_plus = resolveComponent("plus");
2040
2426
  const _component_el_icon = resolveComponent("el-icon");
2041
- return openBlock(), createElementBlock("div", _hoisted_1$9, [
2042
- createElementVNode("div", _hoisted_2$3, [
2427
+ return openBlock(), createElementBlock("div", _hoisted_1$b, [
2428
+ createElementVNode("div", _hoisted_2$5, [
2043
2429
  createElementVNode("div", {
2044
2430
  class: "m-editor-empty-button",
2045
2431
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.clickHandler && _ctx.clickHandler(...args))
@@ -2052,14 +2438,14 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2052
2438
  _: 1
2053
2439
  })
2054
2440
  ]),
2055
- _hoisted_3
2441
+ _hoisted_3$2
2056
2442
  ])
2057
2443
  ])
2058
2444
  ]);
2059
2445
  }
2060
- const AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$5]]);
2446
+ const AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$n, [["render", _sfc_render$5]]);
2061
2447
 
2062
- const _sfc_main$k = /* @__PURE__ */ defineComponent({
2448
+ const _sfc_main$m = /* @__PURE__ */ defineComponent({
2063
2449
  __name: "Resizer",
2064
2450
  emits: ["change"],
2065
2451
  setup(__props, { emit }) {
@@ -2092,7 +2478,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2092
2478
  }
2093
2479
  });
2094
2480
 
2095
- const _sfc_main$j = /* @__PURE__ */ defineComponent({
2481
+ const _sfc_main$l = /* @__PURE__ */ defineComponent({
2096
2482
  __name: "Layout",
2097
2483
  props: {
2098
2484
  left: null,
@@ -2155,7 +2541,8 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2155
2541
  return (_ctx, _cache) => {
2156
2542
  return openBlock(), createElementBlock("div", {
2157
2543
  ref_key: "el",
2158
- ref: el
2544
+ ref: el,
2545
+ class: "m-editor-layout"
2159
2546
  }, [
2160
2547
  typeof props.left !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2161
2548
  createElementVNode("div", {
@@ -2164,7 +2551,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2164
2551
  }, [
2165
2552
  renderSlot(_ctx.$slots, "left")
2166
2553
  ], 6),
2167
- createVNode(_sfc_main$k, { onChange: changeLeft })
2554
+ createVNode(_sfc_main$m, { onChange: changeLeft })
2168
2555
  ], 64)) : createCommentVNode("", true),
2169
2556
  createElementVNode("div", {
2170
2557
  class: normalizeClass(["m-editor-layout-center", __props.centerClass]),
@@ -2173,7 +2560,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2173
2560
  renderSlot(_ctx.$slots, "center")
2174
2561
  ], 6),
2175
2562
  typeof props.right !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
2176
- createVNode(_sfc_main$k, { onChange: changeRight }),
2563
+ createVNode(_sfc_main$m, { onChange: changeRight }),
2177
2564
  createElementVNode("div", {
2178
2565
  class: normalizeClass(["m-editor-layout-right", __props.rightClass]),
2179
2566
  style: normalizeStyle(`width: ${__props.right}px`)
@@ -2186,8 +2573,8 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2186
2573
  }
2187
2574
  });
2188
2575
 
2189
- const _hoisted_1$8 = { class: "m-editor" };
2190
- const _sfc_main$i = /* @__PURE__ */ defineComponent({
2576
+ const _hoisted_1$a = { class: "m-editor" };
2577
+ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2191
2578
  __name: "Framework",
2192
2579
  props: {
2193
2580
  codeOptions: { default: () => ({}) }
@@ -2238,7 +2625,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2238
2625
  return (_ctx, _cache) => {
2239
2626
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
2240
2627
  const _component_el_scrollbar = resolveComponent("el-scrollbar");
2241
- return openBlock(), createElementBlock("div", _hoisted_1$8, [
2628
+ return openBlock(), createElementBlock("div", _hoisted_1$a, [
2242
2629
  renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2243
2630
  unref(showSrc) ? (openBlock(), createBlock(_component_magic_code_editor, {
2244
2631
  key: 0,
@@ -2246,7 +2633,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2246
2633
  "init-values": unref(root),
2247
2634
  options: __props.codeOptions,
2248
2635
  onSave: saveCode
2249
- }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$j, {
2636
+ }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$l, {
2250
2637
  key: 1,
2251
2638
  class: "m-editor-content",
2252
2639
  "left-class": "m-editor-framework-left",
@@ -2287,8 +2674,8 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2287
2674
  }
2288
2675
  });
2289
2676
 
2290
- const _hoisted_1$7 = ["src"];
2291
- const _sfc_main$h = /* @__PURE__ */ defineComponent({
2677
+ const _hoisted_1$9 = ["src"];
2678
+ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2292
2679
  __name: "Icon",
2293
2680
  props: {
2294
2681
  icon: null
@@ -2309,7 +2696,7 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2309
2696
  class: "magic-editor-icon"
2310
2697
  }, {
2311
2698
  default: withCtx(() => [
2312
- createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$7)
2699
+ createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$9)
2313
2700
  ]),
2314
2701
  _: 1
2315
2702
  })) : typeof __props.icon === "string" ? (openBlock(), createElementBlock("i", {
@@ -2328,12 +2715,12 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2328
2715
  }
2329
2716
  });
2330
2717
 
2331
- const _hoisted_1$6 = {
2718
+ const _hoisted_1$8 = {
2332
2719
  key: 1,
2333
2720
  class: "menu-item-text"
2334
2721
  };
2335
- const _hoisted_2$2 = { class: "el-dropdown-link menubar-menu-button" };
2336
- const _sfc_main$g = /* @__PURE__ */ defineComponent({
2722
+ const _hoisted_2$4 = { class: "el-dropdown-link menubar-menu-button" };
2723
+ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2337
2724
  __name: "ToolButton",
2338
2725
  props: {
2339
2726
  data: { default: () => ({
@@ -2416,7 +2803,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2416
2803
  __props.data.type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
2417
2804
  key: 0,
2418
2805
  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 }, [
2806
+ }, 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
2807
  __props.data.tooltip ? (openBlock(), createBlock(_component_el_tooltip, {
2421
2808
  key: 0,
2422
2809
  effect: "dark",
@@ -2430,7 +2817,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2430
2817
  disabled: unref(disabled)
2431
2818
  }, {
2432
2819
  default: withCtx(() => [
2433
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$h, {
2820
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$j, {
2434
2821
  key: 0,
2435
2822
  icon: __props.data.icon
2436
2823
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2447,7 +2834,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2447
2834
  disabled: unref(disabled)
2448
2835
  }, {
2449
2836
  default: withCtx(() => [
2450
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$h, {
2837
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$j, {
2451
2838
  key: 0,
2452
2839
  icon: __props.data.icon
2453
2840
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2480,7 +2867,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2480
2867
  })) : createCommentVNode("", true)
2481
2868
  ]),
2482
2869
  default: withCtx(() => [
2483
- createElementVNode("span", _hoisted_2$2, [
2870
+ createElementVNode("span", _hoisted_2$4, [
2484
2871
  createTextVNode(toDisplayString(__props.data.text), 1),
2485
2872
  createVNode(_component_el_icon, { class: "el-icon--right" }, {
2486
2873
  default: withCtx(() => [
@@ -2497,7 +2884,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2497
2884
  }
2498
2885
  });
2499
2886
 
2500
- const _sfc_main$f = /* @__PURE__ */ defineComponent({
2887
+ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2501
2888
  __name: "NavMenu",
2502
2889
  props: {
2503
2890
  data: { default: () => ({}) },
@@ -2653,7 +3040,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2653
3040
  style: normalizeStyle(`width: ${unref(columnWidth)?.[key]}px`)
2654
3041
  }, [
2655
3042
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(buttons)[key], (item, index) => {
2656
- return openBlock(), createBlock(_sfc_main$g, {
3043
+ return openBlock(), createBlock(_sfc_main$i, {
2657
3044
  data: item,
2658
3045
  key: index
2659
3046
  }, null, 8, ["data"]);
@@ -2665,8 +3052,8 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2665
3052
  }
2666
3053
  });
2667
3054
 
2668
- const _hoisted_1$5 = { class: "`m-editor-props-panel" };
2669
- const _sfc_main$e = /* @__PURE__ */ defineComponent({
3055
+ const _hoisted_1$7 = { class: "m-editor-props-panel" };
3056
+ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2670
3057
  __name: "PropsPanel",
2671
3058
  emits: ["mounted"],
2672
3059
  setup(__props, { expose, emit }) {
@@ -2715,7 +3102,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
2715
3102
  expose({ submit });
2716
3103
  return (_ctx, _cache) => {
2717
3104
  const _component_m_form = resolveComponent("m-form");
2718
- return openBlock(), createElementBlock("div", _hoisted_1$5, [
3105
+ return openBlock(), createElementBlock("div", _hoisted_1$7, [
2719
3106
  renderSlot(_ctx.$slots, "props-panel-header"),
2720
3107
  createVNode(_component_m_form, {
2721
3108
  ref_key: "configForm",
@@ -2732,6 +3119,501 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
2732
3119
  }
2733
3120
  });
2734
3121
 
3122
+ const _hoisted_1$6 = ["id"];
3123
+ const _hoisted_2$3 = { class: "list-item" };
3124
+ const _hoisted_3$1 = { class: "code-name" };
3125
+ const _hoisted_4$1 = { class: "code-name-wrapper" };
3126
+ const _hoisted_5$1 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u4EE3\u7801\u5757\u540D\u79F0", -1);
3127
+ const _hoisted_6$1 = { class: "m-editor-wrapper" };
3128
+ const _hoisted_7$1 = {
3129
+ key: 1,
3130
+ class: "m-editor-content-bottom"
3131
+ };
3132
+ const _hoisted_8$1 = /* @__PURE__ */ createTextVNode("\u4FDD\u5B58");
3133
+ const _hoisted_9$1 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3134
+ const _hoisted_10 = {
3135
+ key: 2,
3136
+ class: "m-editor-content-bottom"
3137
+ };
3138
+ const _hoisted_11 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3139
+ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3140
+ __name: "CodeBlockEditor",
3141
+ setup(__props) {
3142
+ const services = inject("services");
3143
+ const codeEditor = ref();
3144
+ const left = ref(200);
3145
+ const currentTitle = ref("");
3146
+ const codeConfig = ref(null);
3147
+ const state = reactive({
3148
+ codeList: []
3149
+ });
3150
+ const isShowCodeBlockEditor = computed(
3151
+ () => codeConfig.value && services?.codeBlockService.getCodeEditorShowStatus() || false
3152
+ );
3153
+ const mode = computed(() => services?.codeBlockService.getMode());
3154
+ const id = computed(() => services?.codeBlockService.getId() || "");
3155
+ const editable = computed(() => services?.codeBlockService.getEditStatus());
3156
+ const selectedIds = computed(() => services?.codeBlockService.getCombineIds() || []);
3157
+ watchEffect(async () => {
3158
+ codeConfig.value = await services?.codeBlockService.getCodeContentById(id.value) || null;
3159
+ });
3160
+ watchEffect(async () => {
3161
+ const codeDsl = await services?.codeBlockService.getCodeDslByIds(selectedIds.value) || null;
3162
+ if (!codeDsl)
3163
+ return;
3164
+ state.codeList = [];
3165
+ forIn(codeDsl, (value, key) => {
3166
+ state.codeList.push({
3167
+ id: key,
3168
+ name: value.name,
3169
+ content: value.content
3170
+ });
3171
+ });
3172
+ currentTitle.value = state.codeList[0]?.name || "";
3173
+ });
3174
+ const saveCode = async () => {
3175
+ if (!codeEditor.value || !codeConfig.value || !editable.value)
3176
+ return true;
3177
+ try {
3178
+ const codeContent = codeEditor.value.getEditor()?.getValue();
3179
+ codeConfig.value.content = eval(codeContent);
3180
+ } catch (e) {
3181
+ ElMessage.error(e.stack);
3182
+ return false;
3183
+ }
3184
+ await services?.codeBlockService.setCodeDslById(id.value, {
3185
+ name: codeConfig.value.name,
3186
+ content: codeConfig.value.content
3187
+ });
3188
+ ElMessage.success("\u4EE3\u7801\u4FDD\u5B58\u6210\u529F");
3189
+ return true;
3190
+ };
3191
+ const saveAndClose = async () => {
3192
+ const saveRes = await saveCode();
3193
+ if (saveRes) {
3194
+ await services?.codeBlockService.setCodeEditorShowStatus(false);
3195
+ }
3196
+ };
3197
+ const selectHandler = (data) => {
3198
+ services?.codeBlockService.setId(data.id);
3199
+ currentTitle.value = data.name;
3200
+ };
3201
+ return (_ctx, _cache) => {
3202
+ const _component_el_tree = resolveComponent("el-tree");
3203
+ const _component_el_input = resolveComponent("el-input");
3204
+ const _component_el_button = resolveComponent("el-button");
3205
+ const _component_el_card = resolveComponent("el-card");
3206
+ const _component_el_dialog = resolveComponent("el-dialog");
3207
+ return openBlock(), createBlock(_component_el_dialog, {
3208
+ modelValue: unref(isShowCodeBlockEditor),
3209
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(isShowCodeBlockEditor) ? isShowCodeBlockEditor.value = $event : null),
3210
+ title: currentTitle.value,
3211
+ fullscreen: true,
3212
+ "before-close": saveAndClose,
3213
+ "append-to-body": true,
3214
+ "custom-class": "code-editor-dialog"
3215
+ }, {
3216
+ default: withCtx(() => [
3217
+ createVNode(_sfc_main$l, {
3218
+ left: left.value,
3219
+ "onUpdate:left": _cache[1] || (_cache[1] = ($event) => left.value = $event),
3220
+ "min-left": 45,
3221
+ class: "code-editor-layout"
3222
+ }, createSlots({
3223
+ center: withCtx(() => [
3224
+ !unref(isEmpty)(codeConfig.value) ? (openBlock(), createElementBlock("div", {
3225
+ key: 0,
3226
+ class: normalizeClass([
3227
+ unref(mode) === unref(CodeEditorMode).LIST ? "m-editor-code-block-editor-panel-list-mode" : "m-editor-code-block-editor-panel"
3228
+ ])
3229
+ }, [
3230
+ renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id: unref(id) }),
3231
+ createVNode(_component_el_card, { shadow: "never" }, {
3232
+ header: withCtx(() => [
3233
+ createElementVNode("div", _hoisted_4$1, [
3234
+ _hoisted_5$1,
3235
+ codeConfig.value ? (openBlock(), createBlock(_component_el_input, {
3236
+ key: 0,
3237
+ class: "code-name-input",
3238
+ modelValue: codeConfig.value.name,
3239
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeConfig.value.name = $event),
3240
+ disabled: !unref(editable)
3241
+ }, null, 8, ["modelValue", "disabled"])) : createCommentVNode("", true)
3242
+ ])
3243
+ ]),
3244
+ default: withCtx(() => [
3245
+ createElementVNode("div", _hoisted_6$1, [
3246
+ codeConfig.value ? (openBlock(), createBlock(CodeEditor, {
3247
+ key: 0,
3248
+ ref_key: "codeEditor",
3249
+ ref: codeEditor,
3250
+ class: "m-editor-container",
3251
+ "init-values": `${codeConfig.value.content}`,
3252
+ onSave: saveCode,
3253
+ options: {
3254
+ tabSize: 2,
3255
+ fontSize: 16,
3256
+ formatOnPaste: true,
3257
+ readOnly: !unref(editable)
3258
+ }
3259
+ }, null, 8, ["init-values", "options"])) : createCommentVNode("", true),
3260
+ unref(editable) ? (openBlock(), createElementBlock("div", _hoisted_7$1, [
3261
+ createVNode(_component_el_button, {
3262
+ type: "primary",
3263
+ class: "button",
3264
+ onClick: saveCode
3265
+ }, {
3266
+ default: withCtx(() => [
3267
+ _hoisted_8$1
3268
+ ]),
3269
+ _: 1
3270
+ }),
3271
+ createVNode(_component_el_button, {
3272
+ type: "primary",
3273
+ class: "button",
3274
+ onClick: saveAndClose
3275
+ }, {
3276
+ default: withCtx(() => [
3277
+ _hoisted_9$1
3278
+ ]),
3279
+ _: 1
3280
+ })
3281
+ ])) : (openBlock(), createElementBlock("div", _hoisted_10, [
3282
+ createVNode(_component_el_button, {
3283
+ type: "primary",
3284
+ class: "button",
3285
+ onClick: saveAndClose
3286
+ }, {
3287
+ default: withCtx(() => [
3288
+ _hoisted_11
3289
+ ]),
3290
+ _: 1
3291
+ })
3292
+ ]))
3293
+ ])
3294
+ ]),
3295
+ _: 1
3296
+ })
3297
+ ], 2)) : createCommentVNode("", true)
3298
+ ]),
3299
+ _: 2
3300
+ }, [
3301
+ unref(mode) === unref(CodeEditorMode).LIST ? {
3302
+ name: "left",
3303
+ fn: withCtx(() => [
3304
+ !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(_component_el_tree, {
3305
+ key: 0,
3306
+ ref: "tree",
3307
+ "node-key": "id",
3308
+ "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3309
+ data: state.codeList,
3310
+ "highlight-current": true,
3311
+ onNodeClick: selectHandler,
3312
+ "current-node-key": state.codeList[0].id,
3313
+ class: "side-tree"
3314
+ }, {
3315
+ default: withCtx(({ data }) => [
3316
+ createElementVNode("div", {
3317
+ id: data.id,
3318
+ class: "list-container"
3319
+ }, [
3320
+ createElementVNode("div", _hoisted_2$3, [
3321
+ createElementVNode("div", _hoisted_3$1, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1)
3322
+ ])
3323
+ ], 8, _hoisted_1$6)
3324
+ ]),
3325
+ _: 1
3326
+ }, 8, ["data", "current-node-key"])) : createCommentVNode("", true)
3327
+ ])
3328
+ } : void 0
3329
+ ]), 1032, ["left"])
3330
+ ]),
3331
+ _: 3
3332
+ }, 8, ["modelValue", "title"]);
3333
+ };
3334
+ }
3335
+ });
3336
+
3337
+ const _hoisted_1$5 = { class: "m-editor-code-block-list" };
3338
+ const _hoisted_2$2 = { class: "code-header-wrapper" };
3339
+ const _hoisted_3 = /* @__PURE__ */ createTextVNode("\u65B0\u589E");
3340
+ const _hoisted_4 = ["id"];
3341
+ const _hoisted_5 = { class: "list-item" };
3342
+ const _hoisted_6 = { class: "code-name" };
3343
+ const _hoisted_7 = { class: "right-tool" };
3344
+ const _hoisted_8 = {
3345
+ key: 0,
3346
+ class: "code-comp-map-wrapper"
3347
+ };
3348
+ const _hoisted_9 = /* @__PURE__ */ createElementVNode("svg", {
3349
+ class: "arrow-left",
3350
+ viewBox: "0 0 1024 1024",
3351
+ xmlns: "http://www.w3.org/2000/svg",
3352
+ "data-v-029747aa": ""
3353
+ }, [
3354
+ /* @__PURE__ */ createElementVNode("path", {
3355
+ fill: "currentColor",
3356
+ 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"
3357
+ })
3358
+ ], -1);
3359
+ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3360
+ __name: "CodeBlockList",
3361
+ props: {
3362
+ customError: null
3363
+ },
3364
+ setup(__props) {
3365
+ const props = __props;
3366
+ const services = inject("services");
3367
+ const state = reactive({
3368
+ codeList: [],
3369
+ bindComps: {}
3370
+ });
3371
+ const editable = computed(() => services?.codeBlockService.getEditStatus());
3372
+ const getBindCompsByCodeId = (codeId, codeBlockContent) => {
3373
+ if (isEmpty(codeBlockContent) || isEmpty(codeBlockContent.comps)) {
3374
+ state.bindComps[codeId] = [];
3375
+ return;
3376
+ }
3377
+ const compsField = codeBlockContent.comps;
3378
+ const bindCompIds = Object.keys(compsField);
3379
+ const bindCompsFiltered = bindCompIds.filter((compId) => !isEmpty(compsField[compId]));
3380
+ const compsInfo = bindCompsFiltered.map((compId) => ({
3381
+ id: compId,
3382
+ name: getCompName(compId)
3383
+ }));
3384
+ state.bindComps[codeId] = compsInfo;
3385
+ };
3386
+ const initList = async () => {
3387
+ const codeDsl = await services?.codeBlockService.getCodeDsl() || null;
3388
+ if (!codeDsl)
3389
+ return;
3390
+ state.codeList = [];
3391
+ forIn(codeDsl, (value, codeId) => {
3392
+ getBindCompsByCodeId(codeId, value);
3393
+ state.codeList.push({
3394
+ id: codeId,
3395
+ name: value.name,
3396
+ content: value.content,
3397
+ showRelation: true
3398
+ });
3399
+ });
3400
+ };
3401
+ watch(
3402
+ () => services?.codeBlockService.getCodeDsl(),
3403
+ () => {
3404
+ initList();
3405
+ },
3406
+ {
3407
+ immediate: true,
3408
+ deep: true
3409
+ }
3410
+ );
3411
+ watch(
3412
+ () => services?.editorService.get("node"),
3413
+ (curNode) => {
3414
+ if (!curNode?.id)
3415
+ return;
3416
+ forIn(state.bindComps, (bindCompInfo) => {
3417
+ bindCompInfo.forEach((comp) => {
3418
+ if (comp.id === curNode.id) {
3419
+ comp.name = curNode.name;
3420
+ }
3421
+ });
3422
+ });
3423
+ }
3424
+ );
3425
+ const createCodeBlock = async () => {
3426
+ const { codeBlockService } = services || {};
3427
+ if (!codeBlockService) {
3428
+ ElMessage.error("\u65B0\u589E\u4EE3\u7801\u5757\u5931\u8D25");
3429
+ return;
3430
+ }
3431
+ const codeConfig = {
3432
+ name: "\u4EE3\u7801\u5757",
3433
+ content: `() => {
3434
+ // place your code here
3435
+ }`
3436
+ };
3437
+ await codeBlockService.setMode(CodeEditorMode.EDITOR);
3438
+ const id = await codeBlockService.getUniqueId();
3439
+ await codeBlockService.setCodeDslById(id, codeConfig);
3440
+ codeBlockService.setCodeEditorContent(true, id);
3441
+ };
3442
+ const editCode = async (key) => {
3443
+ await services?.codeBlockService.setMode(CodeEditorMode.EDITOR);
3444
+ services?.codeBlockService.setCodeEditorContent(true, key);
3445
+ };
3446
+ const deleteCode = (key) => {
3447
+ const existBinds = !!(state.bindComps[key]?.length > 0);
3448
+ const undeleteableList = services?.codeBlockService.getUndeletableList() || [];
3449
+ if (!existBinds && !undeleteableList.includes(key)) {
3450
+ services?.codeBlockService.deleteCodeDslByIds([key]);
3451
+ } else {
3452
+ if (typeof props.customError === "function") {
3453
+ props.customError(key, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
3454
+ } else {
3455
+ ElMessage.error("\u4EE3\u7801\u5757\u5220\u9664\u5931\u8D25");
3456
+ }
3457
+ }
3458
+ };
3459
+ const filterText = ref("");
3460
+ const tree = ref();
3461
+ const filterNode = (value, data) => {
3462
+ if (!value) {
3463
+ return true;
3464
+ }
3465
+ return `${data.name}${data.id}`.indexOf(value) !== -1;
3466
+ };
3467
+ const filterTextChangeHandler = (val) => {
3468
+ tree.value?.filter(val);
3469
+ };
3470
+ const toggleCombineRelation = (data) => {
3471
+ const { id } = data;
3472
+ const currentCode = state.codeList.find((item) => item.id === id);
3473
+ if (!currentCode)
3474
+ return;
3475
+ currentCode.showRelation = !currentCode?.showRelation;
3476
+ };
3477
+ const getCompName = (compId) => {
3478
+ const node = services?.editorService.getNodeById(compId);
3479
+ return node?.name || String(compId);
3480
+ };
3481
+ const selectComp = (compId) => {
3482
+ const stage = services?.editorService.get("stage");
3483
+ services?.editorService.select(compId);
3484
+ stage?.select(compId);
3485
+ };
3486
+ return (_ctx, _cache) => {
3487
+ const _component_el_input = resolveComponent("el-input");
3488
+ const _component_el_button = resolveComponent("el-button");
3489
+ const _component_el_tooltip = resolveComponent("el-tooltip");
3490
+ const _component_el_tree = resolveComponent("el-tree");
3491
+ return openBlock(), createElementBlock("div", _hoisted_1$5, [
3492
+ renderSlot(_ctx.$slots, "code-block-panel-header", {}, () => [
3493
+ createElementVNode("div", _hoisted_2$2, [
3494
+ createVNode(_component_el_input, {
3495
+ class: normalizeClass([unref(editable) ? "code-filter-input" : "code-filter-input-no-btn"]),
3496
+ size: "small",
3497
+ placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
3498
+ clearable: "",
3499
+ modelValue: filterText.value,
3500
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => filterText.value = $event),
3501
+ onInput: filterTextChangeHandler
3502
+ }, null, 8, ["class", "modelValue"]),
3503
+ unref(editable) ? (openBlock(), createBlock(_component_el_button, {
3504
+ key: 0,
3505
+ class: "create-code-button",
3506
+ type: "primary",
3507
+ size: "small",
3508
+ onClick: createCodeBlock
3509
+ }, {
3510
+ default: withCtx(() => [
3511
+ _hoisted_3
3512
+ ]),
3513
+ _: 1
3514
+ })) : createCommentVNode("", true)
3515
+ ])
3516
+ ]),
3517
+ !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(_component_el_tree, {
3518
+ key: 0,
3519
+ ref_key: "tree",
3520
+ ref: tree,
3521
+ "node-key": "id",
3522
+ "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3523
+ data: state.codeList,
3524
+ "highlight-current": true,
3525
+ "filter-node-method": filterNode,
3526
+ onNodeClick: toggleCombineRelation
3527
+ }, {
3528
+ default: withCtx(({ data }) => [
3529
+ createElementVNode("div", {
3530
+ id: data.id,
3531
+ class: "list-container"
3532
+ }, [
3533
+ createElementVNode("div", _hoisted_5, [
3534
+ createElementVNode("div", _hoisted_6, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1),
3535
+ createElementVNode("div", _hoisted_7, [
3536
+ createVNode(_component_el_tooltip, {
3537
+ effect: "dark",
3538
+ content: unref(editable) ? "\u7F16\u8F91" : "\u67E5\u770B",
3539
+ placement: "bottom"
3540
+ }, {
3541
+ default: withCtx(() => [
3542
+ createVNode(_sfc_main$j, {
3543
+ icon: unref(editable) ? unref(Edit) : unref(View),
3544
+ class: "edit-icon",
3545
+ onClick: withModifiers(($event) => editCode(`${data.id}`), ["stop"])
3546
+ }, null, 8, ["icon", "onClick"])
3547
+ ]),
3548
+ _: 2
3549
+ }, 1032, ["content"]),
3550
+ state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createBlock(_component_el_tooltip, {
3551
+ key: 0,
3552
+ effect: "dark",
3553
+ content: "\u67E5\u770B\u7ED1\u5B9A\u5173\u7CFB",
3554
+ placement: "bottom"
3555
+ }, {
3556
+ default: withCtx(() => [
3557
+ createVNode(_sfc_main$j, {
3558
+ icon: unref(Link),
3559
+ class: "edit-icon",
3560
+ onClick: withModifiers(($event) => toggleCombineRelation(data), ["stop"])
3561
+ }, null, 8, ["icon", "onClick"])
3562
+ ]),
3563
+ _: 2
3564
+ }, 1024)) : createCommentVNode("", true),
3565
+ unref(editable) ? (openBlock(), createBlock(_component_el_tooltip, {
3566
+ key: 1,
3567
+ effect: "dark",
3568
+ content: "\u5220\u9664",
3569
+ placement: "bottom"
3570
+ }, {
3571
+ default: withCtx(() => [
3572
+ createVNode(_sfc_main$j, {
3573
+ icon: unref(Close),
3574
+ class: "edit-icon",
3575
+ onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
3576
+ }, null, 8, ["icon", "onClick"])
3577
+ ]),
3578
+ _: 2
3579
+ }, 1024)) : createCommentVNode("", true),
3580
+ renderSlot(_ctx.$slots, "code-block-panel-tool", {
3581
+ id: data.id
3582
+ })
3583
+ ])
3584
+ ]),
3585
+ data.showRelation && state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
3586
+ _hoisted_9,
3587
+ (openBlock(true), createElementBlock(Fragment, null, renderList(state.bindComps[data.id], (comp, index) => {
3588
+ return openBlock(), createBlock(_component_el_button, {
3589
+ key: index,
3590
+ class: "code-comp",
3591
+ size: "small",
3592
+ plain: true,
3593
+ onClick: withModifiers(($event) => selectComp(comp.id), ["stop"])
3594
+ }, {
3595
+ default: withCtx(() => [
3596
+ createTextVNode(toDisplayString(comp.name), 1)
3597
+ ]),
3598
+ _: 2
3599
+ }, 1032, ["onClick"]);
3600
+ }), 128))
3601
+ ])) : createCommentVNode("", true)
3602
+ ], 8, _hoisted_4)
3603
+ ]),
3604
+ _: 3
3605
+ }, 8, ["data"])) : createCommentVNode("", true),
3606
+ createVNode(_sfc_main$f, null, {
3607
+ "code-block-edit-panel-header": withCtx(({ id }) => [
3608
+ renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
3609
+ ]),
3610
+ _: 3
3611
+ })
3612
+ ]);
3613
+ };
3614
+ }
3615
+ });
3616
+
2735
3617
  const _hoisted_1$4 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
2736
3618
  const _hoisted_2$1 = ["onClick", "onDragstart"];
2737
3619
  const _sfc_main$d = /* @__PURE__ */ defineComponent({
@@ -2844,7 +3726,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2844
3726
  onDrag: dragHandler
2845
3727
  }, [
2846
3728
  renderSlot(_ctx.$slots, "component-list-item", { component: item }, () => [
2847
- createVNode(_sfc_main$h, {
3729
+ createVNode(_sfc_main$j, {
2848
3730
  icon: item.icon
2849
3731
  }, null, 8, ["icon"]),
2850
3732
  createVNode(_component_el_tooltip, {
@@ -2964,7 +3846,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
2964
3846
  }, [
2965
3847
  createElementVNode("div", null, [
2966
3848
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.menuData, (item, index) => {
2967
- return openBlock(), createBlock(_sfc_main$g, {
3849
+ return openBlock(), createBlock(_sfc_main$i, {
2968
3850
  "event-type": "mouseup",
2969
3851
  data: item,
2970
3852
  key: index,
@@ -3331,7 +4213,7 @@ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3331
4213
  const LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$3]]);
3332
4214
 
3333
4215
  const _sfc_main$9 = defineComponent({
3334
- components: { MIcon: _sfc_main$h },
4216
+ components: { MIcon: _sfc_main$j },
3335
4217
  props: {
3336
4218
  data: {
3337
4219
  type: [Object, String]
@@ -3360,6 +4242,14 @@ const _sfc_main$9 = defineComponent({
3360
4242
  component: LayerPanel,
3361
4243
  slots: {}
3362
4244
  };
4245
+ case "code-block":
4246
+ return {
4247
+ type: "component",
4248
+ icon: EditPen,
4249
+ text: "\u4EE3\u7801\u7F16\u8F91",
4250
+ component: _sfc_main$e,
4251
+ slots: {}
4252
+ };
3363
4253
  default:
3364
4254
  return void 0;
3365
4255
  }
@@ -3416,6 +4306,30 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
3416
4306
  _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
4307
  ])
3418
4308
  } : void 0,
4309
+ _ctx.data === "code-block" || _ctx.config.slots?.codeBlockPanelHeader ? {
4310
+ name: "code-block-panel-header",
4311
+ fn: withCtx(() => [
4312
+ _ctx.data === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-header", { key: 0 }) : _ctx.config.slots?.codeBlockPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots.codeBlockPanelHeader), { key: 1 })) : createCommentVNode("", true)
4313
+ ])
4314
+ } : void 0,
4315
+ _ctx.data === "code-block" || _ctx.config.slots?.codeBlockPanelTool ? {
4316
+ name: "code-block-panel-tool",
4317
+ fn: withCtx(({ id }) => [
4318
+ _ctx.data === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
4319
+ key: 0,
4320
+ id
4321
+ }) : _ctx.config.slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
4322
+ ])
4323
+ } : void 0,
4324
+ _ctx.data === "code-block" || _ctx.config.slots?.codeBlockEditPanelHeader ? {
4325
+ name: "code-block-edit-panel-header",
4326
+ fn: withCtx(({ id }) => [
4327
+ _ctx.data === "code-block" ? renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
4328
+ key: 0,
4329
+ id
4330
+ }) : _ctx.config.slots?.codeBlockEditPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots.codeBlockEditPanelHeader), { key: 1 })) : createCommentVNode("", true)
4331
+ ])
4332
+ } : void 0,
3419
4333
  _ctx.data === "layer" || _ctx.config.slots?.layerNodeContent ? {
3420
4334
  name: "layer-node-content",
3421
4335
  fn: withCtx(({ data: nodeData, node }) => [
@@ -3443,7 +4357,7 @@ const _sfc_main$8 = defineComponent({
3443
4357
  props: {
3444
4358
  data: {
3445
4359
  type: Object,
3446
- default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer"] })
4360
+ default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer", "code-block"] })
3447
4361
  }
3448
4362
  },
3449
4363
  setup(props) {
@@ -3503,6 +4417,24 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
3503
4417
  fn: withCtx(({ component }) => [
3504
4418
  renderSlot(_ctx.$slots, "component-list-item", { component })
3505
4419
  ])
4420
+ } : void 0,
4421
+ item === "code-block" ? {
4422
+ name: "code-block-panel-header",
4423
+ fn: withCtx(() => [
4424
+ renderSlot(_ctx.$slots, "code-block-panel-header")
4425
+ ])
4426
+ } : void 0,
4427
+ item === "code-block" ? {
4428
+ name: "code-block-panel-tool",
4429
+ fn: withCtx(({ id }) => [
4430
+ renderSlot(_ctx.$slots, "code-block-panel-tool", { id })
4431
+ ])
4432
+ } : void 0,
4433
+ item === "code-block" ? {
4434
+ name: "code-block-edit-panel-header",
4435
+ fn: withCtx(({ id }) => [
4436
+ renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
4437
+ ])
3506
4438
  } : void 0
3507
4439
  ]), 1032, ["data"]);
3508
4440
  }), 128))
@@ -3598,14 +4530,14 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3598
4530
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3599
4531
  onClick: addPage
3600
4532
  }, [
3601
- createVNode(_sfc_main$h, { icon: unref(Plus) }, null, 8, ["icon"])
4533
+ createVNode(_sfc_main$j, { icon: unref(Plus) }, null, 8, ["icon"])
3602
4534
  ])) : (openBlock(), createElementBlock("div", _hoisted_1$1)),
3603
4535
  canScroll.value ? (openBlock(), createElementBlock("div", {
3604
4536
  key: 2,
3605
4537
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3606
4538
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
3607
4539
  }, [
3608
- createVNode(_sfc_main$h, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
4540
+ createVNode(_sfc_main$j, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
3609
4541
  ])) : createCommentVNode("", true),
3610
4542
  unref(pageLength) ? (openBlock(), createElementBlock("div", {
3611
4543
  key: 3,
@@ -3621,7 +4553,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3621
4553
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3622
4554
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
3623
4555
  }, [
3624
- createVNode(_sfc_main$h, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
4556
+ createVNode(_sfc_main$j, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
3625
4557
  ])) : createCommentVNode("", true)
3626
4558
  ], 512);
3627
4559
  };
@@ -3693,7 +4625,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
3693
4625
  default: withCtx(() => [
3694
4626
  createElementVNode("div", null, [
3695
4627
  renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
3696
- createVNode(_sfc_main$g, {
4628
+ createVNode(_sfc_main$i, {
3697
4629
  data: {
3698
4630
  type: "button",
3699
4631
  text: "\u590D\u5236",
@@ -3701,7 +4633,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
3701
4633
  handler: () => copy(item)
3702
4634
  }
3703
4635
  }, null, 8, ["data"]),
3704
- createVNode(_sfc_main$g, {
4636
+ createVNode(_sfc_main$i, {
3705
4637
  data: {
3706
4638
  type: "button",
3707
4639
  text: "\u5220\u9664",
@@ -4475,11 +5407,11 @@ const componentListService = new ComponentList();
4475
5407
  const _sfc_main = defineComponent({
4476
5408
  name: "m-editor",
4477
5409
  components: {
4478
- NavMenu: _sfc_main$f,
5410
+ NavMenu: _sfc_main$h,
4479
5411
  Sidebar,
4480
5412
  Workspace: _sfc_main$1,
4481
- PropsPanel: _sfc_main$e,
4482
- Framework: _sfc_main$i
5413
+ PropsPanel: _sfc_main$g,
5414
+ Framework: _sfc_main$k
4483
5415
  },
4484
5416
  props: {
4485
5417
  modelValue: {
@@ -4574,7 +5506,9 @@ const _sfc_main = defineComponent({
4574
5506
  });
4575
5507
  watch(
4576
5508
  () => props.modelValue,
4577
- (modelValue) => editorService.set("root", modelValue),
5509
+ (modelValue) => {
5510
+ editorService.set("root", modelValue);
5511
+ },
4578
5512
  {
4579
5513
  immediate: true
4580
5514
  }
@@ -4637,6 +5571,7 @@ const _sfc_main = defineComponent({
4637
5571
  uiService.destroy();
4638
5572
  componentListService.destroy();
4639
5573
  storageService.destroy();
5574
+ codeBlockService.destroy();
4640
5575
  });
4641
5576
  const services = {
4642
5577
  componentListService,
@@ -4645,7 +5580,8 @@ const _sfc_main = defineComponent({
4645
5580
  propsService,
4646
5581
  editorService,
4647
5582
  uiService,
4648
- storageService
5583
+ storageService,
5584
+ codeBlockService
4649
5585
  };
4650
5586
  provide("services", services);
4651
5587
  provide("layerContentMenu", props.layerContentMenu);
@@ -4699,6 +5635,15 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
4699
5635
  "component-list-item": withCtx(({ component }) => [
4700
5636
  renderSlot(_ctx.$slots, "component-list-item", { component })
4701
5637
  ]),
5638
+ "code-block-panel-header": withCtx(() => [
5639
+ renderSlot(_ctx.$slots, "code-block-panel-header")
5640
+ ]),
5641
+ "code-block-panel-tool": withCtx(({ id }) => [
5642
+ renderSlot(_ctx.$slots, "code-block-panel-tool", { id })
5643
+ ]),
5644
+ "code-block-edit-panel-header": withCtx(({ id }) => [
5645
+ renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
5646
+ ]),
4702
5647
  _: 3
4703
5648
  }, 8, ["data"])
4704
5649
  ])
@@ -4751,12 +5696,13 @@ const index = {
4751
5696
  app.config.globalProperties.$TMAGIC_EDITOR = option;
4752
5697
  setConfig(option);
4753
5698
  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);
5699
+ app.component("m-fields-ui-select", _sfc_main$p);
5700
+ app.component("m-fields-code-link", _sfc_main$r);
5701
+ app.component("m-fields-vs-code", _sfc_main$s);
4757
5702
  app.component(CodeEditor.name, CodeEditor);
5703
+ app.component("m-fields-code-select", _sfc_main$q);
4758
5704
  }
4759
5705
  };
4760
5706
 
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 };
5707
+ export { COPY_STORAGE_KEY, _sfc_main$e as CodeBlockList, CodeDeleteErrorType, CodeEditorMode, 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, CodeEditor 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
5708
  //# sourceMappingURL=tmagic-editor.mjs.map