@tmagic/editor 1.2.2 → 1.2.4
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 +343 -331
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +342 -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 +23 -14
- package/src/services/codeBlock.ts +67 -56
- package/src/services/editor.ts +0 -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) {
|
|
@@ -2556,6 +2308,32 @@ const fillConfig = (config = []) => [
|
|
|
2556
2308
|
}
|
|
2557
2309
|
];
|
|
2558
2310
|
|
|
2311
|
+
const log = (...args) => {
|
|
2312
|
+
if (process.env.NODE_ENV === "development") {
|
|
2313
|
+
console.log("magic editor: ", ...args);
|
|
2314
|
+
}
|
|
2315
|
+
};
|
|
2316
|
+
const info = (...args) => {
|
|
2317
|
+
if (process.env.NODE_ENV === "development") {
|
|
2318
|
+
console.info("magic editor: ", ...args);
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
const warn = (...args) => {
|
|
2322
|
+
if (process.env.NODE_ENV === "development") {
|
|
2323
|
+
console.warn("magic editor: ", ...args);
|
|
2324
|
+
}
|
|
2325
|
+
};
|
|
2326
|
+
const debug = (...args) => {
|
|
2327
|
+
if (process.env.NODE_ENV === "development") {
|
|
2328
|
+
console.debug("magic editor: ", ...args);
|
|
2329
|
+
}
|
|
2330
|
+
};
|
|
2331
|
+
const error = (...args) => {
|
|
2332
|
+
if (process.env.NODE_ENV === "development") {
|
|
2333
|
+
console.error("magic editor: ", ...args);
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
|
|
2559
2337
|
const state = reactive({
|
|
2560
2338
|
uiSelectMode: false,
|
|
2561
2339
|
showSrc: false,
|
|
@@ -3736,15 +3514,20 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3736
3514
|
const isShowCodeBlockEditor = computed(() => services?.codeBlockService.getCodeEditorShowStatus() || false);
|
|
3737
3515
|
const codeCombineInfo = ref(null);
|
|
3738
3516
|
const getBindCompsByCodeId = (codeId) => {
|
|
3739
|
-
if (!codeCombineInfo.value
|
|
3517
|
+
if (!codeCombineInfo.value)
|
|
3740
3518
|
return [];
|
|
3741
|
-
const
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3519
|
+
const bindsComp = [];
|
|
3520
|
+
forIn(codeCombineInfo.value, (codeIds, compId) => {
|
|
3521
|
+
if (codeIds.includes(codeId)) {
|
|
3522
|
+
bindsComp.push({
|
|
3523
|
+
compId,
|
|
3524
|
+
compName: getCompName(compId)
|
|
3525
|
+
});
|
|
3526
|
+
}
|
|
3527
|
+
});
|
|
3528
|
+
return bindsComp;
|
|
3746
3529
|
};
|
|
3747
|
-
const
|
|
3530
|
+
const refreshCodeList = async () => {
|
|
3748
3531
|
const codeDsl = cloneDeep(await services?.codeBlockService.getCodeDsl()) || null;
|
|
3749
3532
|
codeCombineInfo.value = cloneDeep(services?.codeBlockService.getCombineInfo()) || null;
|
|
3750
3533
|
if (!codeDsl || !codeCombineInfo.value)
|
|
@@ -3760,13 +3543,16 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3760
3543
|
});
|
|
3761
3544
|
});
|
|
3762
3545
|
};
|
|
3546
|
+
onMounted(() => {
|
|
3547
|
+
services?.codeBlockService.refreshAllRelations();
|
|
3548
|
+
refreshCodeList();
|
|
3549
|
+
});
|
|
3763
3550
|
watch(
|
|
3764
|
-
[() => services?.codeBlockService.getCodeDslSync(), () => services?.codeBlockService.
|
|
3551
|
+
[() => services?.codeBlockService.getCodeDslSync(), () => services?.codeBlockService.getCombineInfo()],
|
|
3765
3552
|
() => {
|
|
3766
|
-
|
|
3553
|
+
refreshCodeList();
|
|
3767
3554
|
},
|
|
3768
3555
|
{
|
|
3769
|
-
immediate: true,
|
|
3770
3556
|
deep: true
|
|
3771
3557
|
}
|
|
3772
3558
|
);
|
|
@@ -4664,7 +4450,7 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
|
|
|
4664
4450
|
default: withCtx(() => [
|
|
4665
4451
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(sideBarItems), (config, index) => {
|
|
4666
4452
|
return openBlock(), createBlock(resolveDynamicComponent(unref(uiComponent).component), {
|
|
4667
|
-
key: index,
|
|
4453
|
+
key: config.$key || index,
|
|
4668
4454
|
name: config.text
|
|
4669
4455
|
}, {
|
|
4670
4456
|
label: withCtx(() => [
|
|
@@ -5799,6 +5585,231 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
5799
5585
|
}
|
|
5800
5586
|
});
|
|
5801
5587
|
|
|
5588
|
+
class CodeBlock extends BaseService {
|
|
5589
|
+
state = reactive({
|
|
5590
|
+
isShowCodeEditor: false,
|
|
5591
|
+
codeDsl: null,
|
|
5592
|
+
id: "",
|
|
5593
|
+
editable: true,
|
|
5594
|
+
combineIds: [],
|
|
5595
|
+
undeletableList: [],
|
|
5596
|
+
relations: {}
|
|
5597
|
+
});
|
|
5598
|
+
constructor() {
|
|
5599
|
+
super([
|
|
5600
|
+
"setCodeDsl",
|
|
5601
|
+
"getCodeDsl",
|
|
5602
|
+
"getCodeContentById",
|
|
5603
|
+
"getCodeDslByIds",
|
|
5604
|
+
"getCurrentDsl",
|
|
5605
|
+
"setCodeDslById",
|
|
5606
|
+
"setCodeEditorShowStatus",
|
|
5607
|
+
"setEditStatus",
|
|
5608
|
+
"setCombineIds",
|
|
5609
|
+
"setUndeleteableList",
|
|
5610
|
+
"deleteCodeDslByIds"
|
|
5611
|
+
]);
|
|
5612
|
+
}
|
|
5613
|
+
async setCodeDsl(codeDsl2) {
|
|
5614
|
+
this.state.codeDsl = codeDsl2;
|
|
5615
|
+
await editorService.setCodeDsl(this.state.codeDsl);
|
|
5616
|
+
info("[code-block]:code-dsl-change", this.state.codeDsl);
|
|
5617
|
+
this.emit("code-dsl-change", this.state.codeDsl);
|
|
5618
|
+
}
|
|
5619
|
+
async getCodeDsl(forceRefresh = false) {
|
|
5620
|
+
return this.getCodeDslSync(forceRefresh);
|
|
5621
|
+
}
|
|
5622
|
+
getCodeDslSync(forceRefresh = false) {
|
|
5623
|
+
if (!this.state.codeDsl || forceRefresh) {
|
|
5624
|
+
this.state.codeDsl = editorService.getCodeDslSync();
|
|
5625
|
+
}
|
|
5626
|
+
return this.state.codeDsl;
|
|
5627
|
+
}
|
|
5628
|
+
async getCodeContentById(id2) {
|
|
5629
|
+
if (!id2)
|
|
5630
|
+
return null;
|
|
5631
|
+
const totalCodeDsl = await this.getCodeDsl();
|
|
5632
|
+
if (!totalCodeDsl)
|
|
5633
|
+
return null;
|
|
5634
|
+
return totalCodeDsl[id2] ?? null;
|
|
5635
|
+
}
|
|
5636
|
+
async setCodeDslById(id, codeConfig) {
|
|
5637
|
+
let codeDsl = await this.getCodeDsl();
|
|
5638
|
+
const codeConfigProcessed = codeConfig;
|
|
5639
|
+
if (codeConfig.content) {
|
|
5640
|
+
codeConfigProcessed.content = eval(codeConfig.content);
|
|
5641
|
+
}
|
|
5642
|
+
if (!codeDsl) {
|
|
5643
|
+
codeDsl = {
|
|
5644
|
+
[id]: {
|
|
5645
|
+
...codeConfigProcessed
|
|
5646
|
+
}
|
|
5647
|
+
};
|
|
5648
|
+
} else {
|
|
5649
|
+
const existContent = codeDsl[id] || {};
|
|
5650
|
+
codeDsl = {
|
|
5651
|
+
...codeDsl,
|
|
5652
|
+
[id]: {
|
|
5653
|
+
...existContent,
|
|
5654
|
+
...codeConfigProcessed
|
|
5655
|
+
}
|
|
5656
|
+
};
|
|
5657
|
+
}
|
|
5658
|
+
await this.setCodeDsl(codeDsl);
|
|
5659
|
+
}
|
|
5660
|
+
async getCodeDslByIds(ids) {
|
|
5661
|
+
const codeDsl2 = await this.getCodeDsl();
|
|
5662
|
+
return pick(codeDsl2, ids);
|
|
5663
|
+
}
|
|
5664
|
+
async setCodeEditorShowStatus(status) {
|
|
5665
|
+
this.state.isShowCodeEditor = status;
|
|
5666
|
+
}
|
|
5667
|
+
getCodeEditorShowStatus() {
|
|
5668
|
+
return this.state.isShowCodeEditor;
|
|
5669
|
+
}
|
|
5670
|
+
setCodeEditorContent(status, id2) {
|
|
5671
|
+
if (!id2)
|
|
5672
|
+
return;
|
|
5673
|
+
this.setId(id2);
|
|
5674
|
+
this.state.isShowCodeEditor = status;
|
|
5675
|
+
}
|
|
5676
|
+
async getCurrentDsl() {
|
|
5677
|
+
return await this.getCodeContentById(this.state.id);
|
|
5678
|
+
}
|
|
5679
|
+
getEditStatus() {
|
|
5680
|
+
return this.state.editable;
|
|
5681
|
+
}
|
|
5682
|
+
async setEditStatus(status) {
|
|
5683
|
+
this.state.editable = status;
|
|
5684
|
+
}
|
|
5685
|
+
setId(id2) {
|
|
5686
|
+
if (!id2)
|
|
5687
|
+
return;
|
|
5688
|
+
this.state.id = id2;
|
|
5689
|
+
}
|
|
5690
|
+
getId() {
|
|
5691
|
+
return this.state.id;
|
|
5692
|
+
}
|
|
5693
|
+
async setCombineIds(ids) {
|
|
5694
|
+
this.state.combineIds = ids;
|
|
5695
|
+
}
|
|
5696
|
+
getCombineIds() {
|
|
5697
|
+
return this.state.combineIds;
|
|
5698
|
+
}
|
|
5699
|
+
addCodeRelationListener() {
|
|
5700
|
+
editorService.on("update", (nodes) => {
|
|
5701
|
+
const relations = cloneDeep(this.state.relations);
|
|
5702
|
+
nodes.forEach((node) => {
|
|
5703
|
+
if (node?.id) {
|
|
5704
|
+
relations[node.id] = [];
|
|
5705
|
+
this.getNodeRelation(node, relations);
|
|
5706
|
+
}
|
|
5707
|
+
});
|
|
5708
|
+
this.state.relations = { ...relations };
|
|
5709
|
+
});
|
|
5710
|
+
editorService.on("remove", (nodes) => {
|
|
5711
|
+
nodes.forEach((node) => {
|
|
5712
|
+
this.state.relations = this.deleteNodeRelation(node, this.state.relations);
|
|
5713
|
+
});
|
|
5714
|
+
});
|
|
5715
|
+
}
|
|
5716
|
+
refreshAllRelations() {
|
|
5717
|
+
const root = editorService.get("root");
|
|
5718
|
+
if (!root)
|
|
5719
|
+
return;
|
|
5720
|
+
const relations = {};
|
|
5721
|
+
this.getNodeRelation(root, relations, true);
|
|
5722
|
+
this.state.relations = relations;
|
|
5723
|
+
}
|
|
5724
|
+
getCombineInfo() {
|
|
5725
|
+
return this.state.relations;
|
|
5726
|
+
}
|
|
5727
|
+
getUndeletableList() {
|
|
5728
|
+
return this.state.undeletableList;
|
|
5729
|
+
}
|
|
5730
|
+
async setUndeleteableList(codeIds) {
|
|
5731
|
+
this.state.undeletableList = codeIds;
|
|
5732
|
+
}
|
|
5733
|
+
setCodeDraft(codeId, content) {
|
|
5734
|
+
globalThis.localStorage.setItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`, content);
|
|
5735
|
+
}
|
|
5736
|
+
getCodeDraft(codeId) {
|
|
5737
|
+
return globalThis.localStorage.getItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
|
|
5738
|
+
}
|
|
5739
|
+
removeCodeDraft(codeId) {
|
|
5740
|
+
globalThis.localStorage.removeItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
|
|
5741
|
+
}
|
|
5742
|
+
async deleteCodeDslByIds(codeIds) {
|
|
5743
|
+
const currentDsl = await this.getCodeDsl();
|
|
5744
|
+
const newDsl = omit(currentDsl, codeIds);
|
|
5745
|
+
await this.setCodeDsl(newDsl);
|
|
5746
|
+
return newDsl;
|
|
5747
|
+
}
|
|
5748
|
+
async getUniqueId() {
|
|
5749
|
+
const newId = `code_${Math.random().toString(10).substring(2).substring(0, 4)}`;
|
|
5750
|
+
const dsl = await this.getCodeDsl();
|
|
5751
|
+
const existedIds = keys(dsl);
|
|
5752
|
+
if (!existedIds.includes(newId))
|
|
5753
|
+
return newId;
|
|
5754
|
+
return await this.getUniqueId();
|
|
5755
|
+
}
|
|
5756
|
+
resetState() {
|
|
5757
|
+
this.state.isShowCodeEditor = false;
|
|
5758
|
+
this.state.codeDsl = null;
|
|
5759
|
+
this.state.id = "";
|
|
5760
|
+
this.state.editable = true;
|
|
5761
|
+
this.state.combineIds = [];
|
|
5762
|
+
this.state.undeletableList = [];
|
|
5763
|
+
}
|
|
5764
|
+
destroy() {
|
|
5765
|
+
this.resetState();
|
|
5766
|
+
this.removeAllListeners();
|
|
5767
|
+
this.removeAllPlugins();
|
|
5768
|
+
}
|
|
5769
|
+
getNodeRelation(node, relation, deep = false) {
|
|
5770
|
+
forIn(node, (value, key) => {
|
|
5771
|
+
if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
|
|
5772
|
+
value.hookData.forEach((relationItem) => {
|
|
5773
|
+
if (relationItem.codeId) {
|
|
5774
|
+
relation[node.id] = union(relation[node.id], [relationItem.codeId]);
|
|
5775
|
+
}
|
|
5776
|
+
});
|
|
5777
|
+
return;
|
|
5778
|
+
}
|
|
5779
|
+
let isContinue = false;
|
|
5780
|
+
try {
|
|
5781
|
+
isContinue = key !== "items" && typeof value === "object" && JSON.stringify(value).includes("hookType");
|
|
5782
|
+
} catch (error) {
|
|
5783
|
+
console.error(error);
|
|
5784
|
+
}
|
|
5785
|
+
if (isContinue) {
|
|
5786
|
+
const unConfirmedValue = {
|
|
5787
|
+
id: node.id,
|
|
5788
|
+
...value
|
|
5789
|
+
};
|
|
5790
|
+
this.getNodeRelation(unConfirmedValue, relation);
|
|
5791
|
+
}
|
|
5792
|
+
if (key === "items" && !isEmpty(value) && deep) {
|
|
5793
|
+
value.forEach((item) => {
|
|
5794
|
+
this.getNodeRelation(item, relation, deep);
|
|
5795
|
+
});
|
|
5796
|
+
}
|
|
5797
|
+
});
|
|
5798
|
+
}
|
|
5799
|
+
deleteNodeRelation(node, relations) {
|
|
5800
|
+
if (!node.id)
|
|
5801
|
+
return {};
|
|
5802
|
+
let newRelations = omit(relations, [node.id]);
|
|
5803
|
+
if (!isEmpty(node.items)) {
|
|
5804
|
+
node.items.forEach((item) => {
|
|
5805
|
+
newRelations = this.deleteNodeRelation(item, newRelations);
|
|
5806
|
+
});
|
|
5807
|
+
}
|
|
5808
|
+
return newRelations;
|
|
5809
|
+
}
|
|
5810
|
+
}
|
|
5811
|
+
const codeBlockService = new CodeBlock();
|
|
5812
|
+
|
|
5802
5813
|
class ComponentList extends BaseService {
|
|
5803
5814
|
state = reactive({
|
|
5804
5815
|
list: []
|
|
@@ -6033,6 +6044,7 @@ const _sfc_main = defineComponent({
|
|
|
6033
6044
|
disabledDragStart: props.disabledDragStart
|
|
6034
6045
|
})
|
|
6035
6046
|
);
|
|
6047
|
+
codeBlockService.addCodeRelationListener();
|
|
6036
6048
|
return services;
|
|
6037
6049
|
}
|
|
6038
6050
|
});
|