@tmagic/editor 1.0.5 → 1.1.0-beta.0
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.es.js +187 -57
- package/dist/tmagic-editor.es.js.map +1 -1
- package/dist/tmagic-editor.umd.js +192 -61
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/dist/types/src/Editor.vue.d.ts +28 -1
- package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +2 -0
- package/dist/types/src/services/editor.d.ts +6 -0
- package/dist/types/src/type.d.ts +3 -0
- package/dist/types/src/utils/editor.d.ts +8 -4
- package/package.json +7 -7
- package/src/Editor.vue +19 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +53 -1
- package/src/layouts/workspace/Stage.vue +52 -11
- package/src/services/editor.ts +74 -17
- package/src/type.ts +3 -0
- package/src/utils/editor.ts +45 -35
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('@element-plus/icons'), require('lodash-es'), require('monaco-editor'), require('@tmagic/schema'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('gesto'), require('element-plus'), require('keycon')
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', '@element-plus/icons', 'lodash-es', 'monaco-editor', '@tmagic/schema', '@tmagic/utils', 'events', '@tmagic/core', 'gesto', 'element-plus', 'keycon'
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.Vue, global.serialize, global.icons, global.lodashEs, global.monaco, global.schema, global.utils, global.events, global.core, global.Gesto, global.ElementPlus, global.KeyController
|
|
5
|
-
})(this, (function (exports, vue, serialize, icons, lodashEs, monaco, schema, utils, events, core, Gesto, elementPlus, KeyController
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('@element-plus/icons'), require('lodash-es'), require('monaco-editor'), require('@tmagic/stage'), require('@tmagic/schema'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('gesto'), require('element-plus'), require('keycon')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', '@element-plus/icons', 'lodash-es', 'monaco-editor', '@tmagic/stage', '@tmagic/schema', '@tmagic/utils', 'events', '@tmagic/core', 'gesto', 'element-plus', 'keycon'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.Vue, global.serialize, global.icons, global.lodashEs, global.monaco, global.StageCore, global.schema, global.utils, global.events, global.core, global.Gesto, global.ElementPlus, global.KeyController));
|
|
5
|
+
})(this, (function (exports, vue, serialize, icons, lodashEs, monaco, StageCore, schema, utils, events, core, Gesto, elementPlus, KeyController) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
|
|
27
27
|
var serialize__default = /*#__PURE__*/_interopDefaultLegacy(serialize);
|
|
28
28
|
var monaco__namespace = /*#__PURE__*/_interopNamespace(monaco);
|
|
29
|
+
var StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
|
|
29
30
|
var Gesto__default = /*#__PURE__*/_interopDefaultLegacy(Gesto);
|
|
30
31
|
var KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
|
|
31
|
-
var StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
|
|
32
32
|
|
|
33
33
|
if (typeof global === "undefined") {
|
|
34
34
|
window.global = window;
|
|
@@ -768,56 +768,50 @@
|
|
|
768
768
|
const items = parent?.items || [];
|
|
769
769
|
return items.findIndex((item) => `${item.id}` === `${node.id}`);
|
|
770
770
|
};
|
|
771
|
-
const
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
return node;
|
|
779
|
-
};
|
|
780
|
-
const setTop2Middle = (node, parentNode, stage) => {
|
|
781
|
-
const style = node.style || {};
|
|
771
|
+
const getRelativeStyle = (style = {}) => ({
|
|
772
|
+
...style,
|
|
773
|
+
position: "relative",
|
|
774
|
+
top: 0,
|
|
775
|
+
left: 0
|
|
776
|
+
});
|
|
777
|
+
const getMiddleTop = (style = {}, parentNode, stage) => {
|
|
782
778
|
let height = style.height || 0;
|
|
783
779
|
if (!stage || typeof style.top !== "undefined" || !parentNode.style)
|
|
784
|
-
return style;
|
|
780
|
+
return style.top;
|
|
785
781
|
if (!utils.isNumber(height)) {
|
|
786
782
|
height = 0;
|
|
787
783
|
}
|
|
788
784
|
const { height: parentHeight } = parentNode.style;
|
|
789
785
|
if (utils.isPage(parentNode)) {
|
|
790
786
|
const { scrollTop = 0, wrapperHeight } = stage.mask;
|
|
791
|
-
|
|
792
|
-
} else {
|
|
793
|
-
style.top = (parentHeight - height) / 2;
|
|
787
|
+
return (wrapperHeight - height) / 2 + scrollTop;
|
|
794
788
|
}
|
|
795
|
-
return
|
|
789
|
+
return (parentHeight - height) / 2;
|
|
796
790
|
};
|
|
797
|
-
const
|
|
791
|
+
const getInitPositionStyle = (style = {}, layout, parentNode, stage) => {
|
|
798
792
|
if (layout === Layout.ABSOLUTE) {
|
|
799
|
-
|
|
793
|
+
return {
|
|
794
|
+
...style,
|
|
800
795
|
position: "absolute",
|
|
801
|
-
|
|
796
|
+
top: getMiddleTop(style, parentNode, stage)
|
|
802
797
|
};
|
|
803
|
-
return node;
|
|
804
798
|
}
|
|
805
799
|
if (layout === Layout.RELATIVE) {
|
|
806
|
-
return
|
|
800
|
+
return getRelativeStyle(style);
|
|
807
801
|
}
|
|
808
|
-
return
|
|
802
|
+
return style;
|
|
809
803
|
};
|
|
810
804
|
const setLayout = (node, layout) => {
|
|
811
805
|
node.items?.forEach((child) => {
|
|
812
806
|
if (utils.isPop(child))
|
|
813
807
|
return;
|
|
814
|
-
|
|
815
|
-
if (
|
|
808
|
+
const style = child.style || {};
|
|
809
|
+
if (style.position === "fixed")
|
|
816
810
|
return;
|
|
817
811
|
if (layout !== Layout.RELATIVE) {
|
|
818
|
-
|
|
812
|
+
style.position = "absolute";
|
|
819
813
|
} else {
|
|
820
|
-
|
|
814
|
+
child.style = getRelativeStyle(style);
|
|
821
815
|
child.style.right = "auto";
|
|
822
816
|
child.style.bottom = "auto";
|
|
823
817
|
}
|
|
@@ -834,11 +828,10 @@
|
|
|
834
828
|
offset.left = offset.left + globalThis.parseFloat(value.style?.left || 0);
|
|
835
829
|
offset.top = offset.top + globalThis.parseFloat(value.style?.top || 0);
|
|
836
830
|
});
|
|
837
|
-
|
|
831
|
+
return {
|
|
838
832
|
...node.style || {},
|
|
839
833
|
...offset
|
|
840
834
|
};
|
|
841
|
-
return node;
|
|
842
835
|
};
|
|
843
836
|
const Fixed2Other = async (node, root, getLayout) => {
|
|
844
837
|
const path = utils.getNodePath(node.id, root.items);
|
|
@@ -853,20 +846,20 @@
|
|
|
853
846
|
offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
|
|
854
847
|
offset.top = offset.top - globalThis.parseFloat(value.style?.top || 0);
|
|
855
848
|
});
|
|
849
|
+
const style = node.style || {};
|
|
856
850
|
const parent = path.pop();
|
|
857
851
|
if (!parent) {
|
|
858
|
-
return
|
|
852
|
+
return getRelativeStyle(style);
|
|
859
853
|
}
|
|
860
854
|
const layout = await getLayout(parent);
|
|
861
855
|
if (layout !== Layout.RELATIVE) {
|
|
862
|
-
|
|
863
|
-
...
|
|
856
|
+
return {
|
|
857
|
+
...style,
|
|
864
858
|
...offset,
|
|
865
859
|
position: "absolute"
|
|
866
860
|
};
|
|
867
|
-
return node;
|
|
868
861
|
}
|
|
869
|
-
return
|
|
862
|
+
return getRelativeStyle(style);
|
|
870
863
|
};
|
|
871
864
|
const getGuideLineFromCache = (key) => {
|
|
872
865
|
if (!key)
|
|
@@ -881,6 +874,16 @@
|
|
|
881
874
|
}
|
|
882
875
|
return [];
|
|
883
876
|
};
|
|
877
|
+
const fixNodeLeft = (config, parent, doc) => {
|
|
878
|
+
if (!doc || !config.style || !utils.isNumber(config.style.left))
|
|
879
|
+
return config.style?.left;
|
|
880
|
+
const el = doc.getElementById(`${config.id}`);
|
|
881
|
+
const parentEl = doc.getElementById(`${parent.id}`);
|
|
882
|
+
if (el && parentEl && el.offsetWidth + config.style?.left > parentEl.offsetWidth) {
|
|
883
|
+
return parentEl.offsetWidth - el.offsetWidth;
|
|
884
|
+
}
|
|
885
|
+
return config.style.left;
|
|
886
|
+
};
|
|
884
887
|
|
|
885
888
|
const log = (...args) => {
|
|
886
889
|
};
|
|
@@ -906,6 +909,7 @@
|
|
|
906
909
|
"paste",
|
|
907
910
|
"alignCenter",
|
|
908
911
|
"moveLayer",
|
|
912
|
+
"moveToContainer",
|
|
909
913
|
"move",
|
|
910
914
|
"undo",
|
|
911
915
|
"redo",
|
|
@@ -1045,13 +1049,22 @@
|
|
|
1045
1049
|
if (!parentNode)
|
|
1046
1050
|
throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
|
|
1047
1051
|
const layout = await this.getLayout(vue.toRaw(parentNode), addNode);
|
|
1048
|
-
const newNode =
|
|
1052
|
+
const newNode = { ...vue.toRaw(await propsService.getPropsValue(type, config2)) };
|
|
1053
|
+
newNode.style = getInitPositionStyle(newNode.style, layout, parentNode, this.get("stage"));
|
|
1049
1054
|
if ((parentNode?.type === schema.NodeType.ROOT || curNode.type === schema.NodeType.ROOT) && newNode.type !== schema.NodeType.PAGE) {
|
|
1050
1055
|
throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
|
|
1051
1056
|
}
|
|
1052
1057
|
parentNode?.items?.push(newNode);
|
|
1053
1058
|
const stage = this.get("stage");
|
|
1054
|
-
|
|
1059
|
+
const root = this.get("root");
|
|
1060
|
+
await stage?.add({ config: lodashEs.cloneDeep(newNode), root: lodashEs.cloneDeep(root) });
|
|
1061
|
+
if (layout === Layout.ABSOLUTE) {
|
|
1062
|
+
const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
|
|
1063
|
+
if (typeof fixedLeft !== "undefined") {
|
|
1064
|
+
newNode.style.left = fixedLeft;
|
|
1065
|
+
await stage?.update({ config: lodashEs.cloneDeep(newNode), root: lodashEs.cloneDeep(root) });
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1055
1068
|
await this.select(newNode);
|
|
1056
1069
|
this.addModifiedNodeId(newNode.id);
|
|
1057
1070
|
if (!isPage2) {
|
|
@@ -1078,7 +1091,7 @@
|
|
|
1078
1091
|
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1079
1092
|
parent.items?.splice(index, 1);
|
|
1080
1093
|
const stage = this.get("stage");
|
|
1081
|
-
stage?.remove({ id: node.id, root: this.get("root") });
|
|
1094
|
+
stage?.remove({ id: node.id, root: lodashEs.cloneDeep(this.get("root")) });
|
|
1082
1095
|
if (node.type === schema.NodeType.PAGE) {
|
|
1083
1096
|
this.state.pageLength -= 1;
|
|
1084
1097
|
if (root.items[0]) {
|
|
@@ -1139,7 +1152,7 @@
|
|
|
1139
1152
|
if (`${newConfig.id}` === `${this.get("node").id}`) {
|
|
1140
1153
|
this.set("node", newConfig);
|
|
1141
1154
|
}
|
|
1142
|
-
this.get("stage")?.update({ config: lodashEs.cloneDeep(newConfig), root: this.get("root") });
|
|
1155
|
+
this.get("stage")?.update({ config: lodashEs.cloneDeep(newConfig), root: lodashEs.cloneDeep(this.get("root")) });
|
|
1143
1156
|
if (newConfig.type === schema.NodeType.PAGE) {
|
|
1144
1157
|
this.set("page", newConfig);
|
|
1145
1158
|
}
|
|
@@ -1158,7 +1171,7 @@
|
|
|
1158
1171
|
parent.items.splice(index2, 0, ...parent.items.splice(index1, 1));
|
|
1159
1172
|
await this.update(parent);
|
|
1160
1173
|
await this.select(node);
|
|
1161
|
-
this.get("stage")?.update({ config: lodashEs.cloneDeep(node), root: this.get("root") });
|
|
1174
|
+
this.get("stage")?.update({ config: lodashEs.cloneDeep(node), root: lodashEs.cloneDeep(this.get("root")) });
|
|
1162
1175
|
this.addModifiedNodeId(parent.id);
|
|
1163
1176
|
this.pushHistoryState();
|
|
1164
1177
|
}
|
|
@@ -1210,7 +1223,10 @@
|
|
|
1210
1223
|
node.style.left = (parent.style.width - node.style.width) / 2;
|
|
1211
1224
|
}
|
|
1212
1225
|
await this.update(node);
|
|
1213
|
-
this.get("stage")?.update({
|
|
1226
|
+
this.get("stage")?.update({
|
|
1227
|
+
config: lodashEs.cloneDeep(vue.toRaw(node)),
|
|
1228
|
+
root: lodashEs.cloneDeep(this.get("root"))
|
|
1229
|
+
});
|
|
1214
1230
|
this.addModifiedNodeId(config2.id);
|
|
1215
1231
|
this.pushHistoryState();
|
|
1216
1232
|
return config2;
|
|
@@ -1227,7 +1243,37 @@
|
|
|
1227
1243
|
} else {
|
|
1228
1244
|
brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
|
|
1229
1245
|
}
|
|
1230
|
-
this.get("stage")?.update({
|
|
1246
|
+
this.get("stage")?.update({
|
|
1247
|
+
config: lodashEs.cloneDeep(vue.toRaw(parent)),
|
|
1248
|
+
root: lodashEs.cloneDeep(this.get("root"))
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
async moveToContainer(config2, targetId) {
|
|
1252
|
+
const { node, parent } = this.getNodeInfo(config2.id, false);
|
|
1253
|
+
const target = this.getNodeById(targetId, false);
|
|
1254
|
+
const stage = this.get("stage");
|
|
1255
|
+
if (node && parent && stage) {
|
|
1256
|
+
const root = lodashEs.cloneDeep(this.get("root"));
|
|
1257
|
+
const index = getNodeIndex(node, parent);
|
|
1258
|
+
parent.items?.splice(index, 1);
|
|
1259
|
+
await stage.remove({ id: node.id, root });
|
|
1260
|
+
const layout = await this.getLayout(target);
|
|
1261
|
+
const newConfig = lodashEs.mergeWith(lodashEs.cloneDeep(node), config2, (objValue, srcValue) => {
|
|
1262
|
+
if (Array.isArray(srcValue)) {
|
|
1263
|
+
return srcValue;
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
newConfig.style = getInitPositionStyle(newConfig.style, layout, target, stage);
|
|
1267
|
+
target.items.push(newConfig);
|
|
1268
|
+
await stage.select(targetId);
|
|
1269
|
+
await stage.update({ config: lodashEs.cloneDeep(target), root });
|
|
1270
|
+
await this.select(newConfig);
|
|
1271
|
+
stage.select(newConfig.id);
|
|
1272
|
+
this.addModifiedNodeId(target.id);
|
|
1273
|
+
this.addModifiedNodeId(parent.id);
|
|
1274
|
+
this.pushHistoryState();
|
|
1275
|
+
return newConfig;
|
|
1276
|
+
}
|
|
1231
1277
|
}
|
|
1232
1278
|
async undo() {
|
|
1233
1279
|
const value = historyService.undo();
|
|
@@ -1299,12 +1345,12 @@
|
|
|
1299
1345
|
}, 0);
|
|
1300
1346
|
}
|
|
1301
1347
|
async toggleFixedPosition(dist, src, root) {
|
|
1302
|
-
|
|
1348
|
+
const newConfig = lodashEs.cloneDeep(dist);
|
|
1303
1349
|
if (!utils.isPop(src) && newConfig.style?.position) {
|
|
1304
1350
|
if (isFixed(newConfig) && !isFixed(src)) {
|
|
1305
|
-
newConfig = change2Fixed(newConfig, root);
|
|
1351
|
+
newConfig.style = change2Fixed(newConfig, root);
|
|
1306
1352
|
} else if (!isFixed(newConfig) && isFixed(src)) {
|
|
1307
|
-
newConfig = await Fixed2Other(newConfig, root, this.getLayout);
|
|
1353
|
+
newConfig.style = await Fixed2Other(newConfig, root, this.getLayout);
|
|
1308
1354
|
}
|
|
1309
1355
|
}
|
|
1310
1356
|
return newConfig;
|
|
@@ -2208,11 +2254,16 @@
|
|
|
2208
2254
|
setup() {
|
|
2209
2255
|
const searchText = vue.ref("");
|
|
2210
2256
|
const services = vue.inject("services");
|
|
2257
|
+
const stageOptions = vue.inject("stageOptions");
|
|
2258
|
+
const stage = vue.computed(() => services?.editorService.get("stage"));
|
|
2211
2259
|
const list = vue.computed(() => services?.componentListService.getList().map((group) => ({
|
|
2212
2260
|
...group,
|
|
2213
2261
|
items: group.items.filter((item) => item.text.includes(searchText.value))
|
|
2214
2262
|
})));
|
|
2215
2263
|
const collapseValue = vue.computed(() => Array(list.value?.length).fill(1).map((x, i) => i));
|
|
2264
|
+
let timeout;
|
|
2265
|
+
let clientX;
|
|
2266
|
+
let clientY;
|
|
2216
2267
|
return {
|
|
2217
2268
|
searchText,
|
|
2218
2269
|
collapseValue,
|
|
@@ -2233,6 +2284,43 @@
|
|
|
2233
2284
|
...data
|
|
2234
2285
|
}).replace(/"(\w+)":\s/g, "$1: "));
|
|
2235
2286
|
}
|
|
2287
|
+
},
|
|
2288
|
+
dragendHandler() {
|
|
2289
|
+
if (timeout) {
|
|
2290
|
+
globalThis.clearTimeout(timeout);
|
|
2291
|
+
timeout = void 0;
|
|
2292
|
+
}
|
|
2293
|
+
const doc = stage.value?.renderer.contentWindow?.document;
|
|
2294
|
+
if (doc && stageOptions) {
|
|
2295
|
+
utils.removeClassNameByClassName(doc, stageOptions.containerHighlightClassName);
|
|
2296
|
+
}
|
|
2297
|
+
clientX = 0;
|
|
2298
|
+
clientY = 0;
|
|
2299
|
+
},
|
|
2300
|
+
dragHandler(e) {
|
|
2301
|
+
if (e.clientX !== clientX || e.clientY !== clientY) {
|
|
2302
|
+
clientX = e.clientX;
|
|
2303
|
+
clientY = e.clientY;
|
|
2304
|
+
if (timeout) {
|
|
2305
|
+
globalThis.clearTimeout(timeout);
|
|
2306
|
+
timeout = void 0;
|
|
2307
|
+
}
|
|
2308
|
+
return;
|
|
2309
|
+
}
|
|
2310
|
+
if (timeout)
|
|
2311
|
+
return;
|
|
2312
|
+
timeout = globalThis.setTimeout(async () => {
|
|
2313
|
+
if (!stageOptions || !stage.value)
|
|
2314
|
+
return;
|
|
2315
|
+
const doc = stage.value.renderer.contentWindow?.document;
|
|
2316
|
+
const els = stage.value.getElementsFromPoint(e);
|
|
2317
|
+
for (const el of els) {
|
|
2318
|
+
if (doc && !el.id.startsWith(StageCore.GHOST_EL_ID_PREFIX) && await stageOptions.isContainer(el)) {
|
|
2319
|
+
utils.addClassName(el, doc, stageOptions?.containerHighlightClassName);
|
|
2320
|
+
break;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
}, stageOptions?.containerHighlightDuration);
|
|
2236
2324
|
}
|
|
2237
2325
|
};
|
|
2238
2326
|
}
|
|
@@ -2280,7 +2368,9 @@
|
|
|
2280
2368
|
draggable: "true",
|
|
2281
2369
|
key: item.type,
|
|
2282
2370
|
onClick: ($event) => _ctx.appendComponent(item),
|
|
2283
|
-
onDragstart: ($event) => _ctx.dragstartHandler(item, $event)
|
|
2371
|
+
onDragstart: ($event) => _ctx.dragstartHandler(item, $event),
|
|
2372
|
+
onDragend: _cache[1] || (_cache[1] = (...args) => _ctx.dragendHandler && _ctx.dragendHandler(...args)),
|
|
2373
|
+
onDrag: _cache[2] || (_cache[2] = (...args) => _ctx.dragHandler && _ctx.dragHandler(...args))
|
|
2284
2374
|
}, [
|
|
2285
2375
|
vue.createVNode(_component_m_icon, {
|
|
2286
2376
|
icon: item.icon
|
|
@@ -3489,6 +3579,9 @@
|
|
|
3489
3579
|
runtimeUrl: stageOptions.runtimeUrl,
|
|
3490
3580
|
zoom: zoom.value,
|
|
3491
3581
|
autoScrollIntoView: stageOptions.autoScrollIntoView,
|
|
3582
|
+
isContainer: stageOptions.isContainer,
|
|
3583
|
+
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
|
3584
|
+
containerHighlightDuration: stageOptions.containerHighlightDuration,
|
|
3492
3585
|
canSelect: (el, event, stop) => {
|
|
3493
3586
|
const elCanSelect = stageOptions.canSelect(el);
|
|
3494
3587
|
if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
|
|
@@ -3513,6 +3606,10 @@
|
|
|
3513
3606
|
services?.editorService.highlight(el.id);
|
|
3514
3607
|
});
|
|
3515
3608
|
stage?.on("update", (ev) => {
|
|
3609
|
+
if (ev.parentEl) {
|
|
3610
|
+
services?.editorService.moveToContainer({ id: ev.el.id, style: ev.style }, ev.parentEl.id);
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3516
3613
|
services?.editorService.update({ id: ev.el.id, style: ev.style });
|
|
3517
3614
|
});
|
|
3518
3615
|
stage?.on("sort", (ev) => {
|
|
@@ -3584,20 +3681,38 @@
|
|
|
3584
3681
|
},
|
|
3585
3682
|
async dropHandler(e) {
|
|
3586
3683
|
e.preventDefault();
|
|
3587
|
-
|
|
3684
|
+
const doc = stage?.renderer.contentWindow?.document;
|
|
3685
|
+
const parentEl = doc?.querySelector(`.${stageOptions?.containerHighlightClassName}`);
|
|
3686
|
+
let parent = page.value;
|
|
3687
|
+
if (parentEl) {
|
|
3688
|
+
parent = services?.editorService.getNodeById(parentEl.id, false);
|
|
3689
|
+
}
|
|
3690
|
+
if (e.dataTransfer && parent && stageContainer.value && stage) {
|
|
3588
3691
|
const config = eval(`(${e.dataTransfer.getData("data")})`);
|
|
3589
|
-
const layout = await services?.editorService.getLayout(
|
|
3692
|
+
const layout = await services?.editorService.getLayout(parent);
|
|
3590
3693
|
const containerRect = stageContainer.value.getBoundingClientRect();
|
|
3591
3694
|
const { scrollTop, scrollLeft } = stage.mask;
|
|
3695
|
+
const { style = {} } = config;
|
|
3696
|
+
let top = 0;
|
|
3697
|
+
let left = 0;
|
|
3698
|
+
let position = "relative";
|
|
3592
3699
|
if (layout === Layout.ABSOLUTE) {
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
left:
|
|
3598
|
-
|
|
3700
|
+
position = "absolute";
|
|
3701
|
+
top = e.clientY - containerRect.top + scrollTop;
|
|
3702
|
+
left = e.clientX - containerRect.left + scrollLeft;
|
|
3703
|
+
if (parentEl && doc) {
|
|
3704
|
+
const { left: parentLeft, top: parentTop } = StageCore.getOffset(parentEl);
|
|
3705
|
+
left = left - StageCore.calcValueByFontsize(doc, parentLeft);
|
|
3706
|
+
top = top - StageCore.calcValueByFontsize(doc, parentTop);
|
|
3707
|
+
}
|
|
3599
3708
|
}
|
|
3600
|
-
|
|
3709
|
+
config.style = {
|
|
3710
|
+
...style,
|
|
3711
|
+
position,
|
|
3712
|
+
top,
|
|
3713
|
+
left
|
|
3714
|
+
};
|
|
3715
|
+
services?.editorService.add(config, parent);
|
|
3601
3716
|
}
|
|
3602
3717
|
}
|
|
3603
3718
|
};
|
|
@@ -3958,6 +4073,18 @@
|
|
|
3958
4073
|
type: Function,
|
|
3959
4074
|
default: (el) => Boolean(el.id)
|
|
3960
4075
|
},
|
|
4076
|
+
isContainer: {
|
|
4077
|
+
type: Function,
|
|
4078
|
+
default: (el) => el.classList.contains("magic-ui-container")
|
|
4079
|
+
},
|
|
4080
|
+
containerHighlightClassName: {
|
|
4081
|
+
type: String,
|
|
4082
|
+
default: StageCore.CONTAINER_HIGHLIGHT_CLASS
|
|
4083
|
+
},
|
|
4084
|
+
containerHighlightDuration: {
|
|
4085
|
+
type: Number,
|
|
4086
|
+
default: 800
|
|
4087
|
+
},
|
|
3961
4088
|
stageRect: {
|
|
3962
4089
|
type: [String, Object]
|
|
3963
4090
|
},
|
|
@@ -4024,7 +4151,10 @@
|
|
|
4024
4151
|
render: props.render,
|
|
4025
4152
|
moveableOptions: props.moveableOptions,
|
|
4026
4153
|
canSelect: props.canSelect,
|
|
4027
|
-
updateDragEl: props.updateDragEl
|
|
4154
|
+
updateDragEl: props.updateDragEl,
|
|
4155
|
+
isContainer: props.isContainer,
|
|
4156
|
+
containerHighlightClassName: props.containerHighlightClassName,
|
|
4157
|
+
containerHighlightDuration: props.containerHighlightDuration
|
|
4028
4158
|
}));
|
|
4029
4159
|
return services;
|
|
4030
4160
|
}
|
|
@@ -4128,23 +4258,24 @@
|
|
|
4128
4258
|
exports.error = error;
|
|
4129
4259
|
exports.eventsService = eventsService;
|
|
4130
4260
|
exports.fillConfig = fillConfig;
|
|
4261
|
+
exports.fixNodeLeft = fixNodeLeft;
|
|
4131
4262
|
exports.generatePageName = generatePageName;
|
|
4132
4263
|
exports.generatePageNameByApp = generatePageNameByApp;
|
|
4133
4264
|
exports.getConfig = getConfig;
|
|
4134
4265
|
exports.getDefaultPropsValue = getDefaultPropsValue;
|
|
4135
4266
|
exports.getGuideLineFromCache = getGuideLineFromCache;
|
|
4267
|
+
exports.getInitPositionStyle = getInitPositionStyle;
|
|
4136
4268
|
exports.getNodeIndex = getNodeIndex;
|
|
4137
4269
|
exports.getPageList = getPageList;
|
|
4138
4270
|
exports.getPageNameList = getPageNameList;
|
|
4271
|
+
exports.getRelativeStyle = getRelativeStyle;
|
|
4139
4272
|
exports.historyService = historyService;
|
|
4140
4273
|
exports.info = info;
|
|
4141
|
-
exports.initPosition = initPosition;
|
|
4142
4274
|
exports.isFixed = isFixed;
|
|
4143
4275
|
exports.log = log;
|
|
4144
4276
|
exports.propsService = propsService;
|
|
4145
4277
|
exports.setConfig = setConfig;
|
|
4146
4278
|
exports.setLayout = setLayout;
|
|
4147
|
-
exports.toRelative = toRelative;
|
|
4148
4279
|
exports.uiService = uiService;
|
|
4149
4280
|
exports.warn = warn;
|
|
4150
4281
|
|