@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/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.10",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@babel/core": "^7.18.0",
|
|
48
48
|
"@element-plus/icons-vue": "^2.0.9",
|
|
49
|
-
"@tmagic/core": "1.2.
|
|
50
|
-
"@tmagic/design": "1.2.
|
|
51
|
-
"@tmagic/form": "1.2.
|
|
52
|
-
"@tmagic/schema": "1.2.
|
|
53
|
-
"@tmagic/stage": "1.2.
|
|
54
|
-
"@tmagic/utils": "1.2.
|
|
49
|
+
"@tmagic/core": "1.2.10",
|
|
50
|
+
"@tmagic/design": "1.2.10",
|
|
51
|
+
"@tmagic/form": "1.2.10",
|
|
52
|
+
"@tmagic/schema": "1.2.10",
|
|
53
|
+
"@tmagic/stage": "1.2.10",
|
|
54
|
+
"@tmagic/utils": "1.2.10",
|
|
55
55
|
"buffer": "^6.0.3",
|
|
56
56
|
"color": "^3.1.3",
|
|
57
57
|
"events": "^3.3.0",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"vue": "^3.2.37"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@tmagic/design": "1.2.
|
|
67
|
-
"@tmagic/form": "1.2.
|
|
66
|
+
"@tmagic/design": "1.2.10",
|
|
67
|
+
"@tmagic/form": "1.2.10",
|
|
68
68
|
"monaco-editor": "^0.34.0",
|
|
69
69
|
"vue": "^3.2.37"
|
|
70
70
|
},
|
package/src/Editor.vue
CHANGED
|
@@ -247,6 +247,10 @@ export default defineComponent({
|
|
|
247
247
|
if (toRaw(value) !== toRaw(preValue)) {
|
|
248
248
|
emit('update:modelValue', value);
|
|
249
249
|
}
|
|
250
|
+
|
|
251
|
+
value.codeBlocks = value.codeBlocks || {};
|
|
252
|
+
|
|
253
|
+
codeBlockService.setCodeDsl(value.codeBlocks);
|
|
250
254
|
};
|
|
251
255
|
|
|
252
256
|
editorService.on('root-change', rootChangeHandler);
|
|
@@ -136,7 +136,7 @@ watchEffect(() => {
|
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
const initTableModel = (): void => {
|
|
139
|
-
const codeDsl = cloneDeep(services?.codeBlockService.
|
|
139
|
+
const codeDsl = cloneDeep(services?.codeBlockService.getCodeDsl());
|
|
140
140
|
if (!codeDsl) return;
|
|
141
141
|
tableModel.value = {
|
|
142
142
|
params: codeDsl[props.id]?.params || [],
|
|
@@ -44,7 +44,7 @@ const props = defineProps<{
|
|
|
44
44
|
name: string;
|
|
45
45
|
size: 'mini' | 'small' | 'medium';
|
|
46
46
|
}>();
|
|
47
|
-
const codeDsl = computed(() => services?.codeBlockService.
|
|
47
|
+
const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
|
|
48
48
|
|
|
49
49
|
const tableConfig = computed<FormItem>(() => {
|
|
50
50
|
const defaultConfig = {
|
|
@@ -164,7 +164,7 @@ watch(
|
|
|
164
164
|
);
|
|
165
165
|
|
|
166
166
|
watch(
|
|
167
|
-
[() => services?.codeBlockService.
|
|
167
|
+
[() => services?.codeBlockService.getCodeDsl(), () => services?.codeBlockService.getCombineInfo()],
|
|
168
168
|
() => {
|
|
169
169
|
refreshCodeList();
|
|
170
170
|
},
|
|
@@ -41,8 +41,6 @@ class CodeBlock extends BaseService {
|
|
|
41
41
|
|
|
42
42
|
constructor() {
|
|
43
43
|
super([
|
|
44
|
-
'setCodeDsl',
|
|
45
|
-
'getCodeDsl',
|
|
46
44
|
'getCodeContentById',
|
|
47
45
|
'getCodeDslByIds',
|
|
48
46
|
'getCurrentDsl',
|
|
@@ -62,7 +60,6 @@ class CodeBlock extends BaseService {
|
|
|
62
60
|
*/
|
|
63
61
|
public async setCodeDsl(codeDsl: CodeBlockDSL): Promise<void> {
|
|
64
62
|
this.state.codeDsl = codeDsl;
|
|
65
|
-
await editorService.setCodeDsl(this.state.codeDsl);
|
|
66
63
|
info('[code-block]:code-dsl-change', this.state.codeDsl);
|
|
67
64
|
this.emit('code-dsl-change', this.state.codeDsl);
|
|
68
65
|
}
|
|
@@ -73,14 +70,7 @@ class CodeBlock extends BaseService {
|
|
|
73
70
|
* @param {boolean} forceRefresh 是否强制从活动dsl拉取刷新
|
|
74
71
|
* @returns {CodeBlockDSL | null}
|
|
75
72
|
*/
|
|
76
|
-
public
|
|
77
|
-
return this.getCodeDslSync(forceRefresh);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public getCodeDslSync(forceRefresh = false): CodeBlockDSL | null {
|
|
81
|
-
if (!this.state.codeDsl || forceRefresh) {
|
|
82
|
-
this.state.codeDsl = editorService.getCodeDslSync();
|
|
83
|
-
}
|
|
73
|
+
public getCodeDsl(): CodeBlockDSL | null {
|
|
84
74
|
return this.state.codeDsl;
|
|
85
75
|
}
|
|
86
76
|
|
|
@@ -103,31 +93,25 @@ class CodeBlock extends BaseService {
|
|
|
103
93
|
* @returns {void}
|
|
104
94
|
*/
|
|
105
95
|
public async setCodeDslById(id: Id, codeConfig: CodeBlockContent): Promise<void> {
|
|
106
|
-
|
|
96
|
+
const codeDsl = await this.getCodeDsl();
|
|
97
|
+
|
|
98
|
+
if (!codeDsl) {
|
|
99
|
+
throw new Error('dsl中没有codeBlocks');
|
|
100
|
+
}
|
|
101
|
+
|
|
107
102
|
const codeConfigProcessed = codeConfig;
|
|
108
103
|
if (codeConfig.content) {
|
|
109
104
|
// 在保存的时候转换代码内容
|
|
110
105
|
// eslint-disable-next-line no-eval
|
|
111
106
|
codeConfigProcessed.content = eval(codeConfig.content);
|
|
112
107
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
} else {
|
|
121
|
-
const existContent = codeDsl[id] || {};
|
|
122
|
-
codeDsl = {
|
|
123
|
-
...codeDsl,
|
|
124
|
-
[id]: {
|
|
125
|
-
...existContent,
|
|
126
|
-
...codeConfigProcessed,
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
await this.setCodeDsl(codeDsl);
|
|
108
|
+
|
|
109
|
+
const existContent = codeDsl[id] || {};
|
|
110
|
+
|
|
111
|
+
codeDsl[id] = {
|
|
112
|
+
...existContent,
|
|
113
|
+
...codeConfigProcessed,
|
|
114
|
+
};
|
|
131
115
|
}
|
|
132
116
|
|
|
133
117
|
/**
|
|
@@ -320,13 +304,15 @@ class CodeBlock extends BaseService {
|
|
|
320
304
|
/**
|
|
321
305
|
* 在dsl数据源中删除指定id的代码块
|
|
322
306
|
* @param {Id[]} codeIds 需要删除的代码块id数组
|
|
323
|
-
* @returns {CodeBlockDSL} 删除后的code dsl
|
|
324
307
|
*/
|
|
325
|
-
public async deleteCodeDslByIds(codeIds: Id[]): Promise<
|
|
308
|
+
public async deleteCodeDslByIds(codeIds: Id[]): Promise<void> {
|
|
326
309
|
const currentDsl = await this.getCodeDsl();
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
310
|
+
|
|
311
|
+
if (!currentDsl) return;
|
|
312
|
+
|
|
313
|
+
codeIds.forEach((id) => {
|
|
314
|
+
delete currentDsl[id];
|
|
315
|
+
});
|
|
330
316
|
}
|
|
331
317
|
|
|
332
318
|
/**
|
package/src/services/editor.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { reactive, toRaw } from 'vue';
|
|
20
20
|
import { cloneDeep, isObject, mergeWith, uniq } from 'lodash-es';
|
|
21
21
|
|
|
22
|
-
import type {
|
|
22
|
+
import type { Id, MApp, MComponent, MContainer, MNode, MPage } from '@tmagic/schema';
|
|
23
23
|
import { NodeType } from '@tmagic/schema';
|
|
24
24
|
import StageCore from '@tmagic/stage';
|
|
25
25
|
import { getNodePath, isNumber, isPage, isPop } from '@tmagic/utils';
|
|
@@ -80,8 +80,6 @@ class Editor extends BaseService {
|
|
|
80
80
|
'undo',
|
|
81
81
|
'redo',
|
|
82
82
|
'highlight',
|
|
83
|
-
'getCodeDsl',
|
|
84
|
-
'setCodeDsl',
|
|
85
83
|
],
|
|
86
84
|
// 需要注意循环依赖问题,如果函数间有相互调用的话,不能设置为串行调用
|
|
87
85
|
['select', 'update', 'moveLayer'],
|
|
@@ -832,30 +830,6 @@ class Editor extends BaseService {
|
|
|
832
830
|
this.get('modifiedNodeIds').clear();
|
|
833
831
|
}
|
|
834
832
|
|
|
835
|
-
/**
|
|
836
|
-
* 从dsl中的codeBlocks字段读取活动的代码块
|
|
837
|
-
* @returns {CodeBlockDSL | null}
|
|
838
|
-
*/
|
|
839
|
-
public async getCodeDsl(): Promise<CodeBlockDSL | null> {
|
|
840
|
-
const root = this.get('root');
|
|
841
|
-
return root?.codeBlocks || null;
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
public getCodeDslSync(): CodeBlockDSL | null {
|
|
845
|
-
const root = this.get('root');
|
|
846
|
-
return root?.codeBlocks || null;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
/**
|
|
850
|
-
* 设置代码块到dsl的codeBlocks字段
|
|
851
|
-
* @param {CodeBlockDSL} codeDsl 代码DSL
|
|
852
|
-
* @returns {void}
|
|
853
|
-
*/
|
|
854
|
-
public async setCodeDsl(codeDsl: CodeBlockDSL): Promise<void> {
|
|
855
|
-
if (!this.state.root) return;
|
|
856
|
-
this.state.root.codeBlocks = codeDsl;
|
|
857
|
-
}
|
|
858
|
-
|
|
859
833
|
private addModifiedNodeId(id: Id) {
|
|
860
834
|
if (!this.isHistoryStateChange) {
|
|
861
835
|
this.get('modifiedNodeIds').set(id, id);
|
|
@@ -16,8 +16,7 @@ declare class CodeBlock extends BaseService {
|
|
|
16
16
|
* @param {boolean} forceRefresh 是否强制从活动dsl拉取刷新
|
|
17
17
|
* @returns {CodeBlockDSL | null}
|
|
18
18
|
*/
|
|
19
|
-
getCodeDsl(
|
|
20
|
-
getCodeDslSync(forceRefresh?: boolean): CodeBlockDSL | null;
|
|
19
|
+
getCodeDsl(): CodeBlockDSL | null;
|
|
21
20
|
/**
|
|
22
21
|
* 根据代码块id获取代码块内容
|
|
23
22
|
* @param {Id} id 代码块id
|
|
@@ -134,9 +133,8 @@ declare class CodeBlock extends BaseService {
|
|
|
134
133
|
/**
|
|
135
134
|
* 在dsl数据源中删除指定id的代码块
|
|
136
135
|
* @param {Id[]} codeIds 需要删除的代码块id数组
|
|
137
|
-
* @returns {CodeBlockDSL} 删除后的code dsl
|
|
138
136
|
*/
|
|
139
|
-
deleteCodeDslByIds(codeIds: Id[]): Promise<
|
|
137
|
+
deleteCodeDslByIds(codeIds: Id[]): Promise<void>;
|
|
140
138
|
/**
|
|
141
139
|
* 生成代码块唯一id
|
|
142
140
|
* @returns {Id} 代码块唯一id
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Id, MContainer, MNode } from '@tmagic/schema';
|
|
2
2
|
import type { AddMNode, EditorNodeInfo, PastePosition, StepValue, StoreState, StoreStateKey } from '../type';
|
|
3
3
|
import { LayerOffset, Layout } from '../type';
|
|
4
4
|
import BaseService from './BaseService';
|
|
@@ -136,18 +136,6 @@ declare class Editor extends BaseService {
|
|
|
136
136
|
resetState(): void;
|
|
137
137
|
destroy(): void;
|
|
138
138
|
resetModifiedNodeId(): void;
|
|
139
|
-
/**
|
|
140
|
-
* 从dsl中的codeBlocks字段读取活动的代码块
|
|
141
|
-
* @returns {CodeBlockDSL | null}
|
|
142
|
-
*/
|
|
143
|
-
getCodeDsl(): Promise<CodeBlockDSL | null>;
|
|
144
|
-
getCodeDslSync(): CodeBlockDSL | null;
|
|
145
|
-
/**
|
|
146
|
-
* 设置代码块到dsl的codeBlocks字段
|
|
147
|
-
* @param {CodeBlockDSL} codeDsl 代码DSL
|
|
148
|
-
* @returns {void}
|
|
149
|
-
*/
|
|
150
|
-
setCodeDsl(codeDsl: CodeBlockDSL): Promise<void>;
|
|
151
139
|
private addModifiedNodeId;
|
|
152
140
|
private pushHistoryState;
|
|
153
141
|
private changeHistoryState;
|