@tmagic/editor 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tmagic-editor.js +352 -331
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +351 -330
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +9 -9
- package/src/Editor.vue +2 -0
- package/src/layouts/sidebar/Sidebar.vue +6 -1
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +25 -13
- package/src/services/codeBlock.ts +74 -57
- package/src/services/editor.ts +1 -5
- package/src/type.ts +2 -4
- package/types/services/codeBlock.d.ts +18 -17
- package/types/type.d.ts +2 -4
package/dist/tmagic-editor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, withCtx, createVNode, createElementVNode, createElementBlock, normalizeClass, resolveDynamicComponent, toRaw, inject, createCommentVNode, ref, withModifiers, createTextVNode, toDisplayString, onMounted, onUnmounted, renderSlot, Fragment, createSlots, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, watchEffect, provide, withDirectives, Teleport, vShow, nextTick, toHandlers } from 'vue';
|
|
2
2
|
import serialize from 'serialize-javascript';
|
|
3
3
|
import { Edit, View, Delete, Close, Plus, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Link, Search, Files, CopyDocument, Coin, EditPen, ArrowLeftBold, ArrowRightBold, CaretBottom, DocumentCopy, Top, Bottom } from '@element-plus/icons-vue';
|
|
4
|
-
import { isEmpty, map, throttle,
|
|
4
|
+
import { isEmpty, map, throttle, cloneDeep, mergeWith, isObject, uniq, forIn, difference, union, pick, omit, keys } from 'lodash-es';
|
|
5
5
|
import { createValues, MForm } from '@tmagic/form';
|
|
6
6
|
import { HookType, NodeType } from '@tmagic/schema';
|
|
7
7
|
import { TMagicIcon, TMagicButton, TMagicTooltip, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, tMagicMessage, tMagicMessageBox, TMagicCard, TMagicInput, TMagicDialog, TMagicTree, TMagicCollapse, TMagicCollapseItem, getConfig as getConfig$1, TMagicTabs, TMagicPopover } from '@tmagic/design';
|
|
@@ -704,62 +704,51 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
|
|
|
704
704
|
}
|
|
705
705
|
});
|
|
706
706
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
return LayerOffset2;
|
|
717
|
-
})(LayerOffset || {});
|
|
718
|
-
var Layout = /* @__PURE__ */ ((Layout2) => {
|
|
719
|
-
Layout2["FLEX"] = "flex";
|
|
720
|
-
Layout2["FIXED"] = "fixed";
|
|
721
|
-
Layout2["RELATIVE"] = "relative";
|
|
722
|
-
Layout2["ABSOLUTE"] = "absolute";
|
|
723
|
-
return Layout2;
|
|
724
|
-
})(Layout || {});
|
|
725
|
-
var Keys = /* @__PURE__ */ ((Keys2) => {
|
|
726
|
-
Keys2["ESCAPE"] = "Space";
|
|
727
|
-
return Keys2;
|
|
728
|
-
})(Keys || {});
|
|
729
|
-
const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
|
|
730
|
-
const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
|
|
731
|
-
var CodeDeleteErrorType = /* @__PURE__ */ ((CodeDeleteErrorType2) => {
|
|
732
|
-
CodeDeleteErrorType2["UNDELETEABLE"] = "undeleteable";
|
|
733
|
-
CodeDeleteErrorType2["BIND"] = "bind";
|
|
734
|
-
return CodeDeleteErrorType2;
|
|
735
|
-
})(CodeDeleteErrorType || {});
|
|
736
|
-
const CODE_DRAFT_STORAGE_KEY = "magicCodeDraft";
|
|
737
|
-
|
|
738
|
-
const log = (...args) => {
|
|
739
|
-
if (process.env.NODE_ENV === "development") {
|
|
740
|
-
console.log("magic editor: ", ...args);
|
|
707
|
+
class UndoRedo {
|
|
708
|
+
elementList;
|
|
709
|
+
listCursor;
|
|
710
|
+
listMaxSize;
|
|
711
|
+
constructor(listMaxSize = 200) {
|
|
712
|
+
const minListMaxSize = 2;
|
|
713
|
+
this.elementList = [];
|
|
714
|
+
this.listCursor = 0;
|
|
715
|
+
this.listMaxSize = listMaxSize > minListMaxSize ? listMaxSize : minListMaxSize;
|
|
741
716
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
717
|
+
pushElement(element) {
|
|
718
|
+
this.elementList.splice(this.listCursor, this.elementList.length - this.listCursor, cloneDeep(element));
|
|
719
|
+
this.listCursor += 1;
|
|
720
|
+
if (this.elementList.length > this.listMaxSize) {
|
|
721
|
+
this.elementList.shift();
|
|
722
|
+
this.listCursor -= 1;
|
|
723
|
+
}
|
|
746
724
|
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
if (process.env.NODE_ENV === "development") {
|
|
750
|
-
console.warn("magic editor: ", ...args);
|
|
725
|
+
canUndo() {
|
|
726
|
+
return this.listCursor > 1;
|
|
751
727
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
728
|
+
undo() {
|
|
729
|
+
if (!this.canUndo()) {
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
this.listCursor -= 1;
|
|
733
|
+
return this.getCurrentElement();
|
|
756
734
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (process.env.NODE_ENV === "development") {
|
|
760
|
-
console.error("magic editor: ", ...args);
|
|
735
|
+
canRedo() {
|
|
736
|
+
return this.elementList.length > this.listCursor;
|
|
761
737
|
}
|
|
762
|
-
|
|
738
|
+
redo() {
|
|
739
|
+
if (!this.canRedo()) {
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
this.listCursor += 1;
|
|
743
|
+
return this.getCurrentElement();
|
|
744
|
+
}
|
|
745
|
+
getCurrentElement() {
|
|
746
|
+
if (this.listCursor < 1) {
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
749
|
+
return cloneDeep(this.elementList[this.listCursor - 1]);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
763
752
|
|
|
764
753
|
const compose = (middleware) => {
|
|
765
754
|
if (!Array.isArray(middleware))
|
|
@@ -883,272 +872,6 @@ class BaseService extends EventEmitter {
|
|
|
883
872
|
}
|
|
884
873
|
}
|
|
885
874
|
|
|
886
|
-
class CodeBlock extends BaseService {
|
|
887
|
-
state = reactive({
|
|
888
|
-
isShowCodeEditor: false,
|
|
889
|
-
codeDsl: null,
|
|
890
|
-
id: "",
|
|
891
|
-
editable: true,
|
|
892
|
-
combineIds: [],
|
|
893
|
-
undeletableList: [],
|
|
894
|
-
relations: {}
|
|
895
|
-
});
|
|
896
|
-
constructor() {
|
|
897
|
-
super([
|
|
898
|
-
"setCodeDsl",
|
|
899
|
-
"getCodeDsl",
|
|
900
|
-
"getCodeContentById",
|
|
901
|
-
"getCodeDslByIds",
|
|
902
|
-
"getCurrentDsl",
|
|
903
|
-
"setCodeDslById",
|
|
904
|
-
"setCodeEditorShowStatus",
|
|
905
|
-
"setEditStatus",
|
|
906
|
-
"setCombineIds",
|
|
907
|
-
"setUndeleteableList",
|
|
908
|
-
"deleteCodeDslByIds"
|
|
909
|
-
]);
|
|
910
|
-
}
|
|
911
|
-
async setCodeDsl(codeDsl2) {
|
|
912
|
-
this.state.codeDsl = codeDsl2;
|
|
913
|
-
await editorService.setCodeDsl(this.state.codeDsl);
|
|
914
|
-
info("[code-block]:code-dsl-change", this.state.codeDsl);
|
|
915
|
-
this.emit("code-dsl-change", this.state.codeDsl);
|
|
916
|
-
}
|
|
917
|
-
async getCodeDsl(forceRefresh = false) {
|
|
918
|
-
return this.getCodeDslSync(forceRefresh);
|
|
919
|
-
}
|
|
920
|
-
getCodeDslSync(forceRefresh = false) {
|
|
921
|
-
if (!this.state.codeDsl || forceRefresh) {
|
|
922
|
-
this.state.codeDsl = editorService.getCodeDslSync();
|
|
923
|
-
}
|
|
924
|
-
return this.state.codeDsl;
|
|
925
|
-
}
|
|
926
|
-
async getCodeContentById(id2) {
|
|
927
|
-
if (!id2)
|
|
928
|
-
return null;
|
|
929
|
-
const totalCodeDsl = await this.getCodeDsl();
|
|
930
|
-
if (!totalCodeDsl)
|
|
931
|
-
return null;
|
|
932
|
-
return totalCodeDsl[id2] ?? null;
|
|
933
|
-
}
|
|
934
|
-
async setCodeDslById(id, codeConfig) {
|
|
935
|
-
let codeDsl = await this.getCodeDsl();
|
|
936
|
-
const codeConfigProcessed = codeConfig;
|
|
937
|
-
if (codeConfig.content) {
|
|
938
|
-
codeConfigProcessed.content = eval(codeConfig.content);
|
|
939
|
-
}
|
|
940
|
-
if (!codeDsl) {
|
|
941
|
-
codeDsl = {
|
|
942
|
-
[id]: {
|
|
943
|
-
...codeConfigProcessed
|
|
944
|
-
}
|
|
945
|
-
};
|
|
946
|
-
} else {
|
|
947
|
-
const existContent = codeDsl[id] || {};
|
|
948
|
-
codeDsl = {
|
|
949
|
-
...codeDsl,
|
|
950
|
-
[id]: {
|
|
951
|
-
...existContent,
|
|
952
|
-
...codeConfigProcessed
|
|
953
|
-
}
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
await this.setCodeDsl(codeDsl);
|
|
957
|
-
}
|
|
958
|
-
async getCodeDslByIds(ids) {
|
|
959
|
-
const codeDsl2 = await this.getCodeDsl();
|
|
960
|
-
return pick(codeDsl2, ids);
|
|
961
|
-
}
|
|
962
|
-
async setCodeEditorShowStatus(status) {
|
|
963
|
-
this.state.isShowCodeEditor = status;
|
|
964
|
-
}
|
|
965
|
-
getCodeEditorShowStatus() {
|
|
966
|
-
return this.state.isShowCodeEditor;
|
|
967
|
-
}
|
|
968
|
-
setCodeEditorContent(status, id2) {
|
|
969
|
-
if (!id2)
|
|
970
|
-
return;
|
|
971
|
-
this.setId(id2);
|
|
972
|
-
this.state.isShowCodeEditor = status;
|
|
973
|
-
}
|
|
974
|
-
async getCurrentDsl() {
|
|
975
|
-
return await this.getCodeContentById(this.state.id);
|
|
976
|
-
}
|
|
977
|
-
getEditStatus() {
|
|
978
|
-
return this.state.editable;
|
|
979
|
-
}
|
|
980
|
-
async setEditStatus(status) {
|
|
981
|
-
this.state.editable = status;
|
|
982
|
-
}
|
|
983
|
-
setId(id2) {
|
|
984
|
-
if (!id2)
|
|
985
|
-
return;
|
|
986
|
-
this.state.id = id2;
|
|
987
|
-
}
|
|
988
|
-
getId() {
|
|
989
|
-
return this.state.id;
|
|
990
|
-
}
|
|
991
|
-
async setCombineIds(ids) {
|
|
992
|
-
this.state.combineIds = ids;
|
|
993
|
-
}
|
|
994
|
-
getCombineIds() {
|
|
995
|
-
return this.state.combineIds;
|
|
996
|
-
}
|
|
997
|
-
refreshCombineInfo() {
|
|
998
|
-
const root = editorService.get("root");
|
|
999
|
-
if (!root)
|
|
1000
|
-
return null;
|
|
1001
|
-
const relations = {};
|
|
1002
|
-
this.recurseMNode(root, relations);
|
|
1003
|
-
this.state.relations = relations;
|
|
1004
|
-
return this.state.relations;
|
|
1005
|
-
}
|
|
1006
|
-
getCombineInfo() {
|
|
1007
|
-
return this.state.relations;
|
|
1008
|
-
}
|
|
1009
|
-
getUndeletableList() {
|
|
1010
|
-
return this.state.undeletableList;
|
|
1011
|
-
}
|
|
1012
|
-
async setUndeleteableList(codeIds) {
|
|
1013
|
-
this.state.undeletableList = codeIds;
|
|
1014
|
-
}
|
|
1015
|
-
setCodeDraft(codeId, content) {
|
|
1016
|
-
globalThis.localStorage.setItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`, content);
|
|
1017
|
-
}
|
|
1018
|
-
getCodeDraft(codeId) {
|
|
1019
|
-
return globalThis.localStorage.getItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
|
|
1020
|
-
}
|
|
1021
|
-
removeCodeDraft(codeId) {
|
|
1022
|
-
globalThis.localStorage.removeItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
|
|
1023
|
-
}
|
|
1024
|
-
async deleteCodeDslByIds(codeIds) {
|
|
1025
|
-
const currentDsl = await this.getCodeDsl();
|
|
1026
|
-
const newDsl = omit(currentDsl, codeIds);
|
|
1027
|
-
await this.setCodeDsl(newDsl);
|
|
1028
|
-
return newDsl;
|
|
1029
|
-
}
|
|
1030
|
-
async getUniqueId() {
|
|
1031
|
-
const newId = `code_${Math.random().toString(10).substring(2).substring(0, 4)}`;
|
|
1032
|
-
const dsl = await this.getCodeDsl();
|
|
1033
|
-
const existedIds = keys(dsl);
|
|
1034
|
-
if (!existedIds.includes(newId))
|
|
1035
|
-
return newId;
|
|
1036
|
-
return await this.getUniqueId();
|
|
1037
|
-
}
|
|
1038
|
-
async deleteCompsInRelation(node) {
|
|
1039
|
-
const codeDsl2 = cloneDeep(await this.getCodeDsl());
|
|
1040
|
-
if (!codeDsl2)
|
|
1041
|
-
return;
|
|
1042
|
-
this.refreshRelationDeep(node, codeDsl2);
|
|
1043
|
-
this.setCodeDsl(codeDsl2);
|
|
1044
|
-
}
|
|
1045
|
-
resetState() {
|
|
1046
|
-
this.state.isShowCodeEditor = false;
|
|
1047
|
-
this.state.codeDsl = null;
|
|
1048
|
-
this.state.id = "";
|
|
1049
|
-
this.state.editable = true;
|
|
1050
|
-
this.state.combineIds = [];
|
|
1051
|
-
this.state.undeletableList = [];
|
|
1052
|
-
}
|
|
1053
|
-
destroy() {
|
|
1054
|
-
this.resetState();
|
|
1055
|
-
this.removeAllListeners();
|
|
1056
|
-
this.removeAllPlugins();
|
|
1057
|
-
}
|
|
1058
|
-
refreshRelationDeep(node, codeDsl2) {
|
|
1059
|
-
if (!node.id)
|
|
1060
|
-
return;
|
|
1061
|
-
forIn(codeDsl2, (codeBlockContent) => {
|
|
1062
|
-
const compsContent = codeBlockContent.comps || {};
|
|
1063
|
-
codeBlockContent.comps = omit(compsContent, node.id);
|
|
1064
|
-
});
|
|
1065
|
-
if (!isEmpty(node.items)) {
|
|
1066
|
-
node.items.forEach((item) => {
|
|
1067
|
-
this.refreshRelationDeep(item, codeDsl2);
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
recurseMNode(node, relations) {
|
|
1072
|
-
forIn(node, (value, key) => {
|
|
1073
|
-
let unConfirmedValue = { id: node.id };
|
|
1074
|
-
if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
|
|
1075
|
-
value.hookData.forEach((relationItem) => {
|
|
1076
|
-
if (!relationItem.codeId)
|
|
1077
|
-
return;
|
|
1078
|
-
if (!relations[relationItem.codeId]) {
|
|
1079
|
-
relations[relationItem.codeId] = {};
|
|
1080
|
-
}
|
|
1081
|
-
const codeItem = relations[relationItem.codeId];
|
|
1082
|
-
if (isEmpty(codeItem[node.id])) {
|
|
1083
|
-
codeItem[node.id] = [];
|
|
1084
|
-
}
|
|
1085
|
-
codeItem[node.id].push(key);
|
|
1086
|
-
});
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
|
-
if (typeof value === "object") {
|
|
1090
|
-
unConfirmedValue = {
|
|
1091
|
-
...unConfirmedValue,
|
|
1092
|
-
...value
|
|
1093
|
-
};
|
|
1094
|
-
this.recurseMNode(unConfirmedValue, relations);
|
|
1095
|
-
}
|
|
1096
|
-
});
|
|
1097
|
-
if (!isEmpty(node.items)) {
|
|
1098
|
-
node.items.forEach((item) => {
|
|
1099
|
-
this.recurseMNode(item, relations);
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
const codeBlockService = new CodeBlock();
|
|
1105
|
-
|
|
1106
|
-
class UndoRedo {
|
|
1107
|
-
elementList;
|
|
1108
|
-
listCursor;
|
|
1109
|
-
listMaxSize;
|
|
1110
|
-
constructor(listMaxSize = 200) {
|
|
1111
|
-
const minListMaxSize = 2;
|
|
1112
|
-
this.elementList = [];
|
|
1113
|
-
this.listCursor = 0;
|
|
1114
|
-
this.listMaxSize = listMaxSize > minListMaxSize ? listMaxSize : minListMaxSize;
|
|
1115
|
-
}
|
|
1116
|
-
pushElement(element) {
|
|
1117
|
-
this.elementList.splice(this.listCursor, this.elementList.length - this.listCursor, cloneDeep(element));
|
|
1118
|
-
this.listCursor += 1;
|
|
1119
|
-
if (this.elementList.length > this.listMaxSize) {
|
|
1120
|
-
this.elementList.shift();
|
|
1121
|
-
this.listCursor -= 1;
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
canUndo() {
|
|
1125
|
-
return this.listCursor > 1;
|
|
1126
|
-
}
|
|
1127
|
-
undo() {
|
|
1128
|
-
if (!this.canUndo()) {
|
|
1129
|
-
return null;
|
|
1130
|
-
}
|
|
1131
|
-
this.listCursor -= 1;
|
|
1132
|
-
return this.getCurrentElement();
|
|
1133
|
-
}
|
|
1134
|
-
canRedo() {
|
|
1135
|
-
return this.elementList.length > this.listCursor;
|
|
1136
|
-
}
|
|
1137
|
-
redo() {
|
|
1138
|
-
if (!this.canRedo()) {
|
|
1139
|
-
return null;
|
|
1140
|
-
}
|
|
1141
|
-
this.listCursor += 1;
|
|
1142
|
-
return this.getCurrentElement();
|
|
1143
|
-
}
|
|
1144
|
-
getCurrentElement() {
|
|
1145
|
-
if (this.listCursor < 1) {
|
|
1146
|
-
return null;
|
|
1147
|
-
}
|
|
1148
|
-
return cloneDeep(this.elementList[this.listCursor - 1]);
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
875
|
class History extends BaseService {
|
|
1153
876
|
state = reactive({
|
|
1154
877
|
pageSteps: {},
|
|
@@ -1317,6 +1040,37 @@ class WebStorage extends BaseService {
|
|
|
1317
1040
|
}
|
|
1318
1041
|
const storageService = new WebStorage();
|
|
1319
1042
|
|
|
1043
|
+
var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
|
|
1044
|
+
ColumnLayout2["LEFT"] = "left";
|
|
1045
|
+
ColumnLayout2["CENTER"] = "center";
|
|
1046
|
+
ColumnLayout2["RIGHT"] = "right";
|
|
1047
|
+
return ColumnLayout2;
|
|
1048
|
+
})(ColumnLayout || {});
|
|
1049
|
+
var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
|
|
1050
|
+
LayerOffset2["TOP"] = "top";
|
|
1051
|
+
LayerOffset2["BOTTOM"] = "bottom";
|
|
1052
|
+
return LayerOffset2;
|
|
1053
|
+
})(LayerOffset || {});
|
|
1054
|
+
var Layout = /* @__PURE__ */ ((Layout2) => {
|
|
1055
|
+
Layout2["FLEX"] = "flex";
|
|
1056
|
+
Layout2["FIXED"] = "fixed";
|
|
1057
|
+
Layout2["RELATIVE"] = "relative";
|
|
1058
|
+
Layout2["ABSOLUTE"] = "absolute";
|
|
1059
|
+
return Layout2;
|
|
1060
|
+
})(Layout || {});
|
|
1061
|
+
var Keys = /* @__PURE__ */ ((Keys2) => {
|
|
1062
|
+
Keys2["ESCAPE"] = "Space";
|
|
1063
|
+
return Keys2;
|
|
1064
|
+
})(Keys || {});
|
|
1065
|
+
const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
|
|
1066
|
+
const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
|
|
1067
|
+
var CodeDeleteErrorType = /* @__PURE__ */ ((CodeDeleteErrorType2) => {
|
|
1068
|
+
CodeDeleteErrorType2["UNDELETEABLE"] = "undeleteable";
|
|
1069
|
+
CodeDeleteErrorType2["BIND"] = "bind";
|
|
1070
|
+
return CodeDeleteErrorType2;
|
|
1071
|
+
})(CodeDeleteErrorType || {});
|
|
1072
|
+
const CODE_DRAFT_STORAGE_KEY = "magicCodeDraft";
|
|
1073
|
+
|
|
1320
1074
|
const COPY_STORAGE_KEY = "$MagicEditorCopyData";
|
|
1321
1075
|
const getPageList = (app) => {
|
|
1322
1076
|
if (app.items && Array.isArray(app.items)) {
|
|
@@ -1949,7 +1703,6 @@ class Editor$1 extends BaseService {
|
|
|
1949
1703
|
stage?.select(parent.id);
|
|
1950
1704
|
}
|
|
1951
1705
|
this.addModifiedNodeId(parent.id);
|
|
1952
|
-
codeBlockService.deleteCompsInRelation(node);
|
|
1953
1706
|
}
|
|
1954
1707
|
async remove(nodeOrNodeList) {
|
|
1955
1708
|
const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
|
|
@@ -2017,7 +1770,6 @@ class Editor$1 extends BaseService {
|
|
|
2017
1770
|
const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
|
|
2018
1771
|
this.pushHistoryState();
|
|
2019
1772
|
this.emit("update", newNodes);
|
|
2020
|
-
codeBlockService.refreshCombineInfo();
|
|
2021
1773
|
return Array.isArray(config) ? newNodes : newNodes[0];
|
|
2022
1774
|
}
|
|
2023
1775
|
async sort(id1, id2) {
|
|
@@ -2256,6 +2008,7 @@ class Editor$1 extends BaseService {
|
|
|
2256
2008
|
await this.select(value.nodeId);
|
|
2257
2009
|
this.get("stage")?.select(value.nodeId);
|
|
2258
2010
|
}, 0);
|
|
2011
|
+
this.emit("history-change", value.data);
|
|
2259
2012
|
}
|
|
2260
2013
|
async toggleFixedPosition(dist, src, root) {
|
|
2261
2014
|
const newConfig = cloneDeep(dist);
|
|
@@ -2556,6 +2309,32 @@ const fillConfig = (config = []) => [
|
|
|
2556
2309
|
}
|
|
2557
2310
|
];
|
|
2558
2311
|
|
|
2312
|
+
const log = (...args) => {
|
|
2313
|
+
if (process.env.NODE_ENV === "development") {
|
|
2314
|
+
console.log("magic editor: ", ...args);
|
|
2315
|
+
}
|
|
2316
|
+
};
|
|
2317
|
+
const info = (...args) => {
|
|
2318
|
+
if (process.env.NODE_ENV === "development") {
|
|
2319
|
+
console.info("magic editor: ", ...args);
|
|
2320
|
+
}
|
|
2321
|
+
};
|
|
2322
|
+
const warn = (...args) => {
|
|
2323
|
+
if (process.env.NODE_ENV === "development") {
|
|
2324
|
+
console.warn("magic editor: ", ...args);
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
const debug = (...args) => {
|
|
2328
|
+
if (process.env.NODE_ENV === "development") {
|
|
2329
|
+
console.debug("magic editor: ", ...args);
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
const error = (...args) => {
|
|
2333
|
+
if (process.env.NODE_ENV === "development") {
|
|
2334
|
+
console.error("magic editor: ", ...args);
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2337
|
+
|
|
2559
2338
|
const state = reactive({
|
|
2560
2339
|
uiSelectMode: false,
|
|
2561
2340
|
showSrc: false,
|
|
@@ -3736,15 +3515,20 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3736
3515
|
const isShowCodeBlockEditor = computed(() => services?.codeBlockService.getCodeEditorShowStatus() || false);
|
|
3737
3516
|
const codeCombineInfo = ref(null);
|
|
3738
3517
|
const getBindCompsByCodeId = (codeId) => {
|
|
3739
|
-
if (!codeCombineInfo.value
|
|
3518
|
+
if (!codeCombineInfo.value)
|
|
3740
3519
|
return [];
|
|
3741
|
-
const
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3520
|
+
const bindsComp = [];
|
|
3521
|
+
forIn(codeCombineInfo.value, (codeIds, compId) => {
|
|
3522
|
+
if (codeIds.includes(codeId)) {
|
|
3523
|
+
bindsComp.push({
|
|
3524
|
+
compId,
|
|
3525
|
+
compName: getCompName(compId)
|
|
3526
|
+
});
|
|
3527
|
+
}
|
|
3528
|
+
});
|
|
3529
|
+
return bindsComp;
|
|
3746
3530
|
};
|
|
3747
|
-
const
|
|
3531
|
+
const refreshCodeList = async () => {
|
|
3748
3532
|
const codeDsl = cloneDeep(await services?.codeBlockService.getCodeDsl()) || null;
|
|
3749
3533
|
codeCombineInfo.value = cloneDeep(services?.codeBlockService.getCombineInfo()) || null;
|
|
3750
3534
|
if (!codeDsl || !codeCombineInfo.value)
|
|
@@ -3761,12 +3545,18 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3761
3545
|
});
|
|
3762
3546
|
};
|
|
3763
3547
|
watch(
|
|
3764
|
-
|
|
3548
|
+
() => services?.editorService.get("root"),
|
|
3549
|
+
() => {
|
|
3550
|
+
services?.codeBlockService.refreshAllRelations();
|
|
3551
|
+
refreshCodeList();
|
|
3552
|
+
}
|
|
3553
|
+
);
|
|
3554
|
+
watch(
|
|
3555
|
+
[() => services?.codeBlockService.getCodeDslSync(), () => services?.codeBlockService.getCombineInfo()],
|
|
3765
3556
|
() => {
|
|
3766
|
-
|
|
3557
|
+
refreshCodeList();
|
|
3767
3558
|
},
|
|
3768
3559
|
{
|
|
3769
|
-
immediate: true,
|
|
3770
3560
|
deep: true
|
|
3771
3561
|
}
|
|
3772
3562
|
);
|
|
@@ -4664,7 +4454,7 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
|
|
|
4664
4454
|
default: withCtx(() => [
|
|
4665
4455
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(sideBarItems), (config, index) => {
|
|
4666
4456
|
return openBlock(), createBlock(resolveDynamicComponent(unref(uiComponent).component), {
|
|
4667
|
-
key: index,
|
|
4457
|
+
key: config.$key || index,
|
|
4668
4458
|
name: config.text
|
|
4669
4459
|
}, {
|
|
4670
4460
|
label: withCtx(() => [
|
|
@@ -5799,6 +5589,236 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
5799
5589
|
}
|
|
5800
5590
|
});
|
|
5801
5591
|
|
|
5592
|
+
class CodeBlock extends BaseService {
|
|
5593
|
+
state = reactive({
|
|
5594
|
+
isShowCodeEditor: false,
|
|
5595
|
+
codeDsl: null,
|
|
5596
|
+
id: "",
|
|
5597
|
+
editable: true,
|
|
5598
|
+
combineIds: [],
|
|
5599
|
+
undeletableList: [],
|
|
5600
|
+
relations: {}
|
|
5601
|
+
});
|
|
5602
|
+
constructor() {
|
|
5603
|
+
super([
|
|
5604
|
+
"setCodeDsl",
|
|
5605
|
+
"getCodeDsl",
|
|
5606
|
+
"getCodeContentById",
|
|
5607
|
+
"getCodeDslByIds",
|
|
5608
|
+
"getCurrentDsl",
|
|
5609
|
+
"setCodeDslById",
|
|
5610
|
+
"setCodeEditorShowStatus",
|
|
5611
|
+
"setEditStatus",
|
|
5612
|
+
"setCombineIds",
|
|
5613
|
+
"setUndeleteableList",
|
|
5614
|
+
"deleteCodeDslByIds"
|
|
5615
|
+
]);
|
|
5616
|
+
}
|
|
5617
|
+
async setCodeDsl(codeDsl2) {
|
|
5618
|
+
this.state.codeDsl = codeDsl2;
|
|
5619
|
+
await editorService.setCodeDsl(this.state.codeDsl);
|
|
5620
|
+
info("[code-block]:code-dsl-change", this.state.codeDsl);
|
|
5621
|
+
this.emit("code-dsl-change", this.state.codeDsl);
|
|
5622
|
+
}
|
|
5623
|
+
async getCodeDsl(forceRefresh = false) {
|
|
5624
|
+
return this.getCodeDslSync(forceRefresh);
|
|
5625
|
+
}
|
|
5626
|
+
getCodeDslSync(forceRefresh = false) {
|
|
5627
|
+
if (!this.state.codeDsl || forceRefresh) {
|
|
5628
|
+
this.state.codeDsl = editorService.getCodeDslSync();
|
|
5629
|
+
}
|
|
5630
|
+
return this.state.codeDsl;
|
|
5631
|
+
}
|
|
5632
|
+
async getCodeContentById(id2) {
|
|
5633
|
+
if (!id2)
|
|
5634
|
+
return null;
|
|
5635
|
+
const totalCodeDsl = await this.getCodeDsl();
|
|
5636
|
+
if (!totalCodeDsl)
|
|
5637
|
+
return null;
|
|
5638
|
+
return totalCodeDsl[id2] ?? null;
|
|
5639
|
+
}
|
|
5640
|
+
async setCodeDslById(id, codeConfig) {
|
|
5641
|
+
let codeDsl = await this.getCodeDsl();
|
|
5642
|
+
const codeConfigProcessed = codeConfig;
|
|
5643
|
+
if (codeConfig.content) {
|
|
5644
|
+
codeConfigProcessed.content = eval(codeConfig.content);
|
|
5645
|
+
}
|
|
5646
|
+
if (!codeDsl) {
|
|
5647
|
+
codeDsl = {
|
|
5648
|
+
[id]: {
|
|
5649
|
+
...codeConfigProcessed
|
|
5650
|
+
}
|
|
5651
|
+
};
|
|
5652
|
+
} else {
|
|
5653
|
+
const existContent = codeDsl[id] || {};
|
|
5654
|
+
codeDsl = {
|
|
5655
|
+
...codeDsl,
|
|
5656
|
+
[id]: {
|
|
5657
|
+
...existContent,
|
|
5658
|
+
...codeConfigProcessed
|
|
5659
|
+
}
|
|
5660
|
+
};
|
|
5661
|
+
}
|
|
5662
|
+
await this.setCodeDsl(codeDsl);
|
|
5663
|
+
}
|
|
5664
|
+
async getCodeDslByIds(ids) {
|
|
5665
|
+
const codeDsl2 = await this.getCodeDsl();
|
|
5666
|
+
return pick(codeDsl2, ids);
|
|
5667
|
+
}
|
|
5668
|
+
async setCodeEditorShowStatus(status) {
|
|
5669
|
+
this.state.isShowCodeEditor = status;
|
|
5670
|
+
}
|
|
5671
|
+
getCodeEditorShowStatus() {
|
|
5672
|
+
return this.state.isShowCodeEditor;
|
|
5673
|
+
}
|
|
5674
|
+
setCodeEditorContent(status, id2) {
|
|
5675
|
+
if (!id2)
|
|
5676
|
+
return;
|
|
5677
|
+
this.setId(id2);
|
|
5678
|
+
this.state.isShowCodeEditor = status;
|
|
5679
|
+
}
|
|
5680
|
+
async getCurrentDsl() {
|
|
5681
|
+
return await this.getCodeContentById(this.state.id);
|
|
5682
|
+
}
|
|
5683
|
+
getEditStatus() {
|
|
5684
|
+
return this.state.editable;
|
|
5685
|
+
}
|
|
5686
|
+
async setEditStatus(status) {
|
|
5687
|
+
this.state.editable = status;
|
|
5688
|
+
}
|
|
5689
|
+
setId(id2) {
|
|
5690
|
+
if (!id2)
|
|
5691
|
+
return;
|
|
5692
|
+
this.state.id = id2;
|
|
5693
|
+
}
|
|
5694
|
+
getId() {
|
|
5695
|
+
return this.state.id;
|
|
5696
|
+
}
|
|
5697
|
+
async setCombineIds(ids) {
|
|
5698
|
+
this.state.combineIds = ids;
|
|
5699
|
+
}
|
|
5700
|
+
getCombineIds() {
|
|
5701
|
+
return this.state.combineIds;
|
|
5702
|
+
}
|
|
5703
|
+
addCodeRelationListener() {
|
|
5704
|
+
editorService.on("update", (nodes) => {
|
|
5705
|
+
const relations = cloneDeep(this.state.relations);
|
|
5706
|
+
nodes.forEach((node) => {
|
|
5707
|
+
if (node?.id) {
|
|
5708
|
+
relations[node.id] = [];
|
|
5709
|
+
this.getNodeRelation(node, relations);
|
|
5710
|
+
}
|
|
5711
|
+
});
|
|
5712
|
+
this.state.relations = { ...relations };
|
|
5713
|
+
});
|
|
5714
|
+
editorService.on("remove", (nodes) => {
|
|
5715
|
+
nodes.forEach((node) => {
|
|
5716
|
+
this.state.relations = this.deleteNodeRelation(node, this.state.relations);
|
|
5717
|
+
});
|
|
5718
|
+
});
|
|
5719
|
+
editorService.on("history-change", (page) => {
|
|
5720
|
+
const relations = {};
|
|
5721
|
+
this.getNodeRelation(page, relations, true);
|
|
5722
|
+
this.state.relations = relations;
|
|
5723
|
+
});
|
|
5724
|
+
}
|
|
5725
|
+
refreshAllRelations() {
|
|
5726
|
+
const root = editorService.get("root");
|
|
5727
|
+
if (!root)
|
|
5728
|
+
return;
|
|
5729
|
+
const relations = {};
|
|
5730
|
+
this.getNodeRelation(root, relations, true);
|
|
5731
|
+
this.state.relations = relations;
|
|
5732
|
+
}
|
|
5733
|
+
getCombineInfo() {
|
|
5734
|
+
return this.state.relations;
|
|
5735
|
+
}
|
|
5736
|
+
getUndeletableList() {
|
|
5737
|
+
return this.state.undeletableList;
|
|
5738
|
+
}
|
|
5739
|
+
async setUndeleteableList(codeIds) {
|
|
5740
|
+
this.state.undeletableList = codeIds;
|
|
5741
|
+
}
|
|
5742
|
+
setCodeDraft(codeId, content) {
|
|
5743
|
+
globalThis.localStorage.setItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`, content);
|
|
5744
|
+
}
|
|
5745
|
+
getCodeDraft(codeId) {
|
|
5746
|
+
return globalThis.localStorage.getItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
|
|
5747
|
+
}
|
|
5748
|
+
removeCodeDraft(codeId) {
|
|
5749
|
+
globalThis.localStorage.removeItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
|
|
5750
|
+
}
|
|
5751
|
+
async deleteCodeDslByIds(codeIds) {
|
|
5752
|
+
const currentDsl = await this.getCodeDsl();
|
|
5753
|
+
const newDsl = omit(currentDsl, codeIds);
|
|
5754
|
+
await this.setCodeDsl(newDsl);
|
|
5755
|
+
return newDsl;
|
|
5756
|
+
}
|
|
5757
|
+
async getUniqueId() {
|
|
5758
|
+
const newId = `code_${Math.random().toString(10).substring(2).substring(0, 4)}`;
|
|
5759
|
+
const dsl = await this.getCodeDsl();
|
|
5760
|
+
const existedIds = keys(dsl);
|
|
5761
|
+
if (!existedIds.includes(newId))
|
|
5762
|
+
return newId;
|
|
5763
|
+
return await this.getUniqueId();
|
|
5764
|
+
}
|
|
5765
|
+
resetState() {
|
|
5766
|
+
this.state.isShowCodeEditor = false;
|
|
5767
|
+
this.state.codeDsl = null;
|
|
5768
|
+
this.state.id = "";
|
|
5769
|
+
this.state.editable = true;
|
|
5770
|
+
this.state.combineIds = [];
|
|
5771
|
+
this.state.undeletableList = [];
|
|
5772
|
+
}
|
|
5773
|
+
destroy() {
|
|
5774
|
+
this.resetState();
|
|
5775
|
+
this.removeAllListeners();
|
|
5776
|
+
this.removeAllPlugins();
|
|
5777
|
+
}
|
|
5778
|
+
getNodeRelation(node, relation, deep = false) {
|
|
5779
|
+
forIn(node, (value, key) => {
|
|
5780
|
+
if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
|
|
5781
|
+
value.hookData.forEach((relationItem) => {
|
|
5782
|
+
if (relationItem.codeId) {
|
|
5783
|
+
relation[node.id] = union(relation[node.id], [relationItem.codeId]);
|
|
5784
|
+
}
|
|
5785
|
+
});
|
|
5786
|
+
return;
|
|
5787
|
+
}
|
|
5788
|
+
let isContinue = false;
|
|
5789
|
+
try {
|
|
5790
|
+
isContinue = key !== "items" && typeof value === "object" && JSON.stringify(value).includes("hookType");
|
|
5791
|
+
} catch (error) {
|
|
5792
|
+
console.error(error);
|
|
5793
|
+
}
|
|
5794
|
+
if (isContinue) {
|
|
5795
|
+
const unConfirmedValue = {
|
|
5796
|
+
id: node.id,
|
|
5797
|
+
...value
|
|
5798
|
+
};
|
|
5799
|
+
this.getNodeRelation(unConfirmedValue, relation);
|
|
5800
|
+
}
|
|
5801
|
+
if (key === "items" && !isEmpty(value) && deep) {
|
|
5802
|
+
value.forEach((item) => {
|
|
5803
|
+
this.getNodeRelation(item, relation, deep);
|
|
5804
|
+
});
|
|
5805
|
+
}
|
|
5806
|
+
});
|
|
5807
|
+
}
|
|
5808
|
+
deleteNodeRelation(node, relations) {
|
|
5809
|
+
if (!node.id)
|
|
5810
|
+
return {};
|
|
5811
|
+
let newRelations = omit(relations, [node.id]);
|
|
5812
|
+
if (!isEmpty(node.items)) {
|
|
5813
|
+
node.items.forEach((item) => {
|
|
5814
|
+
newRelations = this.deleteNodeRelation(item, newRelations);
|
|
5815
|
+
});
|
|
5816
|
+
}
|
|
5817
|
+
return newRelations;
|
|
5818
|
+
}
|
|
5819
|
+
}
|
|
5820
|
+
const codeBlockService = new CodeBlock();
|
|
5821
|
+
|
|
5802
5822
|
class ComponentList extends BaseService {
|
|
5803
5823
|
state = reactive({
|
|
5804
5824
|
list: []
|
|
@@ -6033,6 +6053,7 @@ const _sfc_main = defineComponent({
|
|
|
6033
6053
|
disabledDragStart: props.disabledDragStart
|
|
6034
6054
|
})
|
|
6035
6055
|
);
|
|
6056
|
+
codeBlockService.addCodeRelationListener();
|
|
6036
6057
|
return services;
|
|
6037
6058
|
}
|
|
6038
6059
|
});
|