@tmagic/editor 1.1.0-beta.7 → 1.1.0-beta.8
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/style.css +4 -0
- package/dist/tmagic-editor.mjs +84 -87
- package/dist/tmagic-editor.mjs.map +1 -1
- package/dist/tmagic-editor.umd.js +84 -86
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/package.json +7 -7
- package/src/components/Icon.vue +1 -1
- package/src/layouts/workspace/ViewerMenu.vue +4 -7
- package/src/layouts/workspace/Workspace.vue +1 -1
- package/src/services/editor.ts +64 -47
- package/src/theme/component-list-panel.scss +5 -0
- package/src/utils/editor.ts +17 -10
- package/src/utils/operator.ts +25 -72
- package/types/layouts/workspace/ViewerMenu.vue.d.ts +3 -3
- package/types/services/editor.d.ts +3 -8
- package/types/utils/editor.d.ts +4 -1
- package/types/utils/operator.d.ts +3 -20
package/dist/style.css
CHANGED
|
@@ -353,6 +353,10 @@
|
|
|
353
353
|
color: #fff;
|
|
354
354
|
border-color: #4e8be1;
|
|
355
355
|
}
|
|
356
|
+
.ui-component-panel .el-collapse-item__wrap .component-item img {
|
|
357
|
+
max-width: 100%;
|
|
358
|
+
max-height: 100%;
|
|
359
|
+
}
|
|
356
360
|
.ui-component-panel .el-collapse-item__wrap .component-item span {
|
|
357
361
|
font-size: 12px;
|
|
358
362
|
text-align: center;
|
package/dist/tmagic-editor.mjs
CHANGED
|
@@ -743,10 +743,10 @@ const getRelativeStyle = (style = {}) => ({
|
|
|
743
743
|
top: 0,
|
|
744
744
|
left: 0
|
|
745
745
|
});
|
|
746
|
-
const getMiddleTop = (
|
|
747
|
-
let height = style
|
|
748
|
-
if (!stage || typeof style
|
|
749
|
-
return style
|
|
746
|
+
const getMiddleTop = (node, parentNode, stage) => {
|
|
747
|
+
let height = node.style?.height || 0;
|
|
748
|
+
if (!stage || typeof node.style?.top !== "undefined" || !parentNode.style)
|
|
749
|
+
return node.style?.top;
|
|
750
750
|
if (!isNumber(height)) {
|
|
751
751
|
height = 0;
|
|
752
752
|
}
|
|
@@ -757,12 +757,11 @@ const getMiddleTop = (style = {}, parentNode, stage) => {
|
|
|
757
757
|
}
|
|
758
758
|
return (parentHeight - height) / 2;
|
|
759
759
|
};
|
|
760
|
-
const getInitPositionStyle = (style = {}, layout
|
|
760
|
+
const getInitPositionStyle = (style = {}, layout) => {
|
|
761
761
|
if (layout === Layout.ABSOLUTE) {
|
|
762
762
|
return {
|
|
763
763
|
...style,
|
|
764
|
-
position: "absolute"
|
|
765
|
-
top: getMiddleTop(style, parentNode, stage)
|
|
764
|
+
position: "absolute"
|
|
766
765
|
};
|
|
767
766
|
}
|
|
768
767
|
if (layout === Layout.RELATIVE) {
|
|
@@ -854,6 +853,16 @@ const fixNodeLeft = (config, parent, doc) => {
|
|
|
854
853
|
}
|
|
855
854
|
return config.style.left;
|
|
856
855
|
};
|
|
856
|
+
const fixNodePosition = (config, parent, stage) => {
|
|
857
|
+
if (config.style?.position !== "absolute") {
|
|
858
|
+
return config.style;
|
|
859
|
+
}
|
|
860
|
+
return {
|
|
861
|
+
...config.style || {},
|
|
862
|
+
top: getMiddleTop(config, parent, stage),
|
|
863
|
+
left: fixNodeLeft(config, parent, stage?.renderer.contentWindow?.document)
|
|
864
|
+
};
|
|
865
|
+
};
|
|
857
866
|
|
|
858
867
|
class Props extends BaseService {
|
|
859
868
|
state = reactive({
|
|
@@ -1010,36 +1019,6 @@ const beforePaste = async (position, config) => {
|
|
|
1010
1019
|
}));
|
|
1011
1020
|
return pasteConfigs;
|
|
1012
1021
|
};
|
|
1013
|
-
const beforeAdd = async (addNode, parent) => {
|
|
1014
|
-
const { type, inputEvent, ...config } = addNode;
|
|
1015
|
-
const curNode = editorService.get("node");
|
|
1016
|
-
let parentNode;
|
|
1017
|
-
const isPage2 = type === NodeType.PAGE;
|
|
1018
|
-
if (isPage2) {
|
|
1019
|
-
parentNode = editorService.get("root");
|
|
1020
|
-
} else if (parent && typeof parent !== "function") {
|
|
1021
|
-
parentNode = parent;
|
|
1022
|
-
} else if (curNode.items) {
|
|
1023
|
-
parentNode = curNode;
|
|
1024
|
-
} else {
|
|
1025
|
-
parentNode = editorService.getParentById(curNode.id, false);
|
|
1026
|
-
}
|
|
1027
|
-
if (!parentNode)
|
|
1028
|
-
throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
|
|
1029
|
-
const layout = await editorService.getLayout(toRaw(parentNode), addNode);
|
|
1030
|
-
const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
|
|
1031
|
-
newNode.style = getInitPositionStyle(newNode.style, layout, parentNode, editorService.get("stage"));
|
|
1032
|
-
if ((parentNode?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && newNode.type !== NodeType.PAGE) {
|
|
1033
|
-
throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
|
|
1034
|
-
}
|
|
1035
|
-
parentNode?.items?.push(newNode);
|
|
1036
|
-
return {
|
|
1037
|
-
parentNode,
|
|
1038
|
-
newNode,
|
|
1039
|
-
layout,
|
|
1040
|
-
isPage: isPage2
|
|
1041
|
-
};
|
|
1042
|
-
};
|
|
1043
1022
|
const getPositionInContainer = (position = {}, id) => {
|
|
1044
1023
|
let { left = 0, top = 0 } = position;
|
|
1045
1024
|
const parentEl = editorService.get("stage")?.renderer?.contentWindow?.document.getElementById(`${id}`);
|
|
@@ -1051,18 +1030,6 @@ const getPositionInContainer = (position = {}, id) => {
|
|
|
1051
1030
|
top
|
|
1052
1031
|
};
|
|
1053
1032
|
};
|
|
1054
|
-
const notifyAddToStage = async (parentNode, newNode, layout) => {
|
|
1055
|
-
const stage = editorService.get("stage");
|
|
1056
|
-
const root = editorService.get("root");
|
|
1057
|
-
await stage?.add({ config: cloneDeep(newNode), parent: cloneDeep(parentNode), root: cloneDeep(root) });
|
|
1058
|
-
if (layout === Layout.ABSOLUTE) {
|
|
1059
|
-
const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
|
|
1060
|
-
if (typeof fixedLeft !== "undefined" && newNode.style) {
|
|
1061
|
-
newNode.style.left = fixedLeft;
|
|
1062
|
-
await stage?.update({ config: cloneDeep(newNode), root: cloneDeep(root) });
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
};
|
|
1066
1033
|
const beforeRemove = async (node) => {
|
|
1067
1034
|
if (!node?.id)
|
|
1068
1035
|
return;
|
|
@@ -1101,6 +1068,18 @@ const beforeRemove = async (node) => {
|
|
|
1101
1068
|
}
|
|
1102
1069
|
return parent;
|
|
1103
1070
|
};
|
|
1071
|
+
const getAddParent = (addNode) => {
|
|
1072
|
+
const curNode = editorService.get("node");
|
|
1073
|
+
let parentNode;
|
|
1074
|
+
if (!Array.isArray(addNode) && isPage(addNode)) {
|
|
1075
|
+
parentNode = editorService.get("root");
|
|
1076
|
+
} else if (curNode.items) {
|
|
1077
|
+
parentNode = curNode;
|
|
1078
|
+
} else {
|
|
1079
|
+
parentNode = editorService.getParentById(curNode.id, false);
|
|
1080
|
+
}
|
|
1081
|
+
return parentNode;
|
|
1082
|
+
};
|
|
1104
1083
|
|
|
1105
1084
|
class Editor$1 extends BaseService {
|
|
1106
1085
|
state = reactive({
|
|
@@ -1119,6 +1098,7 @@ class Editor$1 extends BaseService {
|
|
|
1119
1098
|
super([
|
|
1120
1099
|
"getLayout",
|
|
1121
1100
|
"select",
|
|
1101
|
+
"doAdd",
|
|
1122
1102
|
"add",
|
|
1123
1103
|
"remove",
|
|
1124
1104
|
"update",
|
|
@@ -1253,36 +1233,52 @@ class Editor$1 extends BaseService {
|
|
|
1253
1233
|
});
|
|
1254
1234
|
this.set("nodes", nodes);
|
|
1255
1235
|
}
|
|
1256
|
-
async
|
|
1236
|
+
async doAdd(node, parent) {
|
|
1237
|
+
const root = this.get("root");
|
|
1238
|
+
const curNode = this.get("node");
|
|
1257
1239
|
const stage = this.get("stage");
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
this.
|
|
1268
|
-
return
|
|
1240
|
+
if ((parent?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && node.type !== NodeType.PAGE) {
|
|
1241
|
+
throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
|
|
1242
|
+
}
|
|
1243
|
+
const layout = await this.getLayout(toRaw(parent), node);
|
|
1244
|
+
node.style = getInitPositionStyle(node.style, layout);
|
|
1245
|
+
await stage?.add({ config: cloneDeep(node), parent: cloneDeep(parent), root: cloneDeep(root) });
|
|
1246
|
+
node.style = fixNodePosition(node, parent, stage);
|
|
1247
|
+
await stage?.update({ config: cloneDeep(node), root: cloneDeep(root) });
|
|
1248
|
+
parent?.items?.push(node);
|
|
1249
|
+
this.addModifiedNodeId(node.id);
|
|
1250
|
+
return node;
|
|
1269
1251
|
}
|
|
1270
1252
|
async add(addNode, parent) {
|
|
1271
1253
|
const stage = this.get("stage");
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
if (!
|
|
1277
|
-
|
|
1254
|
+
const parentNode = parent && typeof parent !== "function" ? parent : getAddParent(addNode);
|
|
1255
|
+
if (!parentNode)
|
|
1256
|
+
throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
|
|
1257
|
+
const addNodes = [];
|
|
1258
|
+
if (!Array.isArray(addNode)) {
|
|
1259
|
+
const { type, inputEvent, ...config } = addNode;
|
|
1260
|
+
if (!type)
|
|
1261
|
+
throw new Error("\u7EC4\u4EF6\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A");
|
|
1262
|
+
addNodes.push({ ...toRaw(await propsService.getPropsValue(type, config)) });
|
|
1263
|
+
} else {
|
|
1264
|
+
addNodes.push(...addNode);
|
|
1278
1265
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1266
|
+
const newNodes = await Promise.all(addNodes.map((node) => this.doAdd(node, parentNode)));
|
|
1267
|
+
if (newNodes.length > 1) {
|
|
1268
|
+
const newNodeIds = newNodes.map((node) => node.id);
|
|
1269
|
+
stage?.multiSelect(newNodeIds);
|
|
1270
|
+
await this.multiSelect(newNodeIds);
|
|
1281
1271
|
} else {
|
|
1282
|
-
|
|
1272
|
+
await this.select(newNodes[0]);
|
|
1273
|
+
if (isPage(newNodes[0])) {
|
|
1274
|
+
this.state.pageLength += 1;
|
|
1275
|
+
} else {
|
|
1276
|
+
stage?.select(newNodes[0].id);
|
|
1277
|
+
}
|
|
1283
1278
|
}
|
|
1284
|
-
this.
|
|
1285
|
-
|
|
1279
|
+
this.pushHistoryState();
|
|
1280
|
+
this.emit("add", newNodes);
|
|
1281
|
+
return newNodes.length > 1 ? newNodes[0] : newNodes;
|
|
1286
1282
|
}
|
|
1287
1283
|
async remove(nodeOrNodeList) {
|
|
1288
1284
|
if (Array.isArray(nodeOrNodeList)) {
|
|
@@ -1374,10 +1370,10 @@ class Editor$1 extends BaseService {
|
|
|
1374
1370
|
}
|
|
1375
1371
|
async paste(position = {}) {
|
|
1376
1372
|
const config = await storageService.getItem(COPY_STORAGE_KEY);
|
|
1377
|
-
if (!config)
|
|
1373
|
+
if (!Array.isArray(config))
|
|
1378
1374
|
return;
|
|
1379
1375
|
const pasteConfigs = await beforePaste(position, config);
|
|
1380
|
-
return
|
|
1376
|
+
return this.add(pasteConfigs);
|
|
1381
1377
|
}
|
|
1382
1378
|
async alignCenter(config) {
|
|
1383
1379
|
const parent = this.get("parent");
|
|
@@ -1440,7 +1436,7 @@ class Editor$1 extends BaseService {
|
|
|
1440
1436
|
return srcValue;
|
|
1441
1437
|
}
|
|
1442
1438
|
});
|
|
1443
|
-
newConfig.style = getInitPositionStyle(newConfig.style, layout
|
|
1439
|
+
newConfig.style = getInitPositionStyle(newConfig.style, layout);
|
|
1444
1440
|
target.items.push(newConfig);
|
|
1445
1441
|
await stage.select(targetId);
|
|
1446
1442
|
await stage.update({ config: cloneDeep(target), root });
|
|
@@ -1466,7 +1462,7 @@ class Editor$1 extends BaseService {
|
|
|
1466
1462
|
const node = toRaw(this.get("node"));
|
|
1467
1463
|
if (!node || isPage(node))
|
|
1468
1464
|
return;
|
|
1469
|
-
const { style, id } = node;
|
|
1465
|
+
const { style, id, type } = node;
|
|
1470
1466
|
if (!style || style.position !== "absolute")
|
|
1471
1467
|
return;
|
|
1472
1468
|
if (top && !isNumber(style.top))
|
|
@@ -1475,6 +1471,7 @@ class Editor$1 extends BaseService {
|
|
|
1475
1471
|
return;
|
|
1476
1472
|
this.update({
|
|
1477
1473
|
id,
|
|
1474
|
+
type,
|
|
1478
1475
|
style: {
|
|
1479
1476
|
...style,
|
|
1480
1477
|
left: Number(style.left) + left,
|
|
@@ -2039,10 +2036,12 @@ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2039
2036
|
createVNode(_component_edit)
|
|
2040
2037
|
]),
|
|
2041
2038
|
_: 1
|
|
2042
|
-
})) : typeof _ctx.icon === "string" && _ctx.icon.startsWith("http") ? (openBlock(),
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2039
|
+
})) : typeof _ctx.icon === "string" && _ctx.icon.startsWith("http") ? (openBlock(), createBlock(_component_el_icon, { key: 1 }, {
|
|
2040
|
+
default: withCtx(() => [
|
|
2041
|
+
createElementVNode("img", { src: _ctx.icon }, null, 8, _hoisted_1$8)
|
|
2042
|
+
]),
|
|
2043
|
+
_: 1
|
|
2044
|
+
})) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
|
|
2046
2045
|
key: 2,
|
|
2047
2046
|
class: normalizeClass(_ctx.icon)
|
|
2048
2047
|
}, null, 2)) : (openBlock(), createBlock(_component_el_icon, { key: 3 }, {
|
|
@@ -3705,10 +3704,6 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
3705
3704
|
},
|
|
3706
3705
|
...stageContentMenu
|
|
3707
3706
|
]);
|
|
3708
|
-
onMounted(async () => {
|
|
3709
|
-
const data = await storageService.getItem(COPY_STORAGE_KEY);
|
|
3710
|
-
canPaste.value = data !== "undefined" && !!data;
|
|
3711
|
-
});
|
|
3712
3707
|
watch(parent, async () => {
|
|
3713
3708
|
if (!parent.value || !editorService)
|
|
3714
3709
|
return canCenter.value = false;
|
|
@@ -3717,8 +3712,10 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
3717
3712
|
const isTypeConform = nodes.value?.every((selectedNode) => ![NodeType.ROOT, NodeType.PAGE, "pop"].includes(`${selectedNode?.type}`));
|
|
3718
3713
|
canCenter.value = isLayoutConform && !!isTypeConform;
|
|
3719
3714
|
}, { immediate: true });
|
|
3720
|
-
const show = (e) => {
|
|
3715
|
+
const show = async (e) => {
|
|
3721
3716
|
menu.value?.show(e);
|
|
3717
|
+
const data = await storageService.getItem(COPY_STORAGE_KEY);
|
|
3718
|
+
canPaste.value = data !== "undefined" && !!data;
|
|
3722
3719
|
};
|
|
3723
3720
|
expose({ show });
|
|
3724
3721
|
return (_ctx, _cache) => {
|
|
@@ -3966,7 +3963,7 @@ const _sfc_main$1 = defineComponent({
|
|
|
3966
3963
|
nodes.value && services?.editorService.copy(nodes.value);
|
|
3967
3964
|
}).keydown([ctrl, "v"], (e) => {
|
|
3968
3965
|
e.inputEvent.preventDefault();
|
|
3969
|
-
nodes.value && services?.editorService.paste();
|
|
3966
|
+
nodes.value && services?.editorService.paste({ offsetX: 10, offsetY: 10 });
|
|
3970
3967
|
}).keydown([ctrl, "x"], (e) => {
|
|
3971
3968
|
e.inputEvent.preventDefault();
|
|
3972
3969
|
if (!nodes.value || isPage(nodes.value[0]))
|
|
@@ -4424,5 +4421,5 @@ const index = {
|
|
|
4424
4421
|
}
|
|
4425
4422
|
};
|
|
4426
4423
|
|
|
4427
|
-
export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$f as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, warn };
|
|
4424
|
+
export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$f as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, warn };
|
|
4428
4425
|
//# sourceMappingURL=tmagic-editor.mjs.map
|