@tmagic/editor 1.6.0-beta.1 → 1.6.0-beta.3

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.
@@ -7,7 +7,7 @@ export { default as formPlugin } from '@tmagic/form';
7
7
  import tablePlugin__default, { MagicTable } from '@tmagic/table';
8
8
  export * from '@tmagic/table';
9
9
  export { default as tablePlugin } from '@tmagic/table';
10
- import { defineComponent, createBlock, createElementBlock, openBlock, unref, withCtx, createVNode, createElementVNode, normalizeClass, resolveDynamicComponent, toRaw, ref, useTemplateRef, watch, onMounted, onBeforeUnmount, Teleport, normalizeStyle, createCommentVNode, nextTick, computed, reactive, resolveComponent, inject, Fragment, renderList, mergeProps, mergeModels, useModel, provide, renderSlot, toDisplayString, shallowReactive, createTextVNode, isRef, createStaticVNode, watchEffect, markRaw, withDirectives, vModelText, vShow, shallowRef, withModifiers, toHandlers, createSlots, getCurrentInstance, onUnmounted, Transition, resolveDirective, mergeDefaults } from 'vue';
10
+ import { defineComponent, createBlock, createElementBlock, openBlock, unref, withCtx, createVNode, createElementVNode, normalizeClass, resolveDynamicComponent, toRaw, ref, useTemplateRef, watch, onMounted, onBeforeUnmount, onUnmounted, Teleport, normalizeStyle, createCommentVNode, nextTick, computed, reactive, resolveComponent, inject, Fragment, renderList, mergeProps, mergeModels, useModel, provide, renderSlot, toDisplayString, shallowReactive, createTextVNode, isRef, createStaticVNode, watchEffect, markRaw, withDirectives, vModelText, vShow, shallowRef, withModifiers, toHandlers, createSlots, getCurrentInstance, Transition, resolveDirective, mergeDefaults } from 'vue';
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';
@@ -119,7 +119,7 @@ const _sfc_main$1q = /* @__PURE__ */ defineComponent({
119
119
  const props = __props;
120
120
  const emit = __emit;
121
121
  const toString = (v, language) => {
122
- let value = "";
122
+ let value;
123
123
  if (typeof v !== "string") {
124
124
  if (language === "json") {
125
125
  value = JSON.stringify(v, null, 2);
@@ -162,14 +162,35 @@ const _sfc_main$1q = /* @__PURE__ */ defineComponent({
162
162
  if (props.type === "diff") {
163
163
  const originalModel = monaco.editor.createModel(values.value, "text/javascript");
164
164
  const modifiedModel = monaco.editor.createModel(toString(m, props.language), "text/javascript");
165
- return vsDiffEditor?.setModel({
165
+ const position2 = vsDiffEditor?.getPosition();
166
+ const result2 = vsDiffEditor?.setModel({
166
167
  original: originalModel,
167
168
  modified: modifiedModel
168
169
  });
170
+ if (position2) {
171
+ vsDiffEditor?.setPosition(position2);
172
+ vsDiffEditor?.focus();
173
+ }
174
+ return result2;
175
+ }
176
+ const position = vsEditor?.getPosition();
177
+ const result = vsEditor?.setValue(values.value);
178
+ if (position) {
179
+ vsEditor?.setPosition(position);
180
+ vsEditor?.focus();
169
181
  }
170
- return vsEditor?.setValue(values.value);
182
+ return result;
171
183
  };
172
184
  const getEditorValue = () => (props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || "";
185
+ const handleKeyDown = (e) => {
186
+ if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
187
+ e.preventDefault();
188
+ e.stopPropagation();
189
+ const newValue = getEditorValue();
190
+ values.value = newValue;
191
+ emit("save", props.parse ? parseCode(newValue, props.language) : newValue);
192
+ }
193
+ };
173
194
  const init = async () => {
174
195
  if (!codeEditorEl.value) return;
175
196
  if (codeEditorEl.value.clientHeight === 0) {
@@ -188,15 +209,7 @@ const _sfc_main$1q = /* @__PURE__ */ defineComponent({
188
209
  }
189
210
  setEditorValue(props.initValues, props.modifiedValues);
190
211
  emit("initd", vsEditor);
191
- codeEditorEl.value.addEventListener("keydown", (e) => {
192
- if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
193
- e.preventDefault();
194
- e.stopPropagation();
195
- const newValue = getEditorValue();
196
- values.value = newValue;
197
- emit("save", props.parse ? parseCode(newValue, props.language) : newValue);
198
- }
199
- });
212
+ codeEditorEl.value.addEventListener("keydown", handleKeyDown);
200
213
  if (props.type !== "diff" && props.autoSave) {
201
214
  vsEditor?.onDidBlurEditorWidget(() => {
202
215
  const newValue = getEditorValue();
@@ -242,6 +255,9 @@ const _sfc_main$1q = /* @__PURE__ */ defineComponent({
242
255
  vsEditor = null;
243
256
  vsDiffEditor = null;
244
257
  });
258
+ onUnmounted(() => {
259
+ codeEditorEl.value?.removeEventListener("keydown", handleKeyDown);
260
+ });
245
261
  const fullScreen = ref(false);
246
262
  const fullScreenHandler = () => {
247
263
  fullScreen.value = !fullScreen.value;
@@ -16028,6 +16044,22 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
16028
16044
  });
16029
16045
  }
16030
16046
  );
16047
+ watch(
16048
+ () => props.runtimeUrl,
16049
+ (url) => {
16050
+ if (!url) {
16051
+ return;
16052
+ }
16053
+ const stage = editorService.get("stage");
16054
+ if (!stage) {
16055
+ return;
16056
+ }
16057
+ stage.reloadIframe(url);
16058
+ stage.renderer?.once("runtime-ready", (runtime) => {
16059
+ runtime.updateRootConfig?.(cloneDeep(toRaw(editorService.get("root"))));
16060
+ });
16061
+ }
16062
+ );
16031
16063
  const getStage = () => {
16032
16064
  const stage = editorService.get("stage");
16033
16065
  if (stage) {
@@ -16097,7 +16129,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
16097
16129
  delete value.dataSourceDeps;
16098
16130
  delete value.dataSourceCondDeps;
16099
16131
  }
16100
- const handler = async () => {
16132
+ (async () => {
16101
16133
  const nodeId = editorService.get("node")?.id || props.defaultSelected;
16102
16134
  let node;
16103
16135
  if (nodeId) {
@@ -16115,8 +16147,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
16115
16147
  if (toRaw(value) !== toRaw(preValue)) {
16116
16148
  emit("update:modelValue", value);
16117
16149
  }
16118
- };
16119
- handler();
16150
+ })();
16120
16151
  };
16121
16152
  const nodeAddHandler = (nodes) => {
16122
16153
  collectIdle(nodes, true).then(() => {
@@ -16436,19 +16467,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
16436
16467
  disabledMultiSelect: props.disabledMultiSelect
16437
16468
  };
16438
16469
  stageOverlayService.set("stageOptions", stageOptions);
16439
- watch(
16440
- () => props.runtimeUrl,
16441
- (url) => {
16442
- if (!url) {
16443
- return;
16444
- }
16445
- const stage = editorService.get("stage");
16446
- if (!stage) {
16447
- return;
16448
- }
16449
- stage.reloadIframe(url);
16450
- }
16451
- );
16452
16470
  provide("services", services);
16453
16471
  provide("codeOptions", props.codeOptions);
16454
16472
  provide("stageOptions", stageOptions);
@@ -4912,7 +4912,7 @@
4912
4912
  const props = __props;
4913
4913
  const emit = __emit;
4914
4914
  const toString = (v, language) => {
4915
- let value = "";
4915
+ let value;
4916
4916
  if (typeof v !== "string") {
4917
4917
  if (language === "json") {
4918
4918
  value = JSON.stringify(v, null, 2);
@@ -4955,14 +4955,35 @@
4955
4955
  if (props.type === "diff") {
4956
4956
  const originalModel = monaco__namespace.editor.createModel(values.value, "text/javascript");
4957
4957
  const modifiedModel = monaco__namespace.editor.createModel(toString(m, props.language), "text/javascript");
4958
- return vsDiffEditor?.setModel({
4958
+ const position2 = vsDiffEditor?.getPosition();
4959
+ const result2 = vsDiffEditor?.setModel({
4959
4960
  original: originalModel,
4960
4961
  modified: modifiedModel
4961
4962
  });
4963
+ if (position2) {
4964
+ vsDiffEditor?.setPosition(position2);
4965
+ vsDiffEditor?.focus();
4966
+ }
4967
+ return result2;
4962
4968
  }
4963
- return vsEditor?.setValue(values.value);
4969
+ const position = vsEditor?.getPosition();
4970
+ const result = vsEditor?.setValue(values.value);
4971
+ if (position) {
4972
+ vsEditor?.setPosition(position);
4973
+ vsEditor?.focus();
4974
+ }
4975
+ return result;
4964
4976
  };
4965
4977
  const getEditorValue = () => (props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || "";
4978
+ const handleKeyDown = (e) => {
4979
+ if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
4980
+ e.preventDefault();
4981
+ e.stopPropagation();
4982
+ const newValue = getEditorValue();
4983
+ values.value = newValue;
4984
+ emit("save", props.parse ? parseCode(newValue, props.language) : newValue);
4985
+ }
4986
+ };
4966
4987
  const init = async () => {
4967
4988
  if (!codeEditorEl.value) return;
4968
4989
  if (codeEditorEl.value.clientHeight === 0) {
@@ -4981,15 +5002,7 @@
4981
5002
  }
4982
5003
  setEditorValue(props.initValues, props.modifiedValues);
4983
5004
  emit("initd", vsEditor);
4984
- codeEditorEl.value.addEventListener("keydown", (e) => {
4985
- if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
4986
- e.preventDefault();
4987
- e.stopPropagation();
4988
- const newValue = getEditorValue();
4989
- values.value = newValue;
4990
- emit("save", props.parse ? parseCode(newValue, props.language) : newValue);
4991
- }
4992
- });
5005
+ codeEditorEl.value.addEventListener("keydown", handleKeyDown);
4993
5006
  if (props.type !== "diff" && props.autoSave) {
4994
5007
  vsEditor?.onDidBlurEditorWidget(() => {
4995
5008
  const newValue = getEditorValue();
@@ -5035,6 +5048,9 @@
5035
5048
  vsEditor = null;
5036
5049
  vsDiffEditor = null;
5037
5050
  });
5051
+ vue.onUnmounted(() => {
5052
+ codeEditorEl.value?.removeEventListener("keydown", handleKeyDown);
5053
+ });
5038
5054
  const fullScreen = vue.ref(false);
5039
5055
  const fullScreenHandler = () => {
5040
5056
  fullScreen.value = !fullScreen.value;
@@ -20821,6 +20837,22 @@
20821
20837
  });
20822
20838
  }
20823
20839
  );
20840
+ vue.watch(
20841
+ () => props.runtimeUrl,
20842
+ (url) => {
20843
+ if (!url) {
20844
+ return;
20845
+ }
20846
+ const stage = editorService.get("stage");
20847
+ if (!stage) {
20848
+ return;
20849
+ }
20850
+ stage.reloadIframe(url);
20851
+ stage.renderer?.once("runtime-ready", (runtime) => {
20852
+ runtime.updateRootConfig?.(cloneDeep(vue.toRaw(editorService.get("root"))));
20853
+ });
20854
+ }
20855
+ );
20824
20856
  const getStage = () => {
20825
20857
  const stage = editorService.get("stage");
20826
20858
  if (stage) {
@@ -20890,7 +20922,7 @@
20890
20922
  delete value.dataSourceDeps;
20891
20923
  delete value.dataSourceCondDeps;
20892
20924
  }
20893
- const handler = async () => {
20925
+ (async () => {
20894
20926
  const nodeId = editorService.get("node")?.id || props.defaultSelected;
20895
20927
  let node;
20896
20928
  if (nodeId) {
@@ -20908,8 +20940,7 @@
20908
20940
  if (vue.toRaw(value) !== vue.toRaw(preValue)) {
20909
20941
  emit("update:modelValue", value);
20910
20942
  }
20911
- };
20912
- handler();
20943
+ })();
20913
20944
  };
20914
20945
  const nodeAddHandler = (nodes) => {
20915
20946
  collectIdle(nodes, true).then(() => {
@@ -21229,19 +21260,6 @@
21229
21260
  disabledMultiSelect: props.disabledMultiSelect
21230
21261
  };
21231
21262
  stageOverlayService.set("stageOptions", stageOptions);
21232
- vue.watch(
21233
- () => props.runtimeUrl,
21234
- (url) => {
21235
- if (!url) {
21236
- return;
21237
- }
21238
- const stage = editorService.get("stage");
21239
- if (!stage) {
21240
- return;
21241
- }
21242
- stage.reloadIframe(url);
21243
- }
21244
- );
21245
21263
  vue.provide("services", services);
21246
21264
  vue.provide("codeOptions", props.codeOptions);
21247
21265
  vue.provide("stageOptions", stageOptions);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.0-beta.1",
2
+ "version": "1.6.0-beta.3",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -58,11 +58,11 @@
58
58
  "moveable": "^0.53.0",
59
59
  "serialize-javascript": "^6.0.2",
60
60
  "sortablejs": "^1.15.6",
61
- "@tmagic/design": "1.6.0-beta.1",
62
- "@tmagic/form": "1.6.0-beta.1",
63
- "@tmagic/table": "1.6.0-beta.1",
64
- "@tmagic/utils": "1.6.0-beta.1",
65
- "@tmagic/stage": "1.6.0-beta.1"
61
+ "@tmagic/design": "1.6.0-beta.3",
62
+ "@tmagic/form": "1.6.0-beta.3",
63
+ "@tmagic/stage": "1.6.0-beta.3",
64
+ "@tmagic/table": "1.6.0-beta.3",
65
+ "@tmagic/utils": "1.6.0-beta.3"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/events": "^3.0.3",
@@ -76,7 +76,7 @@
76
76
  "monaco-editor": "^0.48.0",
77
77
  "typescript": "^5.8.3",
78
78
  "vue": "^3.5.17",
79
- "@tmagic/core": "1.6.0-beta.1"
79
+ "@tmagic/core": "1.6.0-beta.3"
80
80
  },
81
81
  "peerDependenciesMeta": {
82
82
  "typescript": {
package/src/Editor.vue CHANGED
@@ -129,7 +129,7 @@
129
129
  <script lang="ts" setup>
130
130
  import { EventEmitter } from 'events';
131
131
 
132
- import { provide, watch } from 'vue';
132
+ import { provide } from 'vue';
133
133
 
134
134
  import type { MApp } from '@tmagic/core';
135
135
 
@@ -211,22 +211,6 @@ const stageOptions: StageOptions = {
211
211
 
212
212
  stageOverlayService.set('stageOptions', stageOptions);
213
213
 
214
- watch(
215
- () => props.runtimeUrl,
216
- (url) => {
217
- if (!url) {
218
- return;
219
- }
220
-
221
- const stage = editorService.get('stage');
222
- if (!stage) {
223
- return;
224
- }
225
-
226
- stage.reloadIframe(url);
227
- },
228
- );
229
-
230
214
  provide('services', services);
231
215
 
232
216
  provide('codeOptions', props.codeOptions);
@@ -347,6 +347,26 @@ export const initServiceEvents = (
347
347
  },
348
348
  );
349
349
 
350
+ watch(
351
+ () => props.runtimeUrl,
352
+ (url) => {
353
+ if (!url) {
354
+ return;
355
+ }
356
+
357
+ const stage = editorService.get('stage');
358
+ if (!stage) {
359
+ return;
360
+ }
361
+
362
+ stage.reloadIframe(url);
363
+
364
+ stage.renderer?.once('runtime-ready', (runtime) => {
365
+ runtime.updateRootConfig?.(cloneDeep(toRaw(editorService.get('root')))!);
366
+ });
367
+ },
368
+ );
369
+
350
370
  const getStage = (): Promise<StageCore> => {
351
371
  const stage = editorService.get('stage');
352
372
  if (stage) {
@@ -434,7 +454,7 @@ export const initServiceEvents = (
434
454
  delete value.dataSourceCondDeps;
435
455
  }
436
456
 
437
- const handler = async () => {
457
+ (async () => {
438
458
  const nodeId = editorService.get('node')?.id || props.defaultSelected;
439
459
  let node;
440
460
  if (nodeId) {
@@ -453,9 +473,7 @@ export const initServiceEvents = (
453
473
  if (toRaw(value) !== toRaw(preValue)) {
454
474
  emit('update:modelValue', value);
455
475
  }
456
- };
457
-
458
- handler();
476
+ })();
459
477
  };
460
478
 
461
479
  // 新增节点,收集依赖
@@ -20,7 +20,7 @@
20
20
  </template>
21
21
 
22
22
  <script lang="ts" setup>
23
- import { nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue';
23
+ import { nextTick, onBeforeUnmount, onMounted, onUnmounted, ref, useTemplateRef, watch } from 'vue';
24
24
  import { FullScreen } from '@element-plus/icons-vue';
25
25
  import { throttle } from 'lodash-es';
26
26
  import serialize from 'serialize-javascript';
@@ -62,7 +62,7 @@ const props = withDefaults(
62
62
  const emit = defineEmits(['initd', 'save']);
63
63
 
64
64
  const toString = (v: string | any, language: string): string => {
65
- let value = '';
65
+ let value: string;
66
66
  if (typeof v !== 'string') {
67
67
  if (language === 'json') {
68
68
  value = JSON.stringify(v, null, 2);
@@ -113,19 +113,40 @@ const setEditorValue = (v: string | any, m: string | any) => {
113
113
  if (props.type === 'diff') {
114
114
  const originalModel = monaco.editor.createModel(values.value, 'text/javascript');
115
115
  const modifiedModel = monaco.editor.createModel(toString(m, props.language), 'text/javascript');
116
-
117
- return vsDiffEditor?.setModel({
116
+ const position = vsDiffEditor?.getPosition();
117
+ const result = vsDiffEditor?.setModel({
118
118
  original: originalModel,
119
119
  modified: modifiedModel,
120
120
  });
121
+ if (position) {
122
+ vsDiffEditor?.setPosition(position);
123
+ vsDiffEditor?.focus();
124
+ }
125
+ return result;
121
126
  }
122
-
123
- return vsEditor?.setValue(values.value);
127
+ // 保存当前光标位置
128
+ const position = vsEditor?.getPosition();
129
+ const result = vsEditor?.setValue(values.value);
130
+ // 恢复光标位置
131
+ if (position) {
132
+ vsEditor?.setPosition(position);
133
+ vsEditor?.focus();
134
+ }
135
+ return result;
124
136
  };
125
137
 
126
138
  const getEditorValue = () =>
127
139
  (props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || '';
128
140
 
141
+ const handleKeyDown = (e: KeyboardEvent) => {
142
+ if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
143
+ e.preventDefault();
144
+ e.stopPropagation();
145
+ const newValue = getEditorValue();
146
+ values.value = newValue;
147
+ emit('save', props.parse ? parseCode(newValue, props.language) : newValue);
148
+ }
149
+ };
129
150
  const init = async () => {
130
151
  if (!codeEditorEl.value) return;
131
152
 
@@ -149,16 +170,7 @@ const init = async () => {
149
170
  setEditorValue(props.initValues, props.modifiedValues);
150
171
 
151
172
  emit('initd', vsEditor);
152
-
153
- codeEditorEl.value.addEventListener('keydown', (e) => {
154
- if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
155
- e.preventDefault();
156
- e.stopPropagation();
157
- const newValue = getEditorValue();
158
- values.value = newValue;
159
- emit('save', props.parse ? parseCode(newValue, props.language) : newValue);
160
- }
161
- });
173
+ codeEditorEl.value.addEventListener('keydown', handleKeyDown);
162
174
 
163
175
  if (props.type !== 'diff' && props.autoSave) {
164
176
  vsEditor?.onDidBlurEditorWidget(() => {
@@ -214,7 +226,9 @@ onBeforeUnmount(() => {
214
226
  vsEditor = null;
215
227
  vsDiffEditor = null;
216
228
  });
217
-
229
+ onUnmounted(() => {
230
+ codeEditorEl.value?.removeEventListener('keydown', handleKeyDown);
231
+ });
218
232
  const fullScreen = ref(false);
219
233
  const fullScreenHandler = () => {
220
234
  fullScreen.value = !fullScreen.value;