@tmagic/editor 1.7.6 → 1.7.7

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.
@@ -11,8 +11,6 @@ import { defineComponent, createBlock, createElementBlock, openBlock, unref, wit
11
11
  import { Edit, FullScreen, View, Close, Coin, Delete, Plus, Grid, ArrowDown, ArrowLeftBold, ArrowRightBold, Files, Search, DocumentCopy, CaretBottom, Memo, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Document, Sugar, ArrowRight, CopyDocument, Hide, EditPen, List, Goods, CloseBold, Top, Bottom } from '@element-plus/icons-vue';
12
12
  import { throttle, isEmpty, isObject, cloneDeep, mergeWith, uniq, get, map, has, pick, keys } from 'lodash-es';
13
13
  import serialize from 'serialize-javascript';
14
- import { emmetHTML, emmetCSS } from 'emmet-monaco-es';
15
- import * as monaco from 'monaco-editor';
16
14
  import { HookCodeType, HookType, NODE_DISABLE_CODE_BLOCK_KEY, NODE_DISABLE_DATA_SOURCE_KEY, NODE_CONDS_RESULT_KEY, NODE_CONDS_KEY, Target, Watcher, NodeType, ActionType, DepTargetType, traverseTarget, createCodeBlockTarget, createDataSourceTarget, createDataSourceCondTarget, createDataSourceMethodTarget, updateNode } from '@tmagic/core';
17
15
  export { DepTargetType } from '@tmagic/core';
18
16
  import { isPage, isPageFragment, isPop, getNodePath, isNumber, getElById, calcValueByFontsize, isValueIncludeDataSource, toLine, guid, getValueByKeyPath, setValueByKeyPath, getNodeInfo, dataSourceTemplateRegExp, getKeysArray, getKeys, convertToNumber, getIdFromEl, traverseNode, getDefaultValueFromFields, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, removeDataSourceFieldPrefix, DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, removeClassName, addClassName, removeClassNameByClassName, getNodes, getDepNodeIds } from '@tmagic/utils';
@@ -86,8 +84,18 @@ const setEditorConfig = (option) => {
86
84
  };
87
85
  const getEditorConfig = (key) => $TMAGIC_EDITOR[key];
88
86
 
89
- emmetHTML(monaco);
90
- emmetCSS(monaco, ["css", "scss"]);
87
+ let cached;
88
+ const loadMonaco = () => {
89
+ if (!cached) {
90
+ cached = Promise.all([import('emmet-monaco-es'), import('monaco-editor')]).then(([emmet, monaco]) => {
91
+ const { emmetHTML, emmetCSS } = emmet;
92
+ emmetHTML(monaco);
93
+ emmetCSS(monaco, ["css", "scss"]);
94
+ return monaco;
95
+ });
96
+ }
97
+ return cached;
98
+ };
91
99
 
92
100
  const _hoisted_1$_ = { class: "magic-code-editor" };
93
101
  const _hoisted_2$o = {
@@ -142,7 +150,7 @@ const _sfc_main$1r = /* @__PURE__ */ defineComponent({
142
150
  const editorRect = editorElement.getBoundingClientRect();
143
151
  const scrollableRect = scrollableElement.getBoundingClientRect();
144
152
  extraHeight = Math.max(editorRect.height - scrollableRect.height, 0);
145
- if (extraHeight === 0) {
153
+ if (extraHeight === 0 && monaco) {
146
154
  const editorOptions = vsEditor.getOptions();
147
155
  const scrollBeyondLastLine = editorOptions.get(monaco.editor.EditorOption.scrollBeyondLastLine);
148
156
  const padding = editorOptions.get(monaco.editor.EditorOption.padding);
@@ -164,7 +172,7 @@ const _sfc_main$1r = /* @__PURE__ */ defineComponent({
164
172
  }
165
173
  }
166
174
  let lineHeight = 20;
167
- if (vsEditor) {
175
+ if (vsEditor && monaco) {
168
176
  const editorOptions = vsEditor.getOptions();
169
177
  lineHeight = editorOptions.get(monaco.editor.EditorOption.lineHeight) || 20;
170
178
  }
@@ -211,6 +219,7 @@ const _sfc_main$1r = /* @__PURE__ */ defineComponent({
211
219
  }
212
220
  return getEditorConfig("parseDSL")(v);
213
221
  };
222
+ let monaco = null;
214
223
  let vsEditor = null;
215
224
  let vsDiffEditor = null;
216
225
  const values = ref("");
@@ -225,6 +234,7 @@ const _sfc_main$1r = /* @__PURE__ */ defineComponent({
225
234
  const setEditorValue = (v, m) => {
226
235
  values.value = toString(v, props.language.toLocaleLowerCase());
227
236
  setAutoHeight(values.value);
237
+ if (!monaco) return;
228
238
  if (props.type === "diff") {
229
239
  const originalModel = monaco.editor.createModel(values.value, "text/javascript");
230
240
  const modifiedModel = monaco.editor.createModel(toString(m, props.language), "text/javascript");
@@ -263,6 +273,7 @@ const _sfc_main$1r = /* @__PURE__ */ defineComponent({
263
273
  await nextTick();
264
274
  }
265
275
  cachedExtraHeight = null;
276
+ monaco = await loadMonaco();
266
277
  const options = {
267
278
  value: values.value,
268
279
  language: props.language,
@@ -271,14 +282,14 @@ const _sfc_main$1r = /* @__PURE__ */ defineComponent({
271
282
  ...props.options
272
283
  };
273
284
  if (props.type === "diff") {
274
- vsDiffEditor = getEditorConfig("customCreateMonacoDiffEditor")(monaco, codeEditorEl.value, options);
285
+ vsDiffEditor = await getEditorConfig("customCreateMonacoDiffEditor")(monaco, codeEditorEl.value, options);
275
286
  vsDiffEditor.getModifiedEditor().onDidChangeModelContent(() => {
276
287
  if (props.autosize) {
277
288
  setAutoHeight(getEditorValue());
278
289
  }
279
290
  });
280
291
  } else {
281
- vsEditor = getEditorConfig("customCreateMonacoEditor")(monaco, codeEditorEl.value, options);
292
+ vsEditor = await getEditorConfig("customCreateMonacoEditor")(monaco, codeEditorEl.value, options);
282
293
  vsEditor.onDidChangeModelContent(() => {
283
294
  if (props.autosize) {
284
295
  setAutoHeight(getEditorValue());
@@ -332,6 +343,7 @@ const _sfc_main$1r = /* @__PURE__ */ defineComponent({
332
343
  vsDiffEditor?.dispose();
333
344
  vsEditor = null;
334
345
  vsDiffEditor = null;
346
+ monaco = null;
335
347
  cachedExtraHeight = null;
336
348
  });
337
349
  onUnmounted(() => {
@@ -686,6 +698,7 @@ const numberOptions = [
686
698
  ];
687
699
  const styleTabConfig = {
688
700
  title: "样式",
701
+ lazy: true,
689
702
  display: ({ services }) => !(services.uiService.get("showStylePanel") ?? true),
690
703
  items: [
691
704
  {
@@ -752,6 +765,7 @@ const styleTabConfig = {
752
765
  };
753
766
  const eventTabConfig = {
754
767
  title: "事件",
768
+ lazy: true,
755
769
  items: [
756
770
  {
757
771
  name: "events",
@@ -9726,8 +9740,8 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
9726
9740
  options: unref(codeOptions),
9727
9741
  onSave: saveCode
9728
9742
  }, null, 8, ["init-values", "options"])
9729
- ]) : (openBlock(), createBlock(_sfc_main$B, {
9730
- key: 1,
9743
+ ]) : createCommentVNode("v-if", true),
9744
+ withDirectives(createVNode(_sfc_main$B, {
9731
9745
  ref: "splitView",
9732
9746
  class: "m-editor-content",
9733
9747
  "left-class": "m-editor-framework-left",
@@ -9781,7 +9795,9 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
9781
9795
  ]),
9782
9796
  key: "0"
9783
9797
  } : void 0
9784
- ]), 1032, ["left", "right", "min-left", "min-right", "min-center", "width"])),
9798
+ ]), 1032, ["left", "right", "min-left", "min-right", "min-center", "width"]), [
9799
+ [vShow, !showSrc.value]
9800
+ ]),
9785
9801
  renderSlot(_ctx.$slots, "content-after"),
9786
9802
  renderSlot(_ctx.$slots, "footer")
9787
9803
  ],
@@ -1,27 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tmagic/design'), require('@tmagic/form'), require('@tmagic/table'), require('vue'), require('@element-plus/icons-vue'), require('serialize-javascript'), require('emmet-monaco-es'), require('monaco-editor'), require('@tmagic/core'), require('@tmagic/utils'), require('moveable'), require('@tmagic/stage'), require('events'), require('gesto'), require('deep-object-diff'), require('sortablejs'), require('keycon')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tmagic/design', '@tmagic/form', '@tmagic/table', 'vue', '@element-plus/icons-vue', 'serialize-javascript', 'emmet-monaco-es', 'monaco-editor', '@tmagic/core', '@tmagic/utils', 'moveable', '@tmagic/stage', 'events', 'gesto', 'deep-object-diff', 'sortablejs', 'keycon'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.designPlugin, global.formPlugin, global.tablePlugin, global.Vue, global.iconsVue, global.serialize, global.emmetMonacoEs, global.monaco, global.core, global.utils, global.VanillaMoveable, global.StageCore, global.events, global.Gesto, global.deepObjectDiff, global.Sortable, global.KeyController));
5
- })(this, (function (exports, designPlugin, formPlugin, tablePlugin, vue, iconsVue, serialize, emmetMonacoEs, monaco, core, utils, VanillaMoveable, StageCore, events, Gesto, deepObjectDiff, Sortable, KeyController) { 'use strict';
6
-
7
- function _interopNamespaceDefault(e) {
8
- const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
9
- if (e) {
10
- for (const k in e) {
11
- if (k !== 'default') {
12
- const d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: () => e[k]
16
- });
17
- }
18
- }
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- const monaco__namespace = /*#__PURE__*/_interopNamespaceDefault(monaco);
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tmagic/design'), require('@tmagic/form'), require('@tmagic/table'), require('vue'), require('@element-plus/icons-vue'), require('serialize-javascript'), require('@tmagic/core'), require('@tmagic/utils'), require('moveable'), require('@tmagic/stage'), require('events'), require('gesto'), require('deep-object-diff'), require('sortablejs'), require('keycon')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@tmagic/design', '@tmagic/form', '@tmagic/table', 'vue', '@element-plus/icons-vue', 'serialize-javascript', '@tmagic/core', '@tmagic/utils', 'moveable', '@tmagic/stage', 'events', 'gesto', 'deep-object-diff', 'sortablejs', 'keycon'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.designPlugin, global.formPlugin, global.tablePlugin, global.Vue, global.iconsVue, global.serialize, global.core, global.utils, global.VanillaMoveable, global.StageCore, global.events, global.Gesto, global.deepObjectDiff, global.Sortable, global.KeyController));
5
+ })(this, (function (exports, designPlugin, formPlugin, tablePlugin, vue, iconsVue, serialize, core, utils, VanillaMoveable, StageCore, events, Gesto, deepObjectDiff, Sortable, KeyController) { 'use strict';
25
6
 
26
7
  /** Detect free variable `global` from Node.js. */
27
8
  var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
@@ -4879,8 +4860,18 @@
4879
4860
  };
4880
4861
  const getEditorConfig = (key) => $TMAGIC_EDITOR[key];
4881
4862
 
4882
- emmetMonacoEs.emmetHTML(monaco__namespace);
4883
- emmetMonacoEs.emmetCSS(monaco__namespace, ["css", "scss"]);
4863
+ let cached;
4864
+ const loadMonaco = () => {
4865
+ if (!cached) {
4866
+ cached = Promise.all([import('emmet-monaco-es'), import('monaco-editor')]).then(([emmet, monaco]) => {
4867
+ const { emmetHTML, emmetCSS } = emmet;
4868
+ emmetHTML(monaco);
4869
+ emmetCSS(monaco, ["css", "scss"]);
4870
+ return monaco;
4871
+ });
4872
+ }
4873
+ return cached;
4874
+ };
4884
4875
 
4885
4876
  const _hoisted_1$_ = { class: "magic-code-editor" };
4886
4877
  const _hoisted_2$o = {
@@ -4935,11 +4926,11 @@
4935
4926
  const editorRect = editorElement.getBoundingClientRect();
4936
4927
  const scrollableRect = scrollableElement.getBoundingClientRect();
4937
4928
  extraHeight = Math.max(editorRect.height - scrollableRect.height, 0);
4938
- if (extraHeight === 0) {
4929
+ if (extraHeight === 0 && monaco) {
4939
4930
  const editorOptions = vsEditor.getOptions();
4940
- const scrollBeyondLastLine = editorOptions.get(monaco__namespace.editor.EditorOption.scrollBeyondLastLine);
4941
- const padding = editorOptions.get(monaco__namespace.editor.EditorOption.padding);
4942
- const lineHeight = editorOptions.get(monaco__namespace.editor.EditorOption.lineHeight) || 20;
4931
+ const scrollBeyondLastLine = editorOptions.get(monaco.editor.EditorOption.scrollBeyondLastLine);
4932
+ const padding = editorOptions.get(monaco.editor.EditorOption.padding);
4933
+ const lineHeight = editorOptions.get(monaco.editor.EditorOption.lineHeight) || 20;
4943
4934
  extraHeight = (scrollBeyondLastLine ? lineHeight : 0) + (padding?.top || 0) + (padding?.bottom || 0) + 10;
4944
4935
  }
4945
4936
  }
@@ -4957,9 +4948,9 @@
4957
4948
  }
4958
4949
  }
4959
4950
  let lineHeight = 20;
4960
- if (vsEditor) {
4951
+ if (vsEditor && monaco) {
4961
4952
  const editorOptions = vsEditor.getOptions();
4962
- lineHeight = editorOptions.get(monaco__namespace.editor.EditorOption.lineHeight) || 20;
4953
+ lineHeight = editorOptions.get(monaco.editor.EditorOption.lineHeight) || 20;
4963
4954
  }
4964
4955
  if (cachedExtraHeight === null) {
4965
4956
  cachedExtraHeight = calculateExtraHeight();
@@ -5004,6 +4995,7 @@
5004
4995
  }
5005
4996
  return getEditorConfig("parseDSL")(v);
5006
4997
  };
4998
+ let monaco = null;
5007
4999
  let vsEditor = null;
5008
5000
  let vsDiffEditor = null;
5009
5001
  const values = vue.ref("");
@@ -5018,9 +5010,10 @@
5018
5010
  const setEditorValue = (v, m) => {
5019
5011
  values.value = toString(v, props.language.toLocaleLowerCase());
5020
5012
  setAutoHeight(values.value);
5013
+ if (!monaco) return;
5021
5014
  if (props.type === "diff") {
5022
- const originalModel = monaco__namespace.editor.createModel(values.value, "text/javascript");
5023
- const modifiedModel = monaco__namespace.editor.createModel(toString(m, props.language), "text/javascript");
5015
+ const originalModel = monaco.editor.createModel(values.value, "text/javascript");
5016
+ const modifiedModel = monaco.editor.createModel(toString(m, props.language), "text/javascript");
5024
5017
  const position2 = vsDiffEditor?.getPosition();
5025
5018
  const result2 = vsDiffEditor?.setModel({
5026
5019
  original: originalModel,
@@ -5056,6 +5049,7 @@
5056
5049
  await vue.nextTick();
5057
5050
  }
5058
5051
  cachedExtraHeight = null;
5052
+ monaco = await loadMonaco();
5059
5053
  const options = {
5060
5054
  value: values.value,
5061
5055
  language: props.language,
@@ -5064,14 +5058,14 @@
5064
5058
  ...props.options
5065
5059
  };
5066
5060
  if (props.type === "diff") {
5067
- vsDiffEditor = getEditorConfig("customCreateMonacoDiffEditor")(monaco__namespace, codeEditorEl.value, options);
5061
+ vsDiffEditor = await getEditorConfig("customCreateMonacoDiffEditor")(monaco, codeEditorEl.value, options);
5068
5062
  vsDiffEditor.getModifiedEditor().onDidChangeModelContent(() => {
5069
5063
  if (props.autosize) {
5070
5064
  setAutoHeight(getEditorValue());
5071
5065
  }
5072
5066
  });
5073
5067
  } else {
5074
- vsEditor = getEditorConfig("customCreateMonacoEditor")(monaco__namespace, codeEditorEl.value, options);
5068
+ vsEditor = await getEditorConfig("customCreateMonacoEditor")(monaco, codeEditorEl.value, options);
5075
5069
  vsEditor.onDidChangeModelContent(() => {
5076
5070
  if (props.autosize) {
5077
5071
  setAutoHeight(getEditorValue());
@@ -5125,6 +5119,7 @@
5125
5119
  vsDiffEditor?.dispose();
5126
5120
  vsEditor = null;
5127
5121
  vsDiffEditor = null;
5122
+ monaco = null;
5128
5123
  cachedExtraHeight = null;
5129
5124
  });
5130
5125
  vue.onUnmounted(() => {
@@ -5479,6 +5474,7 @@
5479
5474
  ];
5480
5475
  const styleTabConfig = {
5481
5476
  title: "样式",
5477
+ lazy: true,
5482
5478
  display: ({ services }) => !(services.uiService.get("showStylePanel") ?? true),
5483
5479
  items: [
5484
5480
  {
@@ -5545,6 +5541,7 @@
5545
5541
  };
5546
5542
  const eventTabConfig = {
5547
5543
  title: "事件",
5544
+ lazy: true,
5548
5545
  items: [
5549
5546
  {
5550
5547
  name: "events",
@@ -14519,8 +14516,8 @@
14519
14516
  options: vue.unref(codeOptions),
14520
14517
  onSave: saveCode
14521
14518
  }, null, 8, ["init-values", "options"])
14522
- ]) : (vue.openBlock(), vue.createBlock(_sfc_main$B, {
14523
- key: 1,
14519
+ ]) : vue.createCommentVNode("v-if", true),
14520
+ vue.withDirectives(vue.createVNode(_sfc_main$B, {
14524
14521
  ref: "splitView",
14525
14522
  class: "m-editor-content",
14526
14523
  "left-class": "m-editor-framework-left",
@@ -14574,7 +14571,9 @@
14574
14571
  ]),
14575
14572
  key: "0"
14576
14573
  } : void 0
14577
- ]), 1032, ["left", "right", "min-left", "min-right", "min-center", "width"])),
14574
+ ]), 1032, ["left", "right", "min-left", "min-right", "min-center", "width"]), [
14575
+ [vue.vShow, !showSrc.value]
14576
+ ]),
14578
14577
  vue.renderSlot(_ctx.$slots, "content-after"),
14579
14578
  vue.renderSlot(_ctx.$slots, "footer")
14580
14579
  ],
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.6",
2
+ "version": "1.7.7",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -49,7 +49,7 @@
49
49
  "@element-plus/icons-vue": "^2.3.2",
50
50
  "buffer": "^6.0.3",
51
51
  "deep-object-diff": "^1.1.9",
52
- "emmet-monaco-es": "^5.6.1",
52
+ "emmet-monaco-es": "^5.7.0",
53
53
  "events": "^3.3.0",
54
54
  "gesto": "^1.19.4",
55
55
  "keycon": "^1.4.0",
@@ -57,11 +57,11 @@
57
57
  "moveable": "^0.53.0",
58
58
  "serialize-javascript": "^7.0.0",
59
59
  "sortablejs": "^1.15.6",
60
- "@tmagic/design": "1.7.6",
61
- "@tmagic/form": "1.7.6",
62
- "@tmagic/utils": "1.7.6",
63
- "@tmagic/stage": "1.7.6",
64
- "@tmagic/table": "1.7.6"
60
+ "@tmagic/design": "1.7.7",
61
+ "@tmagic/table": "1.7.7",
62
+ "@tmagic/stage": "1.7.7",
63
+ "@tmagic/form": "1.7.7",
64
+ "@tmagic/utils": "1.7.7"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/events": "^3.0.3",
@@ -75,7 +75,7 @@
75
75
  "monaco-editor": "^0.48.0",
76
76
  "typescript": "^5.9.3",
77
77
  "vue": "^3.5.24",
78
- "@tmagic/core": "1.7.6"
78
+ "@tmagic/core": "1.7.7"
79
79
  },
80
80
  "peerDependenciesMeta": {
81
81
  "typescript": {
@@ -20,13 +20,14 @@
20
20
  import { computed, nextTick, onBeforeUnmount, onMounted, onUnmounted, ref, useTemplateRef, watch } from 'vue';
21
21
  import { FullScreen } from '@element-plus/icons-vue';
22
22
  import { throttle } from 'lodash-es';
23
+ import type * as Monaco from 'monaco-editor';
23
24
  import serialize from 'serialize-javascript';
24
25
 
25
26
  import { TMagicButton } from '@tmagic/design';
26
27
 
27
28
  import MIcon from '@editor/components/Icon.vue';
28
29
  import { getEditorConfig } from '@editor/utils/config';
29
- import monaco from '@editor/utils/monaco-editor';
30
+ import loadMonaco from '@editor/utils/monaco-editor';
30
31
 
31
32
  defineOptions({
32
33
  name: 'MEditorCodeEditor',
@@ -38,7 +39,7 @@ const props = withDefaults(
38
39
  modifiedValues?: any;
39
40
  type?: 'diff';
40
41
  language?: string;
41
- options?: monaco.editor.IStandaloneEditorConstructionOptions;
42
+ options?: Monaco.editor.IStandaloneEditorConstructionOptions;
42
43
  height?: string;
43
44
  autoSave?: boolean;
44
45
  parse?: boolean;
@@ -99,7 +100,7 @@ const calculateExtraHeight = (): number => {
99
100
  extraHeight = Math.max(editorRect.height - scrollableRect.height, 0);
100
101
 
101
102
  // 如果无法获取到有效的差值,使用编辑器配置中的相关选项
102
- if (extraHeight === 0) {
103
+ if (extraHeight === 0 && monaco) {
103
104
  const editorOptions = vsEditor.getOptions();
104
105
  const scrollBeyondLastLine = editorOptions.get(monaco.editor.EditorOption.scrollBeyondLastLine);
105
106
  const padding = editorOptions.get(monaco.editor.EditorOption.padding);
@@ -127,7 +128,7 @@ const setAutoHeight = (v = '') => {
127
128
 
128
129
  // 获取编辑器实际行高,如果编辑器还未初始化则使用默认值
129
130
  let lineHeight = 20;
130
- if (vsEditor) {
131
+ if (vsEditor && monaco) {
131
132
  const editorOptions = vsEditor.getOptions();
132
133
  lineHeight = editorOptions.get(monaco.editor.EditorOption.lineHeight) || 20;
133
134
  }
@@ -188,8 +189,9 @@ const parseCode = (v: string | any, language: string): any => {
188
189
  return getEditorConfig('parseDSL')(v);
189
190
  };
190
191
 
191
- let vsEditor: monaco.editor.IStandaloneCodeEditor | null = null;
192
- let vsDiffEditor: monaco.editor.IStandaloneDiffEditor | null = null;
192
+ let monaco: typeof import('monaco-editor') | null = null;
193
+ let vsEditor: Monaco.editor.IStandaloneCodeEditor | null = null;
194
+ let vsDiffEditor: Monaco.editor.IStandaloneDiffEditor | null = null;
193
195
 
194
196
  const values = ref('');
195
197
  const loading = ref(false);
@@ -207,6 +209,8 @@ const setEditorValue = (v: string | any, m: string | any) => {
207
209
 
208
210
  setAutoHeight(values.value);
209
211
 
212
+ if (!monaco) return;
213
+
210
214
  if (props.type === 'diff') {
211
215
  const originalModel = monaco.editor.createModel(values.value, 'text/javascript');
212
216
  const modifiedModel = monaco.editor.createModel(toString(m, props.language), 'text/javascript');
@@ -255,6 +259,8 @@ const init = async () => {
255
259
  // 重置缓存的额外高度,因为编辑器重新初始化
256
260
  cachedExtraHeight = null;
257
261
 
262
+ monaco = await loadMonaco();
263
+
258
264
  const options = {
259
265
  value: values.value,
260
266
  language: props.language,
@@ -264,7 +270,7 @@ const init = async () => {
264
270
  };
265
271
 
266
272
  if (props.type === 'diff') {
267
- vsDiffEditor = getEditorConfig('customCreateMonacoDiffEditor')(monaco, codeEditorEl.value, options);
273
+ vsDiffEditor = await getEditorConfig('customCreateMonacoDiffEditor')(monaco!, codeEditorEl.value, options);
268
274
 
269
275
  // 监听diff编辑器内容变化
270
276
  vsDiffEditor.getModifiedEditor().onDidChangeModelContent(() => {
@@ -274,7 +280,7 @@ const init = async () => {
274
280
  }
275
281
  });
276
282
  } else {
277
- vsEditor = getEditorConfig('customCreateMonacoEditor')(monaco, codeEditorEl.value, options);
283
+ vsEditor = await getEditorConfig('customCreateMonacoEditor')(monaco!, codeEditorEl.value, options);
278
284
 
279
285
  // 监听编辑器内容变化
280
286
  vsEditor.onDidChangeModelContent(() => {
@@ -343,6 +349,7 @@ onBeforeUnmount(() => {
343
349
 
344
350
  vsEditor = null;
345
351
  vsDiffEditor = null;
352
+ monaco = null;
346
353
 
347
354
  // 重置缓存
348
355
  cachedExtraHeight = null;
@@ -17,7 +17,7 @@
17
17
  </slot>
18
18
 
19
19
  <SplitView
20
- v-else
20
+ v-show="!showSrc"
21
21
  ref="splitView"
22
22
  class="m-editor-content"
23
23
  left-class="m-editor-framework-left"
package/src/type.ts CHANGED
@@ -18,6 +18,7 @@
18
18
 
19
19
  import type { Component } from 'vue';
20
20
  import type EventEmitter from 'events';
21
+ import type * as Monaco from 'monaco-editor';
21
22
  import Sortable, { type Options, type SortableEvent } from 'sortablejs';
22
23
  import type { PascalCasedProperties } from 'type-fest';
23
24
 
@@ -32,8 +33,6 @@ import type {
32
33
  UpdateDragEl,
33
34
  } from '@tmagic/stage';
34
35
 
35
- import Monaco from '@editor/utils/monaco-editor';
36
-
37
36
  import type { CodeBlockService } from './services/codeBlock';
38
37
  import type { ComponentListService } from './services/componentList';
39
38
  import type { DataSourceService } from './services/dataSource';
@@ -121,15 +120,15 @@ export type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig
121
120
  export interface EditorInstallOptions {
122
121
  parseDSL: <T = any>(dsl: string) => T;
123
122
  customCreateMonacoEditor: (
124
- monaco: typeof Monaco,
123
+ monaco: typeof import('monaco-editor'),
125
124
  codeEditorEl: HTMLElement,
126
125
  options: Monaco.editor.IStandaloneEditorConstructionOptions & { editorCustomType?: string },
127
- ) => Monaco.editor.IStandaloneCodeEditor;
126
+ ) => Promise<Monaco.editor.IStandaloneCodeEditor> | Monaco.editor.IStandaloneCodeEditor;
128
127
  customCreateMonacoDiffEditor: (
129
- monaco: typeof Monaco,
128
+ monaco: typeof import('monaco-editor'),
130
129
  codeEditorEl: HTMLElement,
131
130
  options: Monaco.editor.IStandaloneEditorConstructionOptions & { editorCustomType?: string },
132
- ) => Monaco.editor.IStandaloneDiffEditor;
131
+ ) => Promise<Monaco.editor.IStandaloneDiffEditor> | Monaco.editor.IStandaloneDiffEditor;
133
132
  [key: string]: any;
134
133
  }
135
134
 
@@ -1,8 +1,15 @@
1
- import { emmetCSS, emmetHTML } from 'emmet-monaco-es';
2
- import * as monaco from 'monaco-editor';
1
+ let cached: Promise<typeof import('monaco-editor')> | undefined;
3
2
 
4
- // 注册emmet插件
5
- emmetHTML(monaco);
6
- emmetCSS(monaco, ['css', 'scss']);
3
+ export default () => {
4
+ if (!cached) {
5
+ cached = Promise.all([import('emmet-monaco-es'), import('monaco-editor')]).then(([emmet, monaco]) => {
6
+ const { emmetHTML, emmetCSS } = emmet;
7
+ emmetHTML(monaco);
8
+ emmetCSS(monaco, ['css', 'scss']);
7
9
 
8
- export default monaco;
10
+ return monaco;
11
+ });
12
+ }
13
+
14
+ return cached;
15
+ };
@@ -47,6 +47,7 @@ export const numberOptions = [
47
47
 
48
48
  export const styleTabConfig: TabPaneConfig = {
49
49
  title: '样式',
50
+ lazy: true,
50
51
  display: ({ services }: any) => !(services.uiService.get('showStylePanel') ?? true),
51
52
  items: [
52
53
  {
@@ -114,6 +115,7 @@ export const styleTabConfig: TabPaneConfig = {
114
115
 
115
116
  export const eventTabConfig: TabPaneConfig = {
116
117
  title: '事件',
118
+ lazy: true,
117
119
  items: [
118
120
  {
119
121
  name: 'events',
package/types/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { default as designPlugin } from '@tmagic/design';
5
5
  import { TableColumnConfig, FormConfig, ChangeRecord as ChangeRecord$1, TabPaneConfig, CascaderOption, FormState, FieldProps, CodeSelectConfig, ContainerChangeEventData as ContainerChangeEventData$1, CodeSelectColConfig, DataSourceFieldsConfig, DataSourceMocksConfig, DataSourceMethodsConfig, DataSourceInputConfig, DataSourceSelect, DataSourceMethodSelectConfig, DataSourceFieldSelectConfig, EventSelectConfig, KeyValueConfig, FormValue, PageFragmentSelectConfig, DisplayCondsConfig, CondOpSelectConfig, FormInstallOptions } from '@tmagic/form';
6
6
  export * from '@tmagic/form';
7
7
  export { default as formPlugin } from '@tmagic/form';
8
+ import * as Monaco from 'monaco-editor';
8
9
  import EventEmitter$1, { EventEmitter } from 'events';
9
10
  import Sortable, { Options as Options$1, SortableEvent } from 'sortablejs';
10
11
  import { Writable, PascalCasedProperties } from 'type-fest';
@@ -15,7 +16,6 @@ import * as StageCore from '@tmagic/stage';
15
16
  import StageCore__default, { ContainerHighlightType, CustomizeMoveableOptions, UpdateDragEl, RenderType, GuidesOptions } from '@tmagic/stage';
16
17
  export * from '@tmagic/stage';
17
18
  export { default as StageCore } from '@tmagic/stage';
18
- import * as monaco from 'monaco-editor';
19
19
  import * as _tmagic_schema from '@tmagic/schema';
20
20
  import { StyleSchema } from '@tmagic/schema';
21
21
  import * as _vue_reactivity from '@vue/reactivity';
@@ -900,12 +900,12 @@ type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> | MNode;
900
900
  type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
901
901
  interface EditorInstallOptions {
902
902
  parseDSL: <T = any>(dsl: string) => T;
903
- customCreateMonacoEditor: (monaco: typeof monaco, codeEditorEl: HTMLElement, options: monaco.editor.IStandaloneEditorConstructionOptions & {
903
+ customCreateMonacoEditor: (monaco: typeof Monaco, codeEditorEl: HTMLElement, options: Monaco.editor.IStandaloneEditorConstructionOptions & {
904
904
  editorCustomType?: string;
905
- }) => monaco.editor.IStandaloneCodeEditor;
906
- customCreateMonacoDiffEditor: (monaco: typeof monaco, codeEditorEl: HTMLElement, options: monaco.editor.IStandaloneEditorConstructionOptions & {
905
+ }) => Promise<Monaco.editor.IStandaloneCodeEditor> | Monaco.editor.IStandaloneCodeEditor;
906
+ customCreateMonacoDiffEditor: (monaco: typeof Monaco, codeEditorEl: HTMLElement, options: Monaco.editor.IStandaloneEditorConstructionOptions & {
907
907
  editorCustomType?: string;
908
- }) => monaco.editor.IStandaloneDiffEditor;
908
+ }) => Promise<Monaco.editor.IStandaloneDiffEditor> | Monaco.editor.IStandaloneDiffEditor;
909
909
  [key: string]: any;
910
910
  }
911
911
  interface Services {
@@ -2479,7 +2479,7 @@ type __VLS_Props$u = {
2479
2479
  modifiedValues?: any;
2480
2480
  type?: 'diff';
2481
2481
  language?: string;
2482
- options?: monaco.editor.IStandaloneEditorConstructionOptions;
2482
+ options?: Monaco.editor.IStandaloneEditorConstructionOptions;
2483
2483
  height?: string;
2484
2484
  autoSave?: boolean;
2485
2485
  parse?: boolean;
@@ -2492,10 +2492,10 @@ type __VLS_Props$u = {
2492
2492
  };
2493
2493
  declare const __VLS_export$w: _vue_runtime_core.DefineComponent<__VLS_Props$u, {
2494
2494
  values: _vue_reactivity.Ref<string, string>;
2495
- getEditor(): monaco.editor.IStandaloneCodeEditor | monaco.editor.IStandaloneDiffEditor | null;
2496
- getVsEditor(): monaco.editor.IStandaloneCodeEditor | null;
2497
- getVsDiffEditor(): monaco.editor.IStandaloneDiffEditor | null;
2498
- setEditorValue: (v: string | any, m: string | any) => void | undefined;
2495
+ getEditor(): Monaco.editor.IStandaloneCodeEditor | Monaco.editor.IStandaloneDiffEditor | null;
2496
+ getVsEditor(): Monaco.editor.IStandaloneCodeEditor | null;
2497
+ getVsDiffEditor(): Monaco.editor.IStandaloneDiffEditor | null;
2498
+ setEditorValue: (v: string | any, m: string | any) => void;
2499
2499
  getEditorValue: () => string;
2500
2500
  focus(): void;
2501
2501
  }, {}, {}, {}, _vue_runtime_core.ComponentOptionsMixin, _vue_runtime_core.ComponentOptionsMixin, {
@@ -2505,7 +2505,7 @@ declare const __VLS_export$w: _vue_runtime_core.DefineComponent<__VLS_Props$u, {
2505
2505
  onSave?: ((...args: any[]) => any) | undefined;
2506
2506
  onInitd?: ((...args: any[]) => any) | undefined;
2507
2507
  }>, {
2508
- options: monaco.editor.IStandaloneEditorConstructionOptions;
2508
+ options: Monaco.editor.IStandaloneEditorConstructionOptions;
2509
2509
  language: string;
2510
2510
  parse: boolean;
2511
2511
  initValues: any;