@tmagic/editor 1.2.8 → 1.2.10
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 +22 -51
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +21 -50
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +9 -9
- package/src/Editor.vue +4 -0
- package/src/components/FunctionEditor.vue +1 -1
- package/src/fields/CodeSelect.vue +1 -1
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +1 -1
- package/src/services/codeBlock.ts +21 -35
- package/src/services/editor.ts +1 -27
- package/types/services/codeBlock.d.ts +2 -4
- package/types/services/editor.d.ts +1 -13
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, cloneDeep, mergeWith, isObject, uniq, forIn, difference, union, pick,
|
|
4
|
+
import { isEmpty, map, throttle, cloneDeep, mergeWith, isObject, uniq, forIn, difference, union, pick, keys, omit } 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';
|
|
@@ -180,7 +180,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
|
|
|
180
180
|
const props = __props;
|
|
181
181
|
const services = inject("services");
|
|
182
182
|
const mForm = inject("mForm");
|
|
183
|
-
const codeDsl = computed(() => services?.codeBlockService.
|
|
183
|
+
const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
|
|
184
184
|
const tableConfig = computed(() => {
|
|
185
185
|
const defaultConfig = {
|
|
186
186
|
dropSort: false,
|
|
@@ -1451,9 +1451,7 @@ class Editor$1 extends BaseService {
|
|
|
1451
1451
|
"move",
|
|
1452
1452
|
"undo",
|
|
1453
1453
|
"redo",
|
|
1454
|
-
"highlight"
|
|
1455
|
-
"getCodeDsl",
|
|
1456
|
-
"setCodeDsl"
|
|
1454
|
+
"highlight"
|
|
1457
1455
|
],
|
|
1458
1456
|
["select", "update", "moveLayer"]
|
|
1459
1457
|
);
|
|
@@ -1966,19 +1964,6 @@ class Editor$1 extends BaseService {
|
|
|
1966
1964
|
resetModifiedNodeId() {
|
|
1967
1965
|
this.get("modifiedNodeIds").clear();
|
|
1968
1966
|
}
|
|
1969
|
-
async getCodeDsl() {
|
|
1970
|
-
const root = this.get("root");
|
|
1971
|
-
return root?.codeBlocks || null;
|
|
1972
|
-
}
|
|
1973
|
-
getCodeDslSync() {
|
|
1974
|
-
const root = this.get("root");
|
|
1975
|
-
return root?.codeBlocks || null;
|
|
1976
|
-
}
|
|
1977
|
-
async setCodeDsl(codeDsl) {
|
|
1978
|
-
if (!this.state.root)
|
|
1979
|
-
return;
|
|
1980
|
-
this.state.root.codeBlocks = codeDsl;
|
|
1981
|
-
}
|
|
1982
1967
|
addModifiedNodeId(id) {
|
|
1983
1968
|
if (!this.isHistoryStateChange) {
|
|
1984
1969
|
this.get("modifiedNodeIds").set(id, id);
|
|
@@ -3313,7 +3298,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
|
|
|
3313
3298
|
codeContent.value = props.content;
|
|
3314
3299
|
});
|
|
3315
3300
|
const initTableModel = () => {
|
|
3316
|
-
const codeDsl = cloneDeep(services?.codeBlockService.
|
|
3301
|
+
const codeDsl = cloneDeep(services?.codeBlockService.getCodeDsl());
|
|
3317
3302
|
if (!codeDsl)
|
|
3318
3303
|
return;
|
|
3319
3304
|
tableModel.value = {
|
|
@@ -3562,7 +3547,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3562
3547
|
}
|
|
3563
3548
|
);
|
|
3564
3549
|
watch(
|
|
3565
|
-
[() => services?.codeBlockService.
|
|
3550
|
+
[() => services?.codeBlockService.getCodeDsl(), () => services?.codeBlockService.getCombineInfo()],
|
|
3566
3551
|
() => {
|
|
3567
3552
|
refreshCodeList();
|
|
3568
3553
|
},
|
|
@@ -5617,8 +5602,6 @@ class CodeBlock extends BaseService {
|
|
|
5617
5602
|
});
|
|
5618
5603
|
constructor() {
|
|
5619
5604
|
super([
|
|
5620
|
-
"setCodeDsl",
|
|
5621
|
-
"getCodeDsl",
|
|
5622
5605
|
"getCodeContentById",
|
|
5623
5606
|
"getCodeDslByIds",
|
|
5624
5607
|
"getCurrentDsl",
|
|
@@ -5632,17 +5615,10 @@ class CodeBlock extends BaseService {
|
|
|
5632
5615
|
}
|
|
5633
5616
|
async setCodeDsl(codeDsl2) {
|
|
5634
5617
|
this.state.codeDsl = codeDsl2;
|
|
5635
|
-
await editorService.setCodeDsl(this.state.codeDsl);
|
|
5636
5618
|
info("[code-block]:code-dsl-change", this.state.codeDsl);
|
|
5637
5619
|
this.emit("code-dsl-change", this.state.codeDsl);
|
|
5638
5620
|
}
|
|
5639
|
-
|
|
5640
|
-
return this.getCodeDslSync(forceRefresh);
|
|
5641
|
-
}
|
|
5642
|
-
getCodeDslSync(forceRefresh = false) {
|
|
5643
|
-
if (!this.state.codeDsl || forceRefresh) {
|
|
5644
|
-
this.state.codeDsl = editorService.getCodeDslSync();
|
|
5645
|
-
}
|
|
5621
|
+
getCodeDsl() {
|
|
5646
5622
|
return this.state.codeDsl;
|
|
5647
5623
|
}
|
|
5648
5624
|
async getCodeContentById(id2) {
|
|
@@ -5654,28 +5630,19 @@ class CodeBlock extends BaseService {
|
|
|
5654
5630
|
return totalCodeDsl[id2] ?? null;
|
|
5655
5631
|
}
|
|
5656
5632
|
async setCodeDslById(id, codeConfig) {
|
|
5657
|
-
|
|
5633
|
+
const codeDsl = await this.getCodeDsl();
|
|
5634
|
+
if (!codeDsl) {
|
|
5635
|
+
throw new Error("dsl\u4E2D\u6CA1\u6709codeBlocks");
|
|
5636
|
+
}
|
|
5658
5637
|
const codeConfigProcessed = codeConfig;
|
|
5659
5638
|
if (codeConfig.content) {
|
|
5660
5639
|
codeConfigProcessed.content = eval(codeConfig.content);
|
|
5661
5640
|
}
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
};
|
|
5668
|
-
} else {
|
|
5669
|
-
const existContent = codeDsl[id] || {};
|
|
5670
|
-
codeDsl = {
|
|
5671
|
-
...codeDsl,
|
|
5672
|
-
[id]: {
|
|
5673
|
-
...existContent,
|
|
5674
|
-
...codeConfigProcessed
|
|
5675
|
-
}
|
|
5676
|
-
};
|
|
5677
|
-
}
|
|
5678
|
-
await this.setCodeDsl(codeDsl);
|
|
5641
|
+
const existContent = codeDsl[id] || {};
|
|
5642
|
+
codeDsl[id] = {
|
|
5643
|
+
...existContent,
|
|
5644
|
+
...codeConfigProcessed
|
|
5645
|
+
};
|
|
5679
5646
|
}
|
|
5680
5647
|
async getCodeDslByIds(ids) {
|
|
5681
5648
|
const codeDsl2 = await this.getCodeDsl();
|
|
@@ -5766,9 +5733,11 @@ class CodeBlock extends BaseService {
|
|
|
5766
5733
|
}
|
|
5767
5734
|
async deleteCodeDslByIds(codeIds) {
|
|
5768
5735
|
const currentDsl = await this.getCodeDsl();
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5736
|
+
if (!currentDsl)
|
|
5737
|
+
return;
|
|
5738
|
+
codeIds.forEach((id2) => {
|
|
5739
|
+
delete currentDsl[id2];
|
|
5740
|
+
});
|
|
5772
5741
|
}
|
|
5773
5742
|
async getUniqueId() {
|
|
5774
5743
|
const newId = `code_${Math.random().toString(10).substring(2).substring(0, 4)}`;
|
|
@@ -5970,6 +5939,8 @@ const _sfc_main = defineComponent({
|
|
|
5970
5939
|
if (toRaw(value) !== toRaw(preValue)) {
|
|
5971
5940
|
emit("update:modelValue", value);
|
|
5972
5941
|
}
|
|
5942
|
+
value.codeBlocks = value.codeBlocks || {};
|
|
5943
|
+
codeBlockService.setCodeDsl(value.codeBlocks);
|
|
5973
5944
|
};
|
|
5974
5945
|
editorService.on("root-change", rootChangeHandler);
|
|
5975
5946
|
watch(
|