@tmagic/editor 1.0.0-beta.6 → 1.0.0-beta.9
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/LICENSE +5432 -0
- package/dist/style.css +34 -10
- package/dist/tmagic-editor.es.js +161 -77
- package/dist/tmagic-editor.es.js.map +1 -1
- package/dist/tmagic-editor.umd.js +163 -80
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +8 -2
- package/dist/types/src/layouts/workspace/Stage.vue.d.ts +2 -1
- package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +1 -0
- package/dist/types/src/services/editor.d.ts +11 -4
- package/dist/types/src/type.d.ts +1 -0
- package/dist/types/src/utils/editor.d.ts +1 -1
- package/package.json +9 -8
- package/src/components/ToolButton.vue +3 -1
- package/src/layouts/AddPageBox.vue +3 -1
- package/src/layouts/PropsPanel.vue +1 -0
- package/src/layouts/sidebar/LayerPanel.vue +55 -11
- package/src/layouts/workspace/PageBar.vue +9 -4
- package/src/layouts/workspace/Stage.vue +18 -2
- package/src/layouts/workspace/ViewerMenu.vue +5 -3
- package/src/layouts/workspace/Workspace.vue +5 -0
- package/src/services/editor.ts +56 -30
- package/src/theme/common/var.scss +2 -2
- package/src/theme/layer-panel.scss +9 -0
- package/src/theme/page-bar.scss +8 -0
- package/src/theme/props-panel.scss +14 -0
- package/src/type.ts +1 -0
- package/src/utils/editor.ts +4 -3
package/dist/tmagic-editor.es.js
CHANGED
|
@@ -2,7 +2,8 @@ import { defineComponent, computed, resolveComponent, openBlock, createBlock, no
|
|
|
2
2
|
import serialize from 'serialize-javascript';
|
|
3
3
|
import * as monaco from 'monaco-editor';
|
|
4
4
|
import { Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Delete, Files, Coin, CaretBottom } from '@element-plus/icons';
|
|
5
|
-
import {
|
|
5
|
+
import { NodeType } from '@tmagic/schema';
|
|
6
|
+
import { cloneDeep, random, mergeWith, throttle } from 'lodash-es';
|
|
6
7
|
import { toLine, isPop, getNodePath } from '@tmagic/utils';
|
|
7
8
|
import { EventEmitter as EventEmitter$2 } from 'events';
|
|
8
9
|
import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
|
|
@@ -175,12 +176,12 @@ const _sfc_main$i = defineComponent({
|
|
|
175
176
|
};
|
|
176
177
|
}
|
|
177
178
|
});
|
|
178
|
-
const _hoisted_1$
|
|
179
|
+
const _hoisted_1$e = /* @__PURE__ */ createElementVNode("i", {
|
|
179
180
|
class: "el-icon-delete",
|
|
180
181
|
style: { "color": "rgb(221, 75, 57)" }
|
|
181
182
|
}, "\u53D6\u6D88", -1);
|
|
182
183
|
const _hoisted_2$7 = [
|
|
183
|
-
_hoisted_1$
|
|
184
|
+
_hoisted_1$e
|
|
184
185
|
];
|
|
185
186
|
const _hoisted_3$5 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-thumb" }, null, -1);
|
|
186
187
|
function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
|
|
@@ -324,12 +325,12 @@ const _sfc_main$h = defineComponent({
|
|
|
324
325
|
};
|
|
325
326
|
}
|
|
326
327
|
});
|
|
327
|
-
const _hoisted_1$
|
|
328
|
+
const _hoisted_1$d = {
|
|
328
329
|
ref: "codeEditor",
|
|
329
330
|
class: "magic-code-editor"
|
|
330
331
|
};
|
|
331
332
|
function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
|
|
332
|
-
return openBlock(), createElementBlock("div", _hoisted_1$
|
|
333
|
+
return openBlock(), createElementBlock("div", _hoisted_1$d, null, 512);
|
|
333
334
|
}
|
|
334
335
|
var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
|
|
335
336
|
|
|
@@ -613,7 +614,7 @@ const COPY_STORAGE_KEY = "$MagicEditorCopyData";
|
|
|
613
614
|
const generateId = (type) => `${type}_${random(1e4, false)}`;
|
|
614
615
|
const getPageList = (app) => {
|
|
615
616
|
if (app.items && Array.isArray(app.items)) {
|
|
616
|
-
return app.items.filter((item) => item.type ===
|
|
617
|
+
return app.items.filter((item) => item.type === NodeType.PAGE);
|
|
617
618
|
}
|
|
618
619
|
return [];
|
|
619
620
|
};
|
|
@@ -649,7 +650,7 @@ const setNewItemId = (config, parent) => {
|
|
|
649
650
|
const oldId = config.id;
|
|
650
651
|
config.id = generateId(config.type);
|
|
651
652
|
config.name = `${config.name?.replace(/_(\d+)$/, "")}_${config.id}`;
|
|
652
|
-
if (isPop(config) && parent?.type ===
|
|
653
|
+
if (isPop(config) && parent?.type === NodeType.PAGE) {
|
|
653
654
|
updatePopId(oldId, config.id, parent);
|
|
654
655
|
}
|
|
655
656
|
if (config.items && Array.isArray(config.items)) {
|
|
@@ -762,6 +763,7 @@ class Editor$1 extends BaseService {
|
|
|
762
763
|
parent: null,
|
|
763
764
|
node: null,
|
|
764
765
|
stage: null,
|
|
766
|
+
highlightNode: null,
|
|
765
767
|
modifiedNodeIds: /* @__PURE__ */ new Map()
|
|
766
768
|
});
|
|
767
769
|
constructor() {
|
|
@@ -777,7 +779,8 @@ class Editor$1 extends BaseService {
|
|
|
777
779
|
"alignCenter",
|
|
778
780
|
"moveLayer",
|
|
779
781
|
"undo",
|
|
780
|
-
"redo"
|
|
782
|
+
"redo",
|
|
783
|
+
"highlight"
|
|
781
784
|
]);
|
|
782
785
|
}
|
|
783
786
|
set(name, value) {
|
|
@@ -804,7 +807,7 @@ class Editor$1 extends BaseService {
|
|
|
804
807
|
info.node = path[path.length - 1];
|
|
805
808
|
info.parent = path[path.length - 2];
|
|
806
809
|
path.forEach((item) => {
|
|
807
|
-
if (item.type ===
|
|
810
|
+
if (item.type === NodeType.PAGE) {
|
|
808
811
|
info.page = item;
|
|
809
812
|
return;
|
|
810
813
|
}
|
|
@@ -831,21 +834,7 @@ class Editor$1 extends BaseService {
|
|
|
831
834
|
return Layout.ABSOLUTE;
|
|
832
835
|
}
|
|
833
836
|
async select(config2) {
|
|
834
|
-
|
|
835
|
-
if (typeof config2 === "string" || typeof config2 === "number") {
|
|
836
|
-
id = config2;
|
|
837
|
-
} else {
|
|
838
|
-
id = config2.id;
|
|
839
|
-
}
|
|
840
|
-
if (!id) {
|
|
841
|
-
throw new Error("\u6CA1\u6709ID\uFF0C\u65E0\u6CD5\u9009\u4E2D");
|
|
842
|
-
}
|
|
843
|
-
const { node, parent, page } = this.getNodeInfo(id);
|
|
844
|
-
if (!node)
|
|
845
|
-
throw new Error("\u83B7\u53D6\u4E0D\u5230\u7EC4\u4EF6\u4FE1\u606F");
|
|
846
|
-
if (node.id === this.state.root?.id) {
|
|
847
|
-
throw new Error("\u4E0D\u80FD\u9009\u6839\u8282\u70B9");
|
|
848
|
-
}
|
|
837
|
+
const { node, page, parent } = this.selectedConfigExceptionHandler(config2);
|
|
849
838
|
this.set("node", node);
|
|
850
839
|
this.set("page", page || null);
|
|
851
840
|
this.set("parent", parent || null);
|
|
@@ -856,10 +845,17 @@ class Editor$1 extends BaseService {
|
|
|
856
845
|
}
|
|
857
846
|
return node;
|
|
858
847
|
}
|
|
848
|
+
highlight(config2) {
|
|
849
|
+
const { node } = this.selectedConfigExceptionHandler(config2);
|
|
850
|
+
const currentHighligtNode = this.get("highlightNode");
|
|
851
|
+
if (currentHighligtNode === node)
|
|
852
|
+
return;
|
|
853
|
+
this.set("highlightNode", node);
|
|
854
|
+
}
|
|
859
855
|
async add({ type, ...config2 }, parent) {
|
|
860
856
|
const curNode = this.get("node");
|
|
861
857
|
let parentNode;
|
|
862
|
-
if (type ===
|
|
858
|
+
if (type === NodeType.PAGE) {
|
|
863
859
|
parentNode = this.get("root");
|
|
864
860
|
} else if (parent && typeof parent !== "function") {
|
|
865
861
|
parentNode = parent;
|
|
@@ -872,14 +868,16 @@ class Editor$1 extends BaseService {
|
|
|
872
868
|
throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
|
|
873
869
|
const layout = await this.getLayout(parentNode);
|
|
874
870
|
const newNode = initPosition({ ...toRaw(await propsService.getPropsValue(type)), ...config2 }, layout);
|
|
875
|
-
if ((parentNode?.type ===
|
|
871
|
+
if ((parentNode?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && newNode.type !== NodeType.PAGE) {
|
|
876
872
|
throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
|
|
877
873
|
}
|
|
878
874
|
parentNode?.items?.push(newNode);
|
|
879
875
|
await this.get("stage")?.add({ config: cloneDeep(newNode), root: cloneDeep(this.get("root")) });
|
|
880
876
|
await this.select(newNode);
|
|
881
877
|
this.addModifiedNodeId(newNode.id);
|
|
882
|
-
|
|
878
|
+
if (type !== NodeType.PAGE) {
|
|
879
|
+
this.pushHistoryState();
|
|
880
|
+
}
|
|
883
881
|
return newNode;
|
|
884
882
|
}
|
|
885
883
|
async remove(node) {
|
|
@@ -896,7 +894,7 @@ class Editor$1 extends BaseService {
|
|
|
896
894
|
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
897
895
|
parent.items?.splice(index, 1);
|
|
898
896
|
this.get("stage")?.remove({ id: node.id, root: this.get("root") });
|
|
899
|
-
if (node.type ===
|
|
897
|
+
if (node.type === NodeType.PAGE) {
|
|
900
898
|
await this.select(root.items[0] || root);
|
|
901
899
|
} else {
|
|
902
900
|
await this.select(parent);
|
|
@@ -913,14 +911,14 @@ class Editor$1 extends BaseService {
|
|
|
913
911
|
throw new Error(`\u83B7\u53D6\u4E0D\u5230id\u4E3A${config2.id}\u7684\u8282\u70B9`);
|
|
914
912
|
const node = cloneDeep(toRaw(info.node));
|
|
915
913
|
let newConfig = await this.toggleFixedPosition(toRaw(config2), node, this.get("root"));
|
|
916
|
-
newConfig = mergeWith(node, newConfig, (objValue, srcValue) => {
|
|
914
|
+
newConfig = mergeWith(cloneDeep(node), newConfig, (objValue, srcValue) => {
|
|
917
915
|
if (Array.isArray(srcValue)) {
|
|
918
916
|
return srcValue;
|
|
919
917
|
}
|
|
920
918
|
});
|
|
921
919
|
if (!newConfig.type)
|
|
922
920
|
throw new Error("\u914D\u7F6E\u7F3A\u5C11type\u503C");
|
|
923
|
-
if (newConfig.type ===
|
|
921
|
+
if (newConfig.type === NodeType.ROOT) {
|
|
924
922
|
this.set("root", newConfig);
|
|
925
923
|
return newConfig;
|
|
926
924
|
}
|
|
@@ -941,7 +939,7 @@ class Editor$1 extends BaseService {
|
|
|
941
939
|
this.set("node", newConfig);
|
|
942
940
|
}
|
|
943
941
|
this.get("stage")?.update({ config: cloneDeep(newConfig), root: this.get("root") });
|
|
944
|
-
if (newConfig.type ===
|
|
942
|
+
if (newConfig.type === NodeType.PAGE) {
|
|
945
943
|
this.set("page", newConfig);
|
|
946
944
|
}
|
|
947
945
|
this.addModifiedNodeId(newConfig.id);
|
|
@@ -958,6 +956,7 @@ class Editor$1 extends BaseService {
|
|
|
958
956
|
parent.items.splice(index2, 0, ...parent.items.splice(index1, 1));
|
|
959
957
|
await this.update(parent);
|
|
960
958
|
await this.select(node);
|
|
959
|
+
this.get("stage")?.update({ config: cloneDeep(node), root: this.get("root") });
|
|
961
960
|
this.addModifiedNodeId(parent.id);
|
|
962
961
|
this.pushHistoryState();
|
|
963
962
|
}
|
|
@@ -1070,6 +1069,28 @@ class Editor$1 extends BaseService {
|
|
|
1070
1069
|
}
|
|
1071
1070
|
return newConfig;
|
|
1072
1071
|
}
|
|
1072
|
+
selectedConfigExceptionHandler(config2) {
|
|
1073
|
+
let id;
|
|
1074
|
+
if (typeof config2 === "string" || typeof config2 === "number") {
|
|
1075
|
+
id = config2;
|
|
1076
|
+
} else {
|
|
1077
|
+
id = config2.id;
|
|
1078
|
+
}
|
|
1079
|
+
if (!id) {
|
|
1080
|
+
throw new Error("\u6CA1\u6709ID\uFF0C\u65E0\u6CD5\u9009\u4E2D");
|
|
1081
|
+
}
|
|
1082
|
+
const { node, parent, page } = this.getNodeInfo(id);
|
|
1083
|
+
if (!node)
|
|
1084
|
+
throw new Error("\u83B7\u53D6\u4E0D\u5230\u7EC4\u4EF6\u4FE1\u606F");
|
|
1085
|
+
if (node.id === this.state.root?.id) {
|
|
1086
|
+
throw new Error("\u4E0D\u80FD\u9009\u6839\u8282\u70B9");
|
|
1087
|
+
}
|
|
1088
|
+
return {
|
|
1089
|
+
node,
|
|
1090
|
+
parent,
|
|
1091
|
+
page
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1073
1094
|
}
|
|
1074
1095
|
var editorService = new Editor$1();
|
|
1075
1096
|
|
|
@@ -1304,20 +1325,20 @@ const _sfc_main$g = defineComponent({
|
|
|
1304
1325
|
if (!editorService)
|
|
1305
1326
|
return;
|
|
1306
1327
|
editorService.add({
|
|
1307
|
-
type:
|
|
1328
|
+
type: NodeType.PAGE,
|
|
1308
1329
|
name: generatePageNameByApp(toRaw(editorService.get("root")))
|
|
1309
1330
|
});
|
|
1310
1331
|
}
|
|
1311
1332
|
};
|
|
1312
1333
|
}
|
|
1313
1334
|
});
|
|
1314
|
-
const _hoisted_1$
|
|
1335
|
+
const _hoisted_1$c = { class: "m-editor-empty-panel" };
|
|
1315
1336
|
const _hoisted_2$6 = { class: "m-editor-empty-content" };
|
|
1316
1337
|
const _hoisted_3$4 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
|
|
1317
1338
|
function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
|
|
1318
1339
|
const _component_plus = resolveComponent("plus");
|
|
1319
1340
|
const _component_el_icon = resolveComponent("el-icon");
|
|
1320
|
-
return openBlock(), createElementBlock("div", _hoisted_1$
|
|
1341
|
+
return openBlock(), createElementBlock("div", _hoisted_1$c, [
|
|
1321
1342
|
createElementVNode("div", _hoisted_2$6, [
|
|
1322
1343
|
createElementVNode("div", {
|
|
1323
1344
|
class: "m-editor-empty-button",
|
|
@@ -2547,12 +2568,12 @@ const _sfc_main$f = defineComponent({
|
|
|
2547
2568
|
};
|
|
2548
2569
|
}
|
|
2549
2570
|
});
|
|
2550
|
-
const _hoisted_1$
|
|
2571
|
+
const _hoisted_1$b = {
|
|
2551
2572
|
ref: "target",
|
|
2552
2573
|
class: "m-editor-resizer"
|
|
2553
2574
|
};
|
|
2554
2575
|
function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
|
|
2555
|
-
return openBlock(), createElementBlock("span", _hoisted_1$
|
|
2576
|
+
return openBlock(), createElementBlock("span", _hoisted_1$b, [
|
|
2556
2577
|
renderSlot(_ctx.$slots, "default")
|
|
2557
2578
|
], 512);
|
|
2558
2579
|
}
|
|
@@ -2581,7 +2602,7 @@ const _sfc_main$e = defineComponent({
|
|
|
2581
2602
|
};
|
|
2582
2603
|
}
|
|
2583
2604
|
});
|
|
2584
|
-
const _hoisted_1$
|
|
2605
|
+
const _hoisted_1$a = { class: "m-editor" };
|
|
2585
2606
|
const _hoisted_2$5 = {
|
|
2586
2607
|
key: 1,
|
|
2587
2608
|
class: "m-editor-content"
|
|
@@ -2591,7 +2612,7 @@ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2591
2612
|
const _component_resizer = resolveComponent("resizer");
|
|
2592
2613
|
const _component_el_scrollbar = resolveComponent("el-scrollbar");
|
|
2593
2614
|
const _component_add_page_box = resolveComponent("add-page-box");
|
|
2594
|
-
return openBlock(), createElementBlock("div", _hoisted_1$
|
|
2615
|
+
return openBlock(), createElementBlock("div", _hoisted_1$a, [
|
|
2595
2616
|
renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
|
|
2596
2617
|
_ctx.showSrc ? (openBlock(), createBlock(_component_magic_code_editor, {
|
|
2597
2618
|
key: 0,
|
|
@@ -2647,7 +2668,7 @@ const _sfc_main$d = defineComponent({
|
|
|
2647
2668
|
};
|
|
2648
2669
|
}
|
|
2649
2670
|
});
|
|
2650
|
-
const _hoisted_1$
|
|
2671
|
+
const _hoisted_1$9 = ["src"];
|
|
2651
2672
|
function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
|
|
2652
2673
|
const _component_edit = resolveComponent("edit");
|
|
2653
2674
|
const _component_el_icon = resolveComponent("el-icon");
|
|
@@ -2659,7 +2680,7 @@ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2659
2680
|
})) : typeof _ctx.icon === "string" && _ctx.icon.startsWith("http") ? (openBlock(), createElementBlock("img", {
|
|
2660
2681
|
key: 1,
|
|
2661
2682
|
src: _ctx.icon
|
|
2662
|
-
}, null, 8, _hoisted_1$
|
|
2683
|
+
}, null, 8, _hoisted_1$9)) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
|
|
2663
2684
|
key: 2,
|
|
2664
2685
|
class: normalizeClass(_ctx.icon)
|
|
2665
2686
|
}, null, 2)) : (openBlock(), createBlock(_component_el_icon, { key: 3 }, {
|
|
@@ -2709,7 +2730,7 @@ const _sfc_main$c = defineComponent({
|
|
|
2709
2730
|
type: "button",
|
|
2710
2731
|
icon: Delete,
|
|
2711
2732
|
tooltip: "\u522A\u9664",
|
|
2712
|
-
disabled: () => services?.editorService.get("node")?.type ===
|
|
2733
|
+
disabled: () => services?.editorService.get("node")?.type === NodeType.PAGE,
|
|
2713
2734
|
handler: () => services?.editorService.remove(services?.editorService.get("node"))
|
|
2714
2735
|
};
|
|
2715
2736
|
case "undo":
|
|
@@ -2806,7 +2827,7 @@ const _sfc_main$c = defineComponent({
|
|
|
2806
2827
|
};
|
|
2807
2828
|
}
|
|
2808
2829
|
});
|
|
2809
|
-
const _hoisted_1$
|
|
2830
|
+
const _hoisted_1$8 = {
|
|
2810
2831
|
key: 0,
|
|
2811
2832
|
class: "menu-item"
|
|
2812
2833
|
};
|
|
@@ -2829,7 +2850,7 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2829
2850
|
const _component_el_dropdown_item = resolveComponent("el-dropdown-item");
|
|
2830
2851
|
const _component_el_dropdown_menu = resolveComponent("el-dropdown-menu");
|
|
2831
2852
|
const _component_el_dropdown = resolveComponent("el-dropdown");
|
|
2832
|
-
return _ctx.display ? (openBlock(), createElementBlock("div", _hoisted_1$
|
|
2853
|
+
return _ctx.display ? (openBlock(), createElementBlock("div", _hoisted_1$8, [
|
|
2833
2854
|
_ctx.item.type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
|
|
2834
2855
|
key: 0,
|
|
2835
2856
|
direction: "vertical"
|
|
@@ -3001,6 +3022,7 @@ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
3001
3022
|
const _component_m_form = resolveComponent("m-form");
|
|
3002
3023
|
return openBlock(), createBlock(_component_m_form, {
|
|
3003
3024
|
class: "m-editor-props-panel",
|
|
3025
|
+
"popper-class": "m-editor-props-panel-popper",
|
|
3004
3026
|
ref: "configForm",
|
|
3005
3027
|
size: "small",
|
|
3006
3028
|
"init-values": _ctx.values,
|
|
@@ -3035,7 +3057,7 @@ const _sfc_main$9 = defineComponent({
|
|
|
3035
3057
|
};
|
|
3036
3058
|
}
|
|
3037
3059
|
});
|
|
3038
|
-
const _hoisted_1$
|
|
3060
|
+
const _hoisted_1$7 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
|
|
3039
3061
|
const _hoisted_2$3 = ["onClick"];
|
|
3040
3062
|
function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
|
|
3041
3063
|
const _component_el_input = resolveComponent("el-input");
|
|
@@ -3067,7 +3089,7 @@ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
3067
3089
|
name: index
|
|
3068
3090
|
}, {
|
|
3069
3091
|
title: withCtx(() => [
|
|
3070
|
-
_hoisted_1$
|
|
3092
|
+
_hoisted_1$7,
|
|
3071
3093
|
createTextVNode(toDisplayString(group.title), 1)
|
|
3072
3094
|
]),
|
|
3073
3095
|
default: withCtx(() => [
|
|
@@ -3148,7 +3170,7 @@ const _sfc_main$8 = defineComponent({
|
|
|
3148
3170
|
};
|
|
3149
3171
|
}
|
|
3150
3172
|
});
|
|
3151
|
-
const _hoisted_1$
|
|
3173
|
+
const _hoisted_1$6 = {
|
|
3152
3174
|
key: 0,
|
|
3153
3175
|
class: "magic-editor-content-menu"
|
|
3154
3176
|
};
|
|
@@ -3157,7 +3179,7 @@ const _hoisted_3$2 = ["onClick"];
|
|
|
3157
3179
|
const _hoisted_4$2 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
|
|
3158
3180
|
function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
|
|
3159
3181
|
const _component_el_scrollbar = resolveComponent("el-scrollbar");
|
|
3160
|
-
return _ctx.node ? (openBlock(), createElementBlock("div", _hoisted_1$
|
|
3182
|
+
return _ctx.node ? (openBlock(), createElementBlock("div", _hoisted_1$6, [
|
|
3161
3183
|
_ctx.node.items ? (openBlock(), createElementBlock("div", {
|
|
3162
3184
|
key: 0,
|
|
3163
3185
|
class: "magic-editor-content-menu-item",
|
|
@@ -3219,20 +3241,27 @@ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
3219
3241
|
}
|
|
3220
3242
|
var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
|
|
3221
3243
|
|
|
3244
|
+
const throttleTime = 150;
|
|
3222
3245
|
const select = (data, editorService) => {
|
|
3223
3246
|
if (!data.id) {
|
|
3224
3247
|
throw new Error("\u6CA1\u6709id");
|
|
3225
3248
|
}
|
|
3226
3249
|
editorService?.select(data);
|
|
3227
3250
|
};
|
|
3251
|
+
const highlight = (data, editorService) => {
|
|
3252
|
+
if (!data?.id) {
|
|
3253
|
+
throw new Error("\u6CA1\u6709id");
|
|
3254
|
+
}
|
|
3255
|
+
editorService?.highlight(data);
|
|
3256
|
+
};
|
|
3228
3257
|
const useDrop = (tree, editorService) => ({
|
|
3229
3258
|
allowDrop: (draggingNode, dropNode, type) => {
|
|
3230
3259
|
const { data } = dropNode || {};
|
|
3231
3260
|
const { data: ingData } = draggingNode;
|
|
3232
3261
|
const { type: ingType } = ingData;
|
|
3233
|
-
if (ingType !==
|
|
3262
|
+
if (ingType !== NodeType.PAGE && data.type === NodeType.PAGE)
|
|
3234
3263
|
return false;
|
|
3235
|
-
if (ingType ===
|
|
3264
|
+
if (ingType === NodeType.PAGE && data.type !== NodeType.PAGE)
|
|
3236
3265
|
return false;
|
|
3237
3266
|
if (!data || !data.type)
|
|
3238
3267
|
return false;
|
|
@@ -3251,29 +3280,34 @@ const useDrop = (tree, editorService) => ({
|
|
|
3251
3280
|
}
|
|
3252
3281
|
});
|
|
3253
3282
|
const useStatus = (tree, editorService) => {
|
|
3283
|
+
const highlightNode = ref();
|
|
3284
|
+
const node = ref();
|
|
3254
3285
|
const page = computed(() => editorService?.get("page"));
|
|
3255
3286
|
watchEffect(() => {
|
|
3256
3287
|
if (!tree.value)
|
|
3257
3288
|
return;
|
|
3258
|
-
|
|
3259
|
-
node && tree.value.setCurrentKey(node.id, true);
|
|
3289
|
+
node.value = editorService?.get("node");
|
|
3290
|
+
node.value && tree.value.setCurrentKey(node.value.id, true);
|
|
3260
3291
|
const parent = editorService?.get("parent");
|
|
3261
3292
|
if (!parent?.id)
|
|
3262
3293
|
return;
|
|
3263
3294
|
const treeNode = tree.value.getNode(parent.id);
|
|
3264
3295
|
treeNode?.updateChildren();
|
|
3296
|
+
highlightNode.value = editorService?.get("highlightNode");
|
|
3265
3297
|
});
|
|
3266
3298
|
return {
|
|
3267
3299
|
values: computed(() => page.value ? [page.value] : []),
|
|
3268
|
-
loadItems: (
|
|
3269
|
-
if (Array.isArray(
|
|
3270
|
-
return resolve(
|
|
3300
|
+
loadItems: (node2, resolve) => {
|
|
3301
|
+
if (Array.isArray(node2.data)) {
|
|
3302
|
+
return resolve(node2.data);
|
|
3271
3303
|
}
|
|
3272
|
-
if (Array.isArray(
|
|
3273
|
-
return resolve(
|
|
3304
|
+
if (Array.isArray(node2.data?.items)) {
|
|
3305
|
+
return resolve(node2.data?.items);
|
|
3274
3306
|
}
|
|
3275
3307
|
resolve([]);
|
|
3276
|
-
}
|
|
3308
|
+
},
|
|
3309
|
+
highlightNode,
|
|
3310
|
+
clickNode: node
|
|
3277
3311
|
};
|
|
3278
3312
|
};
|
|
3279
3313
|
const useFilter = (tree) => ({
|
|
@@ -3330,11 +3364,20 @@ const _sfc_main$7 = defineComponent({
|
|
|
3330
3364
|
setup() {
|
|
3331
3365
|
const services = inject("services");
|
|
3332
3366
|
const tree = ref();
|
|
3367
|
+
const clicked = ref(false);
|
|
3333
3368
|
const editorService = services?.editorService;
|
|
3369
|
+
const highlightHandler = throttle((data) => {
|
|
3370
|
+
highlight(data, editorService);
|
|
3371
|
+
}, throttleTime);
|
|
3372
|
+
const toogleClickFlag = () => {
|
|
3373
|
+
clicked.value = !clicked.value;
|
|
3374
|
+
};
|
|
3375
|
+
const statusData = useStatus(tree, editorService);
|
|
3376
|
+
const canHighlight = computed(() => statusData.highlightNode.value?.id !== statusData.clickNode.value?.id && !clicked.value);
|
|
3334
3377
|
return {
|
|
3335
3378
|
tree,
|
|
3379
|
+
...statusData,
|
|
3336
3380
|
...useDrop(tree, editorService),
|
|
3337
|
-
...useStatus(tree, editorService),
|
|
3338
3381
|
...useFilter(tree),
|
|
3339
3382
|
...useContentMenu(editorService),
|
|
3340
3383
|
clickHandler(data) {
|
|
@@ -3342,11 +3385,16 @@ const _sfc_main$7 = defineComponent({
|
|
|
3342
3385
|
document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
|
|
3343
3386
|
return;
|
|
3344
3387
|
}
|
|
3388
|
+
tree.value?.setCurrentKey(data.id);
|
|
3345
3389
|
select(data, editorService);
|
|
3346
|
-
}
|
|
3390
|
+
},
|
|
3391
|
+
highlightHandler,
|
|
3392
|
+
toogleClickFlag,
|
|
3393
|
+
canHighlight
|
|
3347
3394
|
};
|
|
3348
3395
|
}
|
|
3349
3396
|
});
|
|
3397
|
+
const _hoisted_1$5 = ["id", "onMouseenter"];
|
|
3350
3398
|
function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
|
|
3351
3399
|
const _component_el_input = resolveComponent("el-input");
|
|
3352
3400
|
const _component_el_tree = resolveComponent("el-tree");
|
|
@@ -3383,12 +3431,20 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
3383
3431
|
"empty-text": "\u9875\u9762\u7A7A\u8361\u8361\u7684"
|
|
3384
3432
|
}, {
|
|
3385
3433
|
default: withCtx(({ node, data }) => [
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
data
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3434
|
+
createElementVNode("div", {
|
|
3435
|
+
id: data.id,
|
|
3436
|
+
class: normalizeClass(["cus-tree-node", { "cus-tree-node-hover": _ctx.canHighlight && data.id === _ctx.highlightNode?.id }]),
|
|
3437
|
+
onMousedown: _cache[1] || (_cache[1] = (...args) => _ctx.toogleClickFlag && _ctx.toogleClickFlag(...args)),
|
|
3438
|
+
onMouseup: _cache[2] || (_cache[2] = (...args) => _ctx.toogleClickFlag && _ctx.toogleClickFlag(...args)),
|
|
3439
|
+
onMouseenter: ($event) => _ctx.highlightHandler(data)
|
|
3440
|
+
}, [
|
|
3441
|
+
renderSlot(_ctx.$slots, "layer-node-content", {
|
|
3442
|
+
node,
|
|
3443
|
+
data
|
|
3444
|
+
}, () => [
|
|
3445
|
+
createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
|
|
3446
|
+
])
|
|
3447
|
+
], 42, _hoisted_1$5)
|
|
3392
3448
|
]),
|
|
3393
3449
|
_: 3
|
|
3394
3450
|
}, 8, ["load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd"])) : createCommentVNode("", true),
|
|
@@ -3515,7 +3571,7 @@ const _sfc_main$5 = defineComponent({
|
|
|
3515
3571
|
if (!editorService)
|
|
3516
3572
|
return;
|
|
3517
3573
|
const pageConfig = {
|
|
3518
|
-
type:
|
|
3574
|
+
type: NodeType.PAGE,
|
|
3519
3575
|
name: generatePageNameByApp(toRaw(editorService.get("root")))
|
|
3520
3576
|
};
|
|
3521
3577
|
editorService.add(pageConfig);
|
|
@@ -3535,11 +3591,13 @@ const _sfc_main$5 = defineComponent({
|
|
|
3535
3591
|
});
|
|
3536
3592
|
const _hoisted_1$3 = { class: "m-editor-page-bar" };
|
|
3537
3593
|
const _hoisted_2$1 = ["onClick"];
|
|
3538
|
-
const _hoisted_3$1 =
|
|
3594
|
+
const _hoisted_3$1 = { class: "m-editor-page-bar-title" };
|
|
3539
3595
|
const _hoisted_4$1 = ["onClick"];
|
|
3596
|
+
const _hoisted_5 = ["onClick"];
|
|
3540
3597
|
function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
|
|
3541
3598
|
const _component_plus = resolveComponent("plus");
|
|
3542
3599
|
const _component_el_icon = resolveComponent("el-icon");
|
|
3600
|
+
const _component_el_tooltip = resolveComponent("el-tooltip");
|
|
3543
3601
|
const _component_caret_bottom = resolveComponent("caret-bottom");
|
|
3544
3602
|
const _component_el_popover = resolveComponent("el-popover");
|
|
3545
3603
|
return openBlock(), createElementBlock("div", _hoisted_1$3, [
|
|
@@ -3560,8 +3618,19 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
3560
3618
|
class: normalizeClass(["m-editor-page-bar-item", { active: _ctx.page?.id === item.id }]),
|
|
3561
3619
|
onClick: ($event) => _ctx.switchPage(item)
|
|
3562
3620
|
}, [
|
|
3563
|
-
|
|
3564
|
-
|
|
3621
|
+
createElementVNode("div", _hoisted_3$1, [
|
|
3622
|
+
renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
|
|
3623
|
+
createVNode(_component_el_tooltip, {
|
|
3624
|
+
effect: "dark",
|
|
3625
|
+
placement: "top-start",
|
|
3626
|
+
content: item.name
|
|
3627
|
+
}, {
|
|
3628
|
+
default: withCtx(() => [
|
|
3629
|
+
createElementVNode("span", null, toDisplayString(item.name), 1)
|
|
3630
|
+
]),
|
|
3631
|
+
_: 2
|
|
3632
|
+
}, 1032, ["content"])
|
|
3633
|
+
])
|
|
3565
3634
|
]),
|
|
3566
3635
|
createVNode(_component_el_popover, {
|
|
3567
3636
|
placement: "top",
|
|
@@ -3582,11 +3651,11 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
3582
3651
|
createElementVNode("div", {
|
|
3583
3652
|
class: "magic-editor-content-menu-item",
|
|
3584
3653
|
onClick: () => _ctx.copy(item)
|
|
3585
|
-
}, "\u590D\u5236", 8,
|
|
3654
|
+
}, "\u590D\u5236", 8, _hoisted_4$1),
|
|
3586
3655
|
createElementVNode("div", {
|
|
3587
3656
|
class: "magic-editor-content-menu-item",
|
|
3588
3657
|
onClick: () => _ctx.remove(item)
|
|
3589
|
-
}, "\u5220\u9664", 8,
|
|
3658
|
+
}, "\u5220\u9664", 8, _hoisted_5)
|
|
3590
3659
|
])
|
|
3591
3660
|
])
|
|
3592
3661
|
]),
|
|
@@ -3835,13 +3904,13 @@ const _sfc_main$3 = defineComponent({
|
|
|
3835
3904
|
if (!parent.value || !editorService)
|
|
3836
3905
|
return canCenter.value = false;
|
|
3837
3906
|
const layout = await editorService.getLayout(parent.value);
|
|
3838
|
-
canCenter.value = [Layout.ABSOLUTE, Layout.FIXED].includes(layout) && ![
|
|
3907
|
+
canCenter.value = [Layout.ABSOLUTE, Layout.FIXED].includes(layout) && ![NodeType.ROOT, NodeType.PAGE, "pop"].includes(`${node.value?.type}`);
|
|
3839
3908
|
}, { immediate: true });
|
|
3840
3909
|
return {
|
|
3841
3910
|
menu,
|
|
3842
3911
|
canPaste,
|
|
3843
|
-
canDelete: computed(() => node.value?.type !==
|
|
3844
|
-
canMoveZPos: computed(() => node.value?.type !==
|
|
3912
|
+
canDelete: computed(() => node.value?.type !== NodeType.PAGE),
|
|
3913
|
+
canMoveZPos: computed(() => node.value?.type !== NodeType.PAGE),
|
|
3845
3914
|
canCenter,
|
|
3846
3915
|
center() {
|
|
3847
3916
|
node.value && editorService?.alignCenter(node.value);
|
|
@@ -3988,7 +4057,7 @@ const _sfc_main$2 = defineComponent({
|
|
|
3988
4057
|
})
|
|
3989
4058
|
}
|
|
3990
4059
|
},
|
|
3991
|
-
emits: ["select", "update", "sort"],
|
|
4060
|
+
emits: ["select", "update", "sort", "highlight"],
|
|
3992
4061
|
setup(props, { emit }) {
|
|
3993
4062
|
const services = inject("services");
|
|
3994
4063
|
const stageWrap = ref();
|
|
@@ -3999,6 +4068,7 @@ const _sfc_main$2 = defineComponent({
|
|
|
3999
4068
|
const page = computed(() => services?.editorService.get("page"));
|
|
4000
4069
|
const zoom = computed(() => services?.uiService.get("zoom"));
|
|
4001
4070
|
const node = computed(() => services?.editorService.get("node"));
|
|
4071
|
+
const highlightNode = computed(() => services?.editorService.get("highlightNode"));
|
|
4002
4072
|
let stage = null;
|
|
4003
4073
|
let runtime = null;
|
|
4004
4074
|
watchEffect(() => {
|
|
@@ -4024,7 +4094,12 @@ const _sfc_main$2 = defineComponent({
|
|
|
4024
4094
|
});
|
|
4025
4095
|
services?.editorService.set("stage", stage);
|
|
4026
4096
|
stage?.mount(stageContainer.value);
|
|
4027
|
-
stage?.on("select", (el) =>
|
|
4097
|
+
stage?.on("select", (el) => {
|
|
4098
|
+
emit("select", el);
|
|
4099
|
+
});
|
|
4100
|
+
stage?.on("highlight", (el) => {
|
|
4101
|
+
emit("highlight", el);
|
|
4102
|
+
});
|
|
4028
4103
|
stage?.on("update", (ev) => {
|
|
4029
4104
|
emit("update", { id: ev.el.id, style: ev.style });
|
|
4030
4105
|
});
|
|
@@ -4060,6 +4135,11 @@ const _sfc_main$2 = defineComponent({
|
|
|
4060
4135
|
id && stage?.select(id);
|
|
4061
4136
|
});
|
|
4062
4137
|
});
|
|
4138
|
+
watch(() => highlightNode.value?.id, (id) => {
|
|
4139
|
+
nextTick(() => {
|
|
4140
|
+
id && stage?.highlight(id);
|
|
4141
|
+
});
|
|
4142
|
+
});
|
|
4063
4143
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
4064
4144
|
for (const { contentRect } of entries) {
|
|
4065
4145
|
services?.uiService.set("stageContainerRect", {
|
|
@@ -4144,6 +4224,9 @@ const _sfc_main$1 = defineComponent({
|
|
|
4144
4224
|
},
|
|
4145
4225
|
sortNodeHandler(ev) {
|
|
4146
4226
|
services?.editorService.sort(ev.src, ev.dist);
|
|
4227
|
+
},
|
|
4228
|
+
highlightHandler(el) {
|
|
4229
|
+
services?.editorService.highlight(el.id);
|
|
4147
4230
|
}
|
|
4148
4231
|
};
|
|
4149
4232
|
}
|
|
@@ -4160,9 +4243,10 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
4160
4243
|
"moveable-options": _ctx.moveableOptions,
|
|
4161
4244
|
"can-select": _ctx.canSelect,
|
|
4162
4245
|
onSelect: _ctx.selectHandler,
|
|
4246
|
+
onHighlight: _ctx.highlightHandler,
|
|
4163
4247
|
onUpdate: _ctx.updateNodeHandler,
|
|
4164
4248
|
onSort: _ctx.sortNodeHandler
|
|
4165
|
-
}, null, 8, ["runtime-url", "render", "moveable-options", "can-select", "onSelect", "onUpdate", "onSort"])),
|
|
4249
|
+
}, null, 8, ["runtime-url", "render", "moveable-options", "can-select", "onSelect", "onHighlight", "onUpdate", "onSort"])),
|
|
4166
4250
|
renderSlot(_ctx.$slots, "workspace-content"),
|
|
4167
4251
|
createVNode(_component_page_bar, null, {
|
|
4168
4252
|
"page-bar-title": withCtx(({ page }) => [
|