@tmagic/editor 1.6.0-beta.2 → 1.6.0-beta.4
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.
- package/dist/tmagic-editor.js +56 -30
- package/dist/tmagic-editor.umd.cjs +55 -29
- package/package.json +7 -7
- package/src/Editor.vue +1 -17
- package/src/initService.ts +28 -4
- package/src/layouts/CodeEditor.vue +31 -17
- package/src/services/BaseService.ts +3 -1
package/dist/tmagic-editor.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
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;
|
|
169
175
|
}
|
|
170
|
-
|
|
176
|
+
const position = vsEditor?.getPosition();
|
|
177
|
+
const result = vsEditor?.setValue(values.value);
|
|
178
|
+
if (position) {
|
|
179
|
+
vsEditor?.setPosition(position);
|
|
180
|
+
vsEditor?.focus();
|
|
181
|
+
}
|
|
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",
|
|
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;
|
|
@@ -1233,7 +1249,9 @@ class BaseService extends EventEmitter {
|
|
|
1233
1249
|
}
|
|
1234
1250
|
usePlugin(options) {
|
|
1235
1251
|
for (const [methodName2, method] of Object.entries(options)) {
|
|
1236
|
-
if (typeof method === "function"
|
|
1252
|
+
if (typeof method === "function" && !this.pluginOptionsList[methodName2].includes(method)) {
|
|
1253
|
+
this.pluginOptionsList[methodName2].push(method);
|
|
1254
|
+
}
|
|
1237
1255
|
}
|
|
1238
1256
|
}
|
|
1239
1257
|
removePlugin(options) {
|
|
@@ -16028,6 +16046,28 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
|
|
|
16028
16046
|
});
|
|
16029
16047
|
}
|
|
16030
16048
|
);
|
|
16049
|
+
watch(
|
|
16050
|
+
() => props.runtimeUrl,
|
|
16051
|
+
(url) => {
|
|
16052
|
+
if (!url) {
|
|
16053
|
+
return;
|
|
16054
|
+
}
|
|
16055
|
+
const stage = editorService.get("stage");
|
|
16056
|
+
if (!stage) {
|
|
16057
|
+
return;
|
|
16058
|
+
}
|
|
16059
|
+
stage.reloadIframe(url);
|
|
16060
|
+
stage.renderer?.once("runtime-ready", (runtime) => {
|
|
16061
|
+
runtime.updateRootConfig?.(cloneDeep(toRaw(editorService.get("root"))));
|
|
16062
|
+
const page = editorService.get("page");
|
|
16063
|
+
const node = editorService.get("node");
|
|
16064
|
+
page?.id && runtime?.updatePageId?.(page.id);
|
|
16065
|
+
setTimeout(() => {
|
|
16066
|
+
node && stage?.select(toRaw(node.id));
|
|
16067
|
+
});
|
|
16068
|
+
});
|
|
16069
|
+
}
|
|
16070
|
+
);
|
|
16031
16071
|
const getStage = () => {
|
|
16032
16072
|
const stage = editorService.get("stage");
|
|
16033
16073
|
if (stage) {
|
|
@@ -16097,7 +16137,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
|
|
|
16097
16137
|
delete value.dataSourceDeps;
|
|
16098
16138
|
delete value.dataSourceCondDeps;
|
|
16099
16139
|
}
|
|
16100
|
-
|
|
16140
|
+
(async () => {
|
|
16101
16141
|
const nodeId = editorService.get("node")?.id || props.defaultSelected;
|
|
16102
16142
|
let node;
|
|
16103
16143
|
if (nodeId) {
|
|
@@ -16115,8 +16155,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
|
|
|
16115
16155
|
if (toRaw(value) !== toRaw(preValue)) {
|
|
16116
16156
|
emit("update:modelValue", value);
|
|
16117
16157
|
}
|
|
16118
|
-
};
|
|
16119
|
-
handler();
|
|
16158
|
+
})();
|
|
16120
16159
|
};
|
|
16121
16160
|
const nodeAddHandler = (nodes) => {
|
|
16122
16161
|
collectIdle(nodes, true).then(() => {
|
|
@@ -16436,19 +16475,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
16436
16475
|
disabledMultiSelect: props.disabledMultiSelect
|
|
16437
16476
|
};
|
|
16438
16477
|
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
16478
|
provide("services", services);
|
|
16453
16479
|
provide("codeOptions", props.codeOptions);
|
|
16454
16480
|
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
|
-
|
|
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
|
-
|
|
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",
|
|
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;
|
|
@@ -6026,7 +6042,9 @@
|
|
|
6026
6042
|
}
|
|
6027
6043
|
usePlugin(options) {
|
|
6028
6044
|
for (const [methodName2, method] of Object.entries(options)) {
|
|
6029
|
-
if (typeof method === "function"
|
|
6045
|
+
if (typeof method === "function" && !this.pluginOptionsList[methodName2].includes(method)) {
|
|
6046
|
+
this.pluginOptionsList[methodName2].push(method);
|
|
6047
|
+
}
|
|
6030
6048
|
}
|
|
6031
6049
|
}
|
|
6032
6050
|
removePlugin(options) {
|
|
@@ -20821,6 +20839,28 @@
|
|
|
20821
20839
|
});
|
|
20822
20840
|
}
|
|
20823
20841
|
);
|
|
20842
|
+
vue.watch(
|
|
20843
|
+
() => props.runtimeUrl,
|
|
20844
|
+
(url) => {
|
|
20845
|
+
if (!url) {
|
|
20846
|
+
return;
|
|
20847
|
+
}
|
|
20848
|
+
const stage = editorService.get("stage");
|
|
20849
|
+
if (!stage) {
|
|
20850
|
+
return;
|
|
20851
|
+
}
|
|
20852
|
+
stage.reloadIframe(url);
|
|
20853
|
+
stage.renderer?.once("runtime-ready", (runtime) => {
|
|
20854
|
+
runtime.updateRootConfig?.(cloneDeep(vue.toRaw(editorService.get("root"))));
|
|
20855
|
+
const page = editorService.get("page");
|
|
20856
|
+
const node = editorService.get("node");
|
|
20857
|
+
page?.id && runtime?.updatePageId?.(page.id);
|
|
20858
|
+
setTimeout(() => {
|
|
20859
|
+
node && stage?.select(vue.toRaw(node.id));
|
|
20860
|
+
});
|
|
20861
|
+
});
|
|
20862
|
+
}
|
|
20863
|
+
);
|
|
20824
20864
|
const getStage = () => {
|
|
20825
20865
|
const stage = editorService.get("stage");
|
|
20826
20866
|
if (stage) {
|
|
@@ -20890,7 +20930,7 @@
|
|
|
20890
20930
|
delete value.dataSourceDeps;
|
|
20891
20931
|
delete value.dataSourceCondDeps;
|
|
20892
20932
|
}
|
|
20893
|
-
|
|
20933
|
+
(async () => {
|
|
20894
20934
|
const nodeId = editorService.get("node")?.id || props.defaultSelected;
|
|
20895
20935
|
let node;
|
|
20896
20936
|
if (nodeId) {
|
|
@@ -20908,8 +20948,7 @@
|
|
|
20908
20948
|
if (vue.toRaw(value) !== vue.toRaw(preValue)) {
|
|
20909
20949
|
emit("update:modelValue", value);
|
|
20910
20950
|
}
|
|
20911
|
-
};
|
|
20912
|
-
handler();
|
|
20951
|
+
})();
|
|
20913
20952
|
};
|
|
20914
20953
|
const nodeAddHandler = (nodes) => {
|
|
20915
20954
|
collectIdle(nodes, true).then(() => {
|
|
@@ -21229,19 +21268,6 @@
|
|
|
21229
21268
|
disabledMultiSelect: props.disabledMultiSelect
|
|
21230
21269
|
};
|
|
21231
21270
|
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
21271
|
vue.provide("services", services);
|
|
21246
21272
|
vue.provide("codeOptions", props.codeOptions);
|
|
21247
21273
|
vue.provide("stageOptions", stageOptions);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.6.0-beta.
|
|
2
|
+
"version": "1.6.0-beta.4",
|
|
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/
|
|
62
|
-
"@tmagic/
|
|
63
|
-
"@tmagic/
|
|
64
|
-
"@tmagic/
|
|
65
|
-
"@tmagic/utils": "1.6.0-beta.
|
|
61
|
+
"@tmagic/design": "1.6.0-beta.4",
|
|
62
|
+
"@tmagic/stage": "1.6.0-beta.4",
|
|
63
|
+
"@tmagic/table": "1.6.0-beta.4",
|
|
64
|
+
"@tmagic/form": "1.6.0-beta.4",
|
|
65
|
+
"@tmagic/utils": "1.6.0-beta.4"
|
|
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.
|
|
79
|
+
"@tmagic/core": "1.6.0-beta.4"
|
|
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
|
|
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);
|
package/src/initService.ts
CHANGED
|
@@ -347,6 +347,32 @@ 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
|
+
const page = editorService.get('page');
|
|
367
|
+
const node = editorService.get('node');
|
|
368
|
+
page?.id && runtime?.updatePageId?.(page.id);
|
|
369
|
+
setTimeout(() => {
|
|
370
|
+
node && stage?.select(toRaw(node.id));
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
);
|
|
375
|
+
|
|
350
376
|
const getStage = (): Promise<StageCore> => {
|
|
351
377
|
const stage = editorService.get('stage');
|
|
352
378
|
if (stage) {
|
|
@@ -434,7 +460,7 @@ export const initServiceEvents = (
|
|
|
434
460
|
delete value.dataSourceCondDeps;
|
|
435
461
|
}
|
|
436
462
|
|
|
437
|
-
|
|
463
|
+
(async () => {
|
|
438
464
|
const nodeId = editorService.get('node')?.id || props.defaultSelected;
|
|
439
465
|
let node;
|
|
440
466
|
if (nodeId) {
|
|
@@ -453,9 +479,7 @@ export const initServiceEvents = (
|
|
|
453
479
|
if (toRaw(value) !== toRaw(preValue)) {
|
|
454
480
|
emit('update:modelValue', value);
|
|
455
481
|
}
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
handler();
|
|
482
|
+
})();
|
|
459
483
|
};
|
|
460
484
|
|
|
461
485
|
// 新增节点,收集依赖
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -206,7 +206,9 @@ export default class extends EventEmitter {
|
|
|
206
206
|
|
|
207
207
|
public usePlugin(options: Record<string, Function>) {
|
|
208
208
|
for (const [methodName, method] of Object.entries(options)) {
|
|
209
|
-
if (typeof method === 'function'
|
|
209
|
+
if (typeof method === 'function' && !this.pluginOptionsList[methodName].includes(method)) {
|
|
210
|
+
this.pluginOptionsList[methodName].push(method);
|
|
211
|
+
}
|
|
210
212
|
}
|
|
211
213
|
}
|
|
212
214
|
|