@tmagic/editor 1.0.4 → 1.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tmagic-editor.es.js +237 -98
- package/dist/tmagic-editor.es.js.map +1 -1
- package/dist/tmagic-editor.umd.js +269 -129
- 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 +8 -8
- package/src/Editor.vue +28 -6
- package/src/components/Icon.vue +1 -1
- package/src/components/ToolButton.vue +1 -1
- package/src/fields/UISelect.vue +1 -1
- package/src/layouts/AddPageBox.vue +1 -1
- package/src/layouts/PropsPanel.vue +12 -9
- package/src/layouts/sidebar/ComponentListPanel.vue +55 -2
- package/src/layouts/sidebar/LayerMenu.vue +1 -1
- package/src/layouts/sidebar/LayerPanel.vue +1 -1
- package/src/layouts/sidebar/Sidebar.vue +4 -4
- package/src/layouts/sidebar/TabPane.vue +7 -5
- package/src/layouts/workspace/PageBar.vue +1 -1
- package/src/layouts/workspace/Stage.vue +52 -11
- package/src/layouts/workspace/ViewerMenu.vue +1 -1
- package/src/services/editor.ts +74 -17
- package/src/type.ts +3 -0
- package/src/utils/editor.ts +45 -35
package/dist/tmagic-editor.es.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, markRaw, createElementBlock, createVNode, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, watch, onMounted, onUnmounted, reactive, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, normalizeProps, mergeProps, getCurrentInstance, nextTick, Teleport, toHandlers, createSlots, provide } from 'vue';
|
|
2
2
|
import serialize from 'serialize-javascript';
|
|
3
|
-
import { Delete, Pointer, Close, Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons';
|
|
3
|
+
import { Delete, Pointer, Close, Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
|
|
4
4
|
import { throttle, cloneDeep, mergeWith, random } from 'lodash-es';
|
|
5
5
|
import * as monaco from 'monaco-editor';
|
|
6
|
+
import StageCore, { GHOST_EL_ID_PREFIX, GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS } from '@tmagic/stage';
|
|
6
7
|
import { NodeType } from '@tmagic/schema';
|
|
7
|
-
import { toLine, isPop, getNodePath, isNumber, isPage } from '@tmagic/utils';
|
|
8
|
+
import { toLine, isPop, getNodePath, isNumber, isPage, removeClassNameByClassName, addClassName } from '@tmagic/utils';
|
|
8
9
|
import { EventEmitter } from 'events';
|
|
9
10
|
import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
|
|
10
11
|
import Gesto from 'gesto';
|
|
11
12
|
import { ElMessage } from 'element-plus';
|
|
12
13
|
import KeyController from 'keycon';
|
|
13
|
-
import StageCore, { GuidesType } from '@tmagic/stage';
|
|
14
14
|
|
|
15
15
|
if (typeof global === "undefined") {
|
|
16
16
|
window.global = window;
|
|
@@ -188,7 +188,7 @@ const _sfc_main$k = defineComponent({
|
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
190
|
});
|
|
191
|
-
const _hoisted_1$
|
|
191
|
+
const _hoisted_1$d = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
|
|
192
192
|
function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
|
|
193
193
|
const _component_el_button = resolveComponent("el-button");
|
|
194
194
|
const _component_el_tooltip = resolveComponent("el-tooltip");
|
|
@@ -204,7 +204,7 @@ function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
204
204
|
style: { "padding": "0" }
|
|
205
205
|
}, {
|
|
206
206
|
default: withCtx(() => [
|
|
207
|
-
_hoisted_1$
|
|
207
|
+
_hoisted_1$d
|
|
208
208
|
]),
|
|
209
209
|
_: 1
|
|
210
210
|
}, 8, ["icon"])
|
|
@@ -369,12 +369,12 @@ const _sfc_main$j = defineComponent({
|
|
|
369
369
|
};
|
|
370
370
|
}
|
|
371
371
|
});
|
|
372
|
-
const _hoisted_1$
|
|
372
|
+
const _hoisted_1$c = {
|
|
373
373
|
ref: "codeEditor",
|
|
374
374
|
class: "magic-code-editor"
|
|
375
375
|
};
|
|
376
376
|
function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
|
|
377
|
-
return openBlock(), createElementBlock("div", _hoisted_1$
|
|
377
|
+
return openBlock(), createElementBlock("div", _hoisted_1$c, null, 512);
|
|
378
378
|
}
|
|
379
379
|
var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
|
|
380
380
|
|
|
@@ -750,56 +750,50 @@ const getNodeIndex = (node, parent) => {
|
|
|
750
750
|
const items = parent?.items || [];
|
|
751
751
|
return items.findIndex((item) => `${item.id}` === `${node.id}`);
|
|
752
752
|
};
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
return node;
|
|
761
|
-
};
|
|
762
|
-
const setTop2Middle = (node, parentNode, stage) => {
|
|
763
|
-
const style = node.style || {};
|
|
753
|
+
const getRelativeStyle = (style = {}) => ({
|
|
754
|
+
...style,
|
|
755
|
+
position: "relative",
|
|
756
|
+
top: 0,
|
|
757
|
+
left: 0
|
|
758
|
+
});
|
|
759
|
+
const getMiddleTop = (style = {}, parentNode, stage) => {
|
|
764
760
|
let height = style.height || 0;
|
|
765
761
|
if (!stage || typeof style.top !== "undefined" || !parentNode.style)
|
|
766
|
-
return style;
|
|
762
|
+
return style.top;
|
|
767
763
|
if (!isNumber(height)) {
|
|
768
764
|
height = 0;
|
|
769
765
|
}
|
|
770
766
|
const { height: parentHeight } = parentNode.style;
|
|
771
767
|
if (isPage(parentNode)) {
|
|
772
768
|
const { scrollTop = 0, wrapperHeight } = stage.mask;
|
|
773
|
-
|
|
774
|
-
} else {
|
|
775
|
-
style.top = (parentHeight - height) / 2;
|
|
769
|
+
return (wrapperHeight - height) / 2 + scrollTop;
|
|
776
770
|
}
|
|
777
|
-
return
|
|
771
|
+
return (parentHeight - height) / 2;
|
|
778
772
|
};
|
|
779
|
-
const
|
|
773
|
+
const getInitPositionStyle = (style = {}, layout, parentNode, stage) => {
|
|
780
774
|
if (layout === Layout.ABSOLUTE) {
|
|
781
|
-
|
|
775
|
+
return {
|
|
776
|
+
...style,
|
|
782
777
|
position: "absolute",
|
|
783
|
-
|
|
778
|
+
top: getMiddleTop(style, parentNode, stage)
|
|
784
779
|
};
|
|
785
|
-
return node;
|
|
786
780
|
}
|
|
787
781
|
if (layout === Layout.RELATIVE) {
|
|
788
|
-
return
|
|
782
|
+
return getRelativeStyle(style);
|
|
789
783
|
}
|
|
790
|
-
return
|
|
784
|
+
return style;
|
|
791
785
|
};
|
|
792
786
|
const setLayout = (node, layout) => {
|
|
793
787
|
node.items?.forEach((child) => {
|
|
794
788
|
if (isPop(child))
|
|
795
789
|
return;
|
|
796
|
-
|
|
797
|
-
if (
|
|
790
|
+
const style = child.style || {};
|
|
791
|
+
if (style.position === "fixed")
|
|
798
792
|
return;
|
|
799
793
|
if (layout !== Layout.RELATIVE) {
|
|
800
|
-
|
|
794
|
+
style.position = "absolute";
|
|
801
795
|
} else {
|
|
802
|
-
|
|
796
|
+
child.style = getRelativeStyle(style);
|
|
803
797
|
child.style.right = "auto";
|
|
804
798
|
child.style.bottom = "auto";
|
|
805
799
|
}
|
|
@@ -816,11 +810,10 @@ const change2Fixed = (node, root) => {
|
|
|
816
810
|
offset.left = offset.left + globalThis.parseFloat(value.style?.left || 0);
|
|
817
811
|
offset.top = offset.top + globalThis.parseFloat(value.style?.top || 0);
|
|
818
812
|
});
|
|
819
|
-
|
|
813
|
+
return {
|
|
820
814
|
...node.style || {},
|
|
821
815
|
...offset
|
|
822
816
|
};
|
|
823
|
-
return node;
|
|
824
817
|
};
|
|
825
818
|
const Fixed2Other = async (node, root, getLayout) => {
|
|
826
819
|
const path = getNodePath(node.id, root.items);
|
|
@@ -835,20 +828,20 @@ const Fixed2Other = async (node, root, getLayout) => {
|
|
|
835
828
|
offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
|
|
836
829
|
offset.top = offset.top - globalThis.parseFloat(value.style?.top || 0);
|
|
837
830
|
});
|
|
831
|
+
const style = node.style || {};
|
|
838
832
|
const parent = path.pop();
|
|
839
833
|
if (!parent) {
|
|
840
|
-
return
|
|
834
|
+
return getRelativeStyle(style);
|
|
841
835
|
}
|
|
842
836
|
const layout = await getLayout(parent);
|
|
843
837
|
if (layout !== Layout.RELATIVE) {
|
|
844
|
-
|
|
845
|
-
...
|
|
838
|
+
return {
|
|
839
|
+
...style,
|
|
846
840
|
...offset,
|
|
847
841
|
position: "absolute"
|
|
848
842
|
};
|
|
849
|
-
return node;
|
|
850
843
|
}
|
|
851
|
-
return
|
|
844
|
+
return getRelativeStyle(style);
|
|
852
845
|
};
|
|
853
846
|
const getGuideLineFromCache = (key) => {
|
|
854
847
|
if (!key)
|
|
@@ -863,6 +856,16 @@ const getGuideLineFromCache = (key) => {
|
|
|
863
856
|
}
|
|
864
857
|
return [];
|
|
865
858
|
};
|
|
859
|
+
const fixNodeLeft = (config, parent, doc) => {
|
|
860
|
+
if (!doc || !config.style || !isNumber(config.style.left))
|
|
861
|
+
return config.style?.left;
|
|
862
|
+
const el = doc.getElementById(`${config.id}`);
|
|
863
|
+
const parentEl = doc.getElementById(`${parent.id}`);
|
|
864
|
+
if (el && parentEl && el.offsetWidth + config.style?.left > parentEl.offsetWidth) {
|
|
865
|
+
return parentEl.offsetWidth - el.offsetWidth;
|
|
866
|
+
}
|
|
867
|
+
return config.style.left;
|
|
868
|
+
};
|
|
866
869
|
|
|
867
870
|
const log = (...args) => {
|
|
868
871
|
};
|
|
@@ -888,6 +891,7 @@ class Editor$1 extends BaseService {
|
|
|
888
891
|
"paste",
|
|
889
892
|
"alignCenter",
|
|
890
893
|
"moveLayer",
|
|
894
|
+
"moveToContainer",
|
|
891
895
|
"move",
|
|
892
896
|
"undo",
|
|
893
897
|
"redo",
|
|
@@ -1027,13 +1031,22 @@ class Editor$1 extends BaseService {
|
|
|
1027
1031
|
if (!parentNode)
|
|
1028
1032
|
throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
|
|
1029
1033
|
const layout = await this.getLayout(toRaw(parentNode), addNode);
|
|
1030
|
-
const newNode =
|
|
1034
|
+
const newNode = { ...toRaw(await propsService.getPropsValue(type, config2)) };
|
|
1035
|
+
newNode.style = getInitPositionStyle(newNode.style, layout, parentNode, this.get("stage"));
|
|
1031
1036
|
if ((parentNode?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && newNode.type !== NodeType.PAGE) {
|
|
1032
1037
|
throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
|
|
1033
1038
|
}
|
|
1034
1039
|
parentNode?.items?.push(newNode);
|
|
1035
1040
|
const stage = this.get("stage");
|
|
1036
|
-
|
|
1041
|
+
const root = this.get("root");
|
|
1042
|
+
await stage?.add({ config: cloneDeep(newNode), root: cloneDeep(root) });
|
|
1043
|
+
if (layout === Layout.ABSOLUTE) {
|
|
1044
|
+
const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
|
|
1045
|
+
if (typeof fixedLeft !== "undefined") {
|
|
1046
|
+
newNode.style.left = fixedLeft;
|
|
1047
|
+
await stage?.update({ config: cloneDeep(newNode), root: cloneDeep(root) });
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1037
1050
|
await this.select(newNode);
|
|
1038
1051
|
this.addModifiedNodeId(newNode.id);
|
|
1039
1052
|
if (!isPage2) {
|
|
@@ -1060,7 +1073,7 @@ class Editor$1 extends BaseService {
|
|
|
1060
1073
|
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1061
1074
|
parent.items?.splice(index, 1);
|
|
1062
1075
|
const stage = this.get("stage");
|
|
1063
|
-
stage?.remove({ id: node.id, root: this.get("root") });
|
|
1076
|
+
stage?.remove({ id: node.id, root: cloneDeep(this.get("root")) });
|
|
1064
1077
|
if (node.type === NodeType.PAGE) {
|
|
1065
1078
|
this.state.pageLength -= 1;
|
|
1066
1079
|
if (root.items[0]) {
|
|
@@ -1121,7 +1134,7 @@ class Editor$1 extends BaseService {
|
|
|
1121
1134
|
if (`${newConfig.id}` === `${this.get("node").id}`) {
|
|
1122
1135
|
this.set("node", newConfig);
|
|
1123
1136
|
}
|
|
1124
|
-
this.get("stage")?.update({ config: cloneDeep(newConfig), root: this.get("root") });
|
|
1137
|
+
this.get("stage")?.update({ config: cloneDeep(newConfig), root: cloneDeep(this.get("root")) });
|
|
1125
1138
|
if (newConfig.type === NodeType.PAGE) {
|
|
1126
1139
|
this.set("page", newConfig);
|
|
1127
1140
|
}
|
|
@@ -1140,7 +1153,7 @@ class Editor$1 extends BaseService {
|
|
|
1140
1153
|
parent.items.splice(index2, 0, ...parent.items.splice(index1, 1));
|
|
1141
1154
|
await this.update(parent);
|
|
1142
1155
|
await this.select(node);
|
|
1143
|
-
this.get("stage")?.update({ config: cloneDeep(node), root: this.get("root") });
|
|
1156
|
+
this.get("stage")?.update({ config: cloneDeep(node), root: cloneDeep(this.get("root")) });
|
|
1144
1157
|
this.addModifiedNodeId(parent.id);
|
|
1145
1158
|
this.pushHistoryState();
|
|
1146
1159
|
}
|
|
@@ -1192,7 +1205,10 @@ class Editor$1 extends BaseService {
|
|
|
1192
1205
|
node.style.left = (parent.style.width - node.style.width) / 2;
|
|
1193
1206
|
}
|
|
1194
1207
|
await this.update(node);
|
|
1195
|
-
this.get("stage")?.update({
|
|
1208
|
+
this.get("stage")?.update({
|
|
1209
|
+
config: cloneDeep(toRaw(node)),
|
|
1210
|
+
root: cloneDeep(this.get("root"))
|
|
1211
|
+
});
|
|
1196
1212
|
this.addModifiedNodeId(config2.id);
|
|
1197
1213
|
this.pushHistoryState();
|
|
1198
1214
|
return config2;
|
|
@@ -1209,7 +1225,37 @@ class Editor$1 extends BaseService {
|
|
|
1209
1225
|
} else {
|
|
1210
1226
|
brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
|
|
1211
1227
|
}
|
|
1212
|
-
this.get("stage")?.update({
|
|
1228
|
+
this.get("stage")?.update({
|
|
1229
|
+
config: cloneDeep(toRaw(parent)),
|
|
1230
|
+
root: cloneDeep(this.get("root"))
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
async moveToContainer(config2, targetId) {
|
|
1234
|
+
const { node, parent } = this.getNodeInfo(config2.id, false);
|
|
1235
|
+
const target = this.getNodeById(targetId, false);
|
|
1236
|
+
const stage = this.get("stage");
|
|
1237
|
+
if (node && parent && stage) {
|
|
1238
|
+
const root = cloneDeep(this.get("root"));
|
|
1239
|
+
const index = getNodeIndex(node, parent);
|
|
1240
|
+
parent.items?.splice(index, 1);
|
|
1241
|
+
await stage.remove({ id: node.id, root });
|
|
1242
|
+
const layout = await this.getLayout(target);
|
|
1243
|
+
const newConfig = mergeWith(cloneDeep(node), config2, (objValue, srcValue) => {
|
|
1244
|
+
if (Array.isArray(srcValue)) {
|
|
1245
|
+
return srcValue;
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
newConfig.style = getInitPositionStyle(newConfig.style, layout, target, stage);
|
|
1249
|
+
target.items.push(newConfig);
|
|
1250
|
+
await stage.select(targetId);
|
|
1251
|
+
await stage.update({ config: cloneDeep(target), root });
|
|
1252
|
+
await this.select(newConfig);
|
|
1253
|
+
stage.select(newConfig.id);
|
|
1254
|
+
this.addModifiedNodeId(target.id);
|
|
1255
|
+
this.addModifiedNodeId(parent.id);
|
|
1256
|
+
this.pushHistoryState();
|
|
1257
|
+
return newConfig;
|
|
1258
|
+
}
|
|
1213
1259
|
}
|
|
1214
1260
|
async undo() {
|
|
1215
1261
|
const value = historyService.undo();
|
|
@@ -1281,12 +1327,12 @@ class Editor$1 extends BaseService {
|
|
|
1281
1327
|
}, 0);
|
|
1282
1328
|
}
|
|
1283
1329
|
async toggleFixedPosition(dist, src, root) {
|
|
1284
|
-
|
|
1330
|
+
const newConfig = cloneDeep(dist);
|
|
1285
1331
|
if (!isPop(src) && newConfig.style?.position) {
|
|
1286
1332
|
if (isFixed(newConfig) && !isFixed(src)) {
|
|
1287
|
-
newConfig = change2Fixed(newConfig, root);
|
|
1333
|
+
newConfig.style = change2Fixed(newConfig, root);
|
|
1288
1334
|
} else if (!isFixed(newConfig) && isFixed(src)) {
|
|
1289
|
-
newConfig = await Fixed2Other(newConfig, root, this.getLayout);
|
|
1335
|
+
newConfig.style = await Fixed2Other(newConfig, root, this.getLayout);
|
|
1290
1336
|
}
|
|
1291
1337
|
}
|
|
1292
1338
|
return newConfig;
|
|
@@ -1595,13 +1641,13 @@ const _sfc_main$i = defineComponent({
|
|
|
1595
1641
|
};
|
|
1596
1642
|
}
|
|
1597
1643
|
});
|
|
1598
|
-
const _hoisted_1$
|
|
1644
|
+
const _hoisted_1$b = { class: "m-editor-empty-panel" };
|
|
1599
1645
|
const _hoisted_2$4 = { class: "m-editor-empty-content" };
|
|
1600
1646
|
const _hoisted_3$2 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
|
|
1601
1647
|
function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
|
|
1602
1648
|
const _component_plus = resolveComponent("plus");
|
|
1603
1649
|
const _component_el_icon = resolveComponent("el-icon");
|
|
1604
|
-
return openBlock(), createElementBlock("div", _hoisted_1$
|
|
1650
|
+
return openBlock(), createElementBlock("div", _hoisted_1$b, [
|
|
1605
1651
|
createElementVNode("div", _hoisted_2$4, [
|
|
1606
1652
|
createElementVNode("div", {
|
|
1607
1653
|
class: "m-editor-empty-button",
|
|
@@ -1664,12 +1710,12 @@ const _sfc_main$h = defineComponent({
|
|
|
1664
1710
|
};
|
|
1665
1711
|
}
|
|
1666
1712
|
});
|
|
1667
|
-
const _hoisted_1$
|
|
1713
|
+
const _hoisted_1$a = {
|
|
1668
1714
|
ref: "target",
|
|
1669
1715
|
class: "m-editor-resizer"
|
|
1670
1716
|
};
|
|
1671
1717
|
function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
|
|
1672
|
-
return openBlock(), createElementBlock("span", _hoisted_1$
|
|
1718
|
+
return openBlock(), createElementBlock("span", _hoisted_1$a, [
|
|
1673
1719
|
renderSlot(_ctx.$slots, "default")
|
|
1674
1720
|
], 512);
|
|
1675
1721
|
}
|
|
@@ -1704,7 +1750,7 @@ const _sfc_main$g = defineComponent({
|
|
|
1704
1750
|
};
|
|
1705
1751
|
}
|
|
1706
1752
|
});
|
|
1707
|
-
const _hoisted_1$
|
|
1753
|
+
const _hoisted_1$9 = { class: "m-editor" };
|
|
1708
1754
|
const _hoisted_2$3 = {
|
|
1709
1755
|
key: 1,
|
|
1710
1756
|
class: "m-editor-content"
|
|
@@ -1714,7 +1760,7 @@ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
1714
1760
|
const _component_resizer = resolveComponent("resizer");
|
|
1715
1761
|
const _component_el_scrollbar = resolveComponent("el-scrollbar");
|
|
1716
1762
|
const _component_add_page_box = resolveComponent("add-page-box");
|
|
1717
|
-
return openBlock(), createElementBlock("div", _hoisted_1$
|
|
1763
|
+
return openBlock(), createElementBlock("div", _hoisted_1$9, [
|
|
1718
1764
|
renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
|
|
1719
1765
|
_ctx.showSrc ? (openBlock(), createBlock(_component_magic_code_editor, {
|
|
1720
1766
|
key: 0,
|
|
@@ -1771,7 +1817,7 @@ const _sfc_main$f = defineComponent({
|
|
|
1771
1817
|
};
|
|
1772
1818
|
}
|
|
1773
1819
|
});
|
|
1774
|
-
const _hoisted_1$
|
|
1820
|
+
const _hoisted_1$8 = ["src"];
|
|
1775
1821
|
function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
|
|
1776
1822
|
const _component_edit = resolveComponent("edit");
|
|
1777
1823
|
const _component_el_icon = resolveComponent("el-icon");
|
|
@@ -1783,7 +1829,7 @@ function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
1783
1829
|
})) : typeof _ctx.icon === "string" && _ctx.icon.startsWith("http") ? (openBlock(), createElementBlock("img", {
|
|
1784
1830
|
key: 1,
|
|
1785
1831
|
src: _ctx.icon
|
|
1786
|
-
}, null, 8, _hoisted_1$
|
|
1832
|
+
}, null, 8, _hoisted_1$8)) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
|
|
1787
1833
|
key: 2,
|
|
1788
1834
|
class: normalizeClass(_ctx.icon)
|
|
1789
1835
|
}, null, 2)) : (openBlock(), createBlock(_component_el_icon, { key: 3 }, {
|
|
@@ -1955,7 +2001,7 @@ const _sfc_main$e = defineComponent({
|
|
|
1955
2001
|
};
|
|
1956
2002
|
}
|
|
1957
2003
|
});
|
|
1958
|
-
const _hoisted_1$
|
|
2004
|
+
const _hoisted_1$7 = {
|
|
1959
2005
|
key: 1,
|
|
1960
2006
|
class: "menu-item-text"
|
|
1961
2007
|
};
|
|
@@ -1985,7 +2031,7 @@ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
1985
2031
|
_ctx.item.type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
|
|
1986
2032
|
key: 0,
|
|
1987
2033
|
direction: _ctx.item.direction || "vertical"
|
|
1988
|
-
}, null, 8, ["direction"])) : _ctx.item.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$
|
|
2034
|
+
}, null, 8, ["direction"])) : _ctx.item.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$7, toDisplayString(_ctx.item.text), 1)) : _ctx.item.type === "zoom" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
|
|
1989
2035
|
createVNode(_component_tool_button, {
|
|
1990
2036
|
data: { type: "button", icon: _ctx.ZoomOut, handler: _ctx.zoomOutHandler, tooltip: "\u7F29\u5C0F" },
|
|
1991
2037
|
"event-type": _ctx.eventType
|
|
@@ -2166,17 +2212,21 @@ const _sfc_main$c = defineComponent({
|
|
|
2166
2212
|
};
|
|
2167
2213
|
}
|
|
2168
2214
|
});
|
|
2215
|
+
const _hoisted_1$6 = { class: "`m-editor-props-panel" };
|
|
2169
2216
|
function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
|
|
2170
2217
|
const _component_m_form = resolveComponent("m-form");
|
|
2171
|
-
return openBlock(),
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2218
|
+
return openBlock(), createElementBlock("div", _hoisted_1$6, [
|
|
2219
|
+
renderSlot(_ctx.$slots, "props-panel-header"),
|
|
2220
|
+
createVNode(_component_m_form, {
|
|
2221
|
+
class: normalizeClass(`m-editor-props-panel ${_ctx.propsPanelSize}`),
|
|
2222
|
+
"popper-class": `m-editor-props-panel-popper ${_ctx.propsPanelSize}`,
|
|
2223
|
+
ref: "configForm",
|
|
2224
|
+
size: _ctx.propsPanelSize,
|
|
2225
|
+
"init-values": _ctx.values,
|
|
2226
|
+
config: _ctx.curFormConfig,
|
|
2227
|
+
onChange: _ctx.submit
|
|
2228
|
+
}, null, 8, ["class", "popper-class", "size", "init-values", "config", "onChange"])
|
|
2229
|
+
]);
|
|
2180
2230
|
}
|
|
2181
2231
|
var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
|
|
2182
2232
|
|
|
@@ -2186,11 +2236,16 @@ const _sfc_main$b = defineComponent({
|
|
|
2186
2236
|
setup() {
|
|
2187
2237
|
const searchText = ref("");
|
|
2188
2238
|
const services = inject("services");
|
|
2239
|
+
const stageOptions = inject("stageOptions");
|
|
2240
|
+
const stage = computed(() => services?.editorService.get("stage"));
|
|
2189
2241
|
const list = computed(() => services?.componentListService.getList().map((group) => ({
|
|
2190
2242
|
...group,
|
|
2191
2243
|
items: group.items.filter((item) => item.text.includes(searchText.value))
|
|
2192
2244
|
})));
|
|
2193
2245
|
const collapseValue = computed(() => Array(list.value?.length).fill(1).map((x, i) => i));
|
|
2246
|
+
let timeout;
|
|
2247
|
+
let clientX;
|
|
2248
|
+
let clientY;
|
|
2194
2249
|
return {
|
|
2195
2250
|
searchText,
|
|
2196
2251
|
collapseValue,
|
|
@@ -2211,6 +2266,43 @@ const _sfc_main$b = defineComponent({
|
|
|
2211
2266
|
...data
|
|
2212
2267
|
}).replace(/"(\w+)":\s/g, "$1: "));
|
|
2213
2268
|
}
|
|
2269
|
+
},
|
|
2270
|
+
dragendHandler() {
|
|
2271
|
+
if (timeout) {
|
|
2272
|
+
globalThis.clearTimeout(timeout);
|
|
2273
|
+
timeout = void 0;
|
|
2274
|
+
}
|
|
2275
|
+
const doc = stage.value?.renderer.contentWindow?.document;
|
|
2276
|
+
if (doc && stageOptions) {
|
|
2277
|
+
removeClassNameByClassName(doc, stageOptions.containerHighlightClassName);
|
|
2278
|
+
}
|
|
2279
|
+
clientX = 0;
|
|
2280
|
+
clientY = 0;
|
|
2281
|
+
},
|
|
2282
|
+
dragHandler(e) {
|
|
2283
|
+
if (e.clientX !== clientX || e.clientY !== clientY) {
|
|
2284
|
+
clientX = e.clientX;
|
|
2285
|
+
clientY = e.clientY;
|
|
2286
|
+
if (timeout) {
|
|
2287
|
+
globalThis.clearTimeout(timeout);
|
|
2288
|
+
timeout = void 0;
|
|
2289
|
+
}
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
if (timeout)
|
|
2293
|
+
return;
|
|
2294
|
+
timeout = globalThis.setTimeout(async () => {
|
|
2295
|
+
if (!stageOptions || !stage.value)
|
|
2296
|
+
return;
|
|
2297
|
+
const doc = stage.value.renderer.contentWindow?.document;
|
|
2298
|
+
const els = stage.value.getElementsFromPoint(e);
|
|
2299
|
+
for (const el of els) {
|
|
2300
|
+
if (doc && !el.id.startsWith(GHOST_EL_ID_PREFIX) && await stageOptions.isContainer(el)) {
|
|
2301
|
+
addClassName(el, doc, stageOptions?.containerHighlightClassName);
|
|
2302
|
+
break;
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
}, stageOptions?.containerHighlightDuration);
|
|
2214
2306
|
}
|
|
2215
2307
|
};
|
|
2216
2308
|
}
|
|
@@ -2226,7 +2318,7 @@ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2226
2318
|
const _component_el_scrollbar = resolveComponent("el-scrollbar");
|
|
2227
2319
|
return openBlock(), createBlock(_component_el_scrollbar, null, {
|
|
2228
2320
|
default: withCtx(() => [
|
|
2229
|
-
renderSlot(_ctx.$slots, "component-list-panel"),
|
|
2321
|
+
renderSlot(_ctx.$slots, "component-list-panel-header"),
|
|
2230
2322
|
createVNode(_component_el_collapse, {
|
|
2231
2323
|
class: "ui-component-panel",
|
|
2232
2324
|
"model-value": _ctx.collapseValue
|
|
@@ -2258,7 +2350,9 @@ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2258
2350
|
draggable: "true",
|
|
2259
2351
|
key: item.type,
|
|
2260
2352
|
onClick: ($event) => _ctx.appendComponent(item),
|
|
2261
|
-
onDragstart: ($event) => _ctx.dragstartHandler(item, $event)
|
|
2353
|
+
onDragstart: ($event) => _ctx.dragstartHandler(item, $event),
|
|
2354
|
+
onDragend: _cache[1] || (_cache[1] = (...args) => _ctx.dragendHandler && _ctx.dragendHandler(...args)),
|
|
2355
|
+
onDrag: _cache[2] || (_cache[2] = (...args) => _ctx.dragHandler && _ctx.dragHandler(...args))
|
|
2262
2356
|
}, [
|
|
2263
2357
|
createVNode(_component_m_icon, {
|
|
2264
2358
|
icon: item.icon
|
|
@@ -2649,7 +2743,7 @@ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2649
2743
|
const _component_el_scrollbar = resolveComponent("el-scrollbar");
|
|
2650
2744
|
return openBlock(), createBlock(_component_el_scrollbar, { class: "magic-editor-layer-panel" }, {
|
|
2651
2745
|
default: withCtx(() => [
|
|
2652
|
-
renderSlot(_ctx.$slots, "layer-panel"),
|
|
2746
|
+
renderSlot(_ctx.$slots, "layer-panel-header"),
|
|
2653
2747
|
createVNode(_component_el_input, {
|
|
2654
2748
|
class: "filterInput",
|
|
2655
2749
|
size: "small",
|
|
@@ -2767,16 +2861,16 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2767
2861
|
]),
|
|
2768
2862
|
default: withCtx(() => [
|
|
2769
2863
|
(openBlock(), createBlock(resolveDynamicComponent(_ctx.config.component), mergeProps(_ctx.config.props || {}, toHandlers(_ctx.config?.listeners || {})), createSlots({ _: 2 }, [
|
|
2770
|
-
_ctx.data === "
|
|
2771
|
-
name: "
|
|
2864
|
+
_ctx.data === "component-list" || _ctx.config.slots?.componentListPanelHeader ? {
|
|
2865
|
+
name: "component-list-panel-header",
|
|
2772
2866
|
fn: withCtx(() => [
|
|
2773
|
-
renderSlot(_ctx.$slots, "
|
|
2867
|
+
_ctx.data === "component-list" ? renderSlot(_ctx.$slots, "component-list-panel-header", { key: 0 }) : _ctx.config.slots?.componentListPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots.componentListPanelHeader), { key: 1 })) : createCommentVNode("", true)
|
|
2774
2868
|
])
|
|
2775
2869
|
} : void 0,
|
|
2776
|
-
_ctx.data === "
|
|
2777
|
-
name: "
|
|
2870
|
+
_ctx.data === "layer" || _ctx.config.slots?.layerPanelHeader ? {
|
|
2871
|
+
name: "layer-panel-header",
|
|
2778
2872
|
fn: withCtx(() => [
|
|
2779
|
-
renderSlot(_ctx.$slots, "
|
|
2873
|
+
_ctx.data === "layer" ? renderSlot(_ctx.$slots, "layer-panel-header", { key: 0 }) : _ctx.config.slots?.layerPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots.layerPanelHeader), { key: 1 })) : createCommentVNode("", true)
|
|
2780
2874
|
])
|
|
2781
2875
|
} : void 0,
|
|
2782
2876
|
_ctx.config.slots?.layerNodeContent ? {
|
|
@@ -2832,15 +2926,15 @@ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2832
2926
|
data: item
|
|
2833
2927
|
}, createSlots({ _: 2 }, [
|
|
2834
2928
|
item === "layer" ? {
|
|
2835
|
-
name: "layer-panel",
|
|
2929
|
+
name: "layer-panel-header",
|
|
2836
2930
|
fn: withCtx(() => [
|
|
2837
|
-
renderSlot(_ctx.$slots, "layer-panel")
|
|
2931
|
+
renderSlot(_ctx.$slots, "layer-panel-header")
|
|
2838
2932
|
])
|
|
2839
2933
|
} : void 0,
|
|
2840
2934
|
item === "component-list" ? {
|
|
2841
|
-
name: "component-list-panel",
|
|
2935
|
+
name: "component-list-panel-header",
|
|
2842
2936
|
fn: withCtx(() => [
|
|
2843
|
-
renderSlot(_ctx.$slots, "component-list-panel")
|
|
2937
|
+
renderSlot(_ctx.$slots, "component-list-panel-header")
|
|
2844
2938
|
])
|
|
2845
2939
|
} : void 0
|
|
2846
2940
|
]), 1032, ["data"]);
|
|
@@ -3467,6 +3561,9 @@ const _sfc_main$2 = defineComponent({
|
|
|
3467
3561
|
runtimeUrl: stageOptions.runtimeUrl,
|
|
3468
3562
|
zoom: zoom.value,
|
|
3469
3563
|
autoScrollIntoView: stageOptions.autoScrollIntoView,
|
|
3564
|
+
isContainer: stageOptions.isContainer,
|
|
3565
|
+
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
|
3566
|
+
containerHighlightDuration: stageOptions.containerHighlightDuration,
|
|
3470
3567
|
canSelect: (el, event, stop) => {
|
|
3471
3568
|
const elCanSelect = stageOptions.canSelect(el);
|
|
3472
3569
|
if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
|
|
@@ -3491,6 +3588,10 @@ const _sfc_main$2 = defineComponent({
|
|
|
3491
3588
|
services?.editorService.highlight(el.id);
|
|
3492
3589
|
});
|
|
3493
3590
|
stage?.on("update", (ev) => {
|
|
3591
|
+
if (ev.parentEl) {
|
|
3592
|
+
services?.editorService.moveToContainer({ id: ev.el.id, style: ev.style }, ev.parentEl.id);
|
|
3593
|
+
return;
|
|
3594
|
+
}
|
|
3494
3595
|
services?.editorService.update({ id: ev.el.id, style: ev.style });
|
|
3495
3596
|
});
|
|
3496
3597
|
stage?.on("sort", (ev) => {
|
|
@@ -3562,20 +3663,38 @@ const _sfc_main$2 = defineComponent({
|
|
|
3562
3663
|
},
|
|
3563
3664
|
async dropHandler(e) {
|
|
3564
3665
|
e.preventDefault();
|
|
3565
|
-
|
|
3666
|
+
const doc = stage?.renderer.contentWindow?.document;
|
|
3667
|
+
const parentEl = doc?.querySelector(`.${stageOptions?.containerHighlightClassName}`);
|
|
3668
|
+
let parent = page.value;
|
|
3669
|
+
if (parentEl) {
|
|
3670
|
+
parent = services?.editorService.getNodeById(parentEl.id, false);
|
|
3671
|
+
}
|
|
3672
|
+
if (e.dataTransfer && parent && stageContainer.value && stage) {
|
|
3566
3673
|
const config = eval(`(${e.dataTransfer.getData("data")})`);
|
|
3567
|
-
const layout = await services?.editorService.getLayout(
|
|
3674
|
+
const layout = await services?.editorService.getLayout(parent);
|
|
3568
3675
|
const containerRect = stageContainer.value.getBoundingClientRect();
|
|
3569
3676
|
const { scrollTop, scrollLeft } = stage.mask;
|
|
3677
|
+
const { style = {} } = config;
|
|
3678
|
+
let top = 0;
|
|
3679
|
+
let left = 0;
|
|
3680
|
+
let position = "relative";
|
|
3570
3681
|
if (layout === Layout.ABSOLUTE) {
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
left:
|
|
3576
|
-
|
|
3682
|
+
position = "absolute";
|
|
3683
|
+
top = e.clientY - containerRect.top + scrollTop;
|
|
3684
|
+
left = e.clientX - containerRect.left + scrollLeft;
|
|
3685
|
+
if (parentEl && doc) {
|
|
3686
|
+
const { left: parentLeft, top: parentTop } = getOffset(parentEl);
|
|
3687
|
+
left = left - calcValueByFontsize(doc, parentLeft);
|
|
3688
|
+
top = top - calcValueByFontsize(doc, parentTop);
|
|
3689
|
+
}
|
|
3577
3690
|
}
|
|
3578
|
-
|
|
3691
|
+
config.style = {
|
|
3692
|
+
...style,
|
|
3693
|
+
position,
|
|
3694
|
+
top,
|
|
3695
|
+
left
|
|
3696
|
+
};
|
|
3697
|
+
services?.editorService.add(config, parent);
|
|
3579
3698
|
}
|
|
3580
3699
|
}
|
|
3581
3700
|
};
|
|
@@ -3936,6 +4055,18 @@ const _sfc_main = defineComponent({
|
|
|
3936
4055
|
type: Function,
|
|
3937
4056
|
default: (el) => Boolean(el.id)
|
|
3938
4057
|
},
|
|
4058
|
+
isContainer: {
|
|
4059
|
+
type: Function,
|
|
4060
|
+
default: (el) => el.classList.contains("magic-ui-container")
|
|
4061
|
+
},
|
|
4062
|
+
containerHighlightClassName: {
|
|
4063
|
+
type: String,
|
|
4064
|
+
default: CONTAINER_HIGHLIGHT_CLASS
|
|
4065
|
+
},
|
|
4066
|
+
containerHighlightDuration: {
|
|
4067
|
+
type: Number,
|
|
4068
|
+
default: 800
|
|
4069
|
+
},
|
|
3939
4070
|
stageRect: {
|
|
3940
4071
|
type: [String, Object]
|
|
3941
4072
|
},
|
|
@@ -4002,7 +4133,10 @@ const _sfc_main = defineComponent({
|
|
|
4002
4133
|
render: props.render,
|
|
4003
4134
|
moveableOptions: props.moveableOptions,
|
|
4004
4135
|
canSelect: props.canSelect,
|
|
4005
|
-
updateDragEl: props.updateDragEl
|
|
4136
|
+
updateDragEl: props.updateDragEl,
|
|
4137
|
+
isContainer: props.isContainer,
|
|
4138
|
+
containerHighlightClassName: props.containerHighlightClassName,
|
|
4139
|
+
containerHighlightDuration: props.containerHighlightDuration
|
|
4006
4140
|
}));
|
|
4007
4141
|
return services;
|
|
4008
4142
|
}
|
|
@@ -4022,11 +4156,11 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
4022
4156
|
sidebar: withCtx(() => [
|
|
4023
4157
|
renderSlot(_ctx.$slots, "sidebar", { editorService: _ctx.editorService }, () => [
|
|
4024
4158
|
createVNode(_component_sidebar, { data: _ctx.sidebar }, {
|
|
4025
|
-
"layer-panel": withCtx(() => [
|
|
4026
|
-
renderSlot(_ctx.$slots, "layer-panel")
|
|
4159
|
+
"layer-panel-header": withCtx(() => [
|
|
4160
|
+
renderSlot(_ctx.$slots, "layer-panel-header")
|
|
4027
4161
|
]),
|
|
4028
|
-
"component-list-panel": withCtx(() => [
|
|
4029
|
-
renderSlot(_ctx.$slots, "component-list-panel")
|
|
4162
|
+
"component-list-panel-header": withCtx(() => [
|
|
4163
|
+
renderSlot(_ctx.$slots, "component-list-panel-header")
|
|
4030
4164
|
]),
|
|
4031
4165
|
_: 3
|
|
4032
4166
|
}, 8, ["data"])
|
|
@@ -4053,7 +4187,12 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
4053
4187
|
createVNode(_component_props_panel, {
|
|
4054
4188
|
ref: "propsPanel",
|
|
4055
4189
|
onMounted: _cache[0] || (_cache[0] = (instance) => _ctx.$emit("props-panel-mounted", instance))
|
|
4056
|
-
},
|
|
4190
|
+
}, {
|
|
4191
|
+
"props-panel-header": withCtx(() => [
|
|
4192
|
+
renderSlot(_ctx.$slots, "props-panel-header")
|
|
4193
|
+
]),
|
|
4194
|
+
_: 3
|
|
4195
|
+
}, 512)
|
|
4057
4196
|
])
|
|
4058
4197
|
]),
|
|
4059
4198
|
empty: withCtx(() => [
|
|
@@ -4080,5 +4219,5 @@ var index = {
|
|
|
4080
4219
|
}
|
|
4081
4220
|
};
|
|
4082
4221
|
|
|
4083
|
-
export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getGuideLineFromCache, getNodeIndex, getPageList, getPageNameList, historyService, info,
|
|
4222
|
+
export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, uiService, warn };
|
|
4084
4223
|
//# sourceMappingURL=tmagic-editor.es.js.map
|