@tmagic/editor 1.4.5 → 1.4.6
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 +2329 -2205
- package/dist/tmagic-editor.umd.cjs +2344 -2217
- package/package.json +19 -14
- package/src/editorProps.ts +5 -1
- package/src/hooks/use-code-block-edit.ts +0 -2
- package/src/hooks/use-stage.ts +1 -1
- package/src/index.ts +1 -0
- package/src/initService.ts +12 -2
- package/src/services/codeBlock.ts +77 -9
- package/src/services/dataSource.ts +53 -4
- package/src/services/props.ts +10 -5
- package/src/services/stageOverlay.ts +1 -0
- package/src/type.ts +1 -0
- package/src/utils/editor.ts +2 -0
- package/types/editorProps.d.ts +5 -1
- package/types/index.d.ts +1 -0
- package/types/layouts/PropsPanel.vue.d.ts +24 -24
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +1 -1
- package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +1 -1
- package/types/services/codeBlock.d.ts +22 -2
- package/types/services/dataSource.d.ts +12 -1
- package/types/type.d.ts +1 -0
- package/types/utils/editor.d.ts +2 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.6",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -50,18 +50,8 @@
|
|
|
50
50
|
"lodash-es": "^4.17.21",
|
|
51
51
|
"moveable": "^0.53.0",
|
|
52
52
|
"serialize-javascript": "^6.0.0",
|
|
53
|
-
"@tmagic/dep": "1.4.
|
|
54
|
-
"@tmagic/table": "1.4.
|
|
55
|
-
},
|
|
56
|
-
"peerDependencies": {
|
|
57
|
-
"monaco-editor": "^0.48.0",
|
|
58
|
-
"vue": "^3.4.27",
|
|
59
|
-
"@tmagic/design": "1.4.5",
|
|
60
|
-
"@tmagic/form": "1.4.5",
|
|
61
|
-
"@tmagic/schema": "1.4.5",
|
|
62
|
-
"@tmagic/stage": "1.4.5",
|
|
63
|
-
"@tmagic/utils": "1.4.5",
|
|
64
|
-
"@tmagic/core": "1.4.5"
|
|
53
|
+
"@tmagic/dep": "1.4.6",
|
|
54
|
+
"@tmagic/table": "1.4.6"
|
|
65
55
|
},
|
|
66
56
|
"devDependencies": {
|
|
67
57
|
"@types/events": "^3.0.0",
|
|
@@ -75,10 +65,25 @@
|
|
|
75
65
|
"sass": "^1.77.0",
|
|
76
66
|
"tsc-alias": "^1.8.5",
|
|
77
67
|
"type-fest": "^4.10.3",
|
|
78
|
-
"typescript": "^5.4.2",
|
|
79
68
|
"vite": "^5.2.11",
|
|
80
69
|
"vue-tsc": "^2.0.16"
|
|
81
70
|
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"monaco-editor": "^0.48.0",
|
|
73
|
+
"vue": "^3.4.27",
|
|
74
|
+
"typescript": "*",
|
|
75
|
+
"@tmagic/form": "1.4.6",
|
|
76
|
+
"@tmagic/schema": "1.4.6",
|
|
77
|
+
"@tmagic/design": "1.4.6",
|
|
78
|
+
"@tmagic/core": "1.4.6",
|
|
79
|
+
"@tmagic/utils": "1.4.6",
|
|
80
|
+
"@tmagic/stage": "1.4.6"
|
|
81
|
+
},
|
|
82
|
+
"peerDependenciesMeta": {
|
|
83
|
+
"typescript": {
|
|
84
|
+
"optional": true
|
|
85
|
+
}
|
|
86
|
+
},
|
|
82
87
|
"scripts": {
|
|
83
88
|
"build": "npm run build:type && vite build",
|
|
84
89
|
"build:type": "npm run clear:type && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
package/src/editorProps.ts
CHANGED
|
@@ -70,8 +70,12 @@ export interface EditorProps {
|
|
|
70
70
|
codeOptions?: { [key: string]: any };
|
|
71
71
|
/** 禁用鼠标左键按下时就开始拖拽,需要先选中再可以拖拽 */
|
|
72
72
|
disabledDragStart?: boolean;
|
|
73
|
-
/**
|
|
73
|
+
/** 自定义依赖收集器,复制组件时会将关联组件一并复制 */
|
|
74
74
|
collectorOptions?: CustomTargetOptions;
|
|
75
|
+
/** 自定义依赖收集器,复制组件时会将关联代码块一并复制 */
|
|
76
|
+
collectorOptionsForCode?: CustomTargetOptions;
|
|
77
|
+
/** 自定义依赖收集器,复制组件时会将关联数据源一并复制 */
|
|
78
|
+
collectorOptionsForDataSource?: CustomTargetOptions;
|
|
75
79
|
/** 标尺配置 */
|
|
76
80
|
guidesOptions?: Partial<GuidesOptions>;
|
|
77
81
|
/** 禁止多选 */
|
package/src/hooks/use-stage.ts
CHANGED
|
@@ -24,7 +24,7 @@ export const useStage = (stageOptions: StageOptions) => {
|
|
|
24
24
|
const stage = new StageCore({
|
|
25
25
|
render: stageOptions.render,
|
|
26
26
|
runtimeUrl: stageOptions.runtimeUrl,
|
|
27
|
-
zoom: zoom.value,
|
|
27
|
+
zoom: stageOptions.zoom ?? zoom.value,
|
|
28
28
|
autoScrollIntoView: stageOptions.autoScrollIntoView,
|
|
29
29
|
isContainer: stageOptions.isContainer,
|
|
30
30
|
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
package/src/index.ts
CHANGED
|
@@ -82,6 +82,7 @@ export { default as LayoutContainer } from './components/SplitView.vue';
|
|
|
82
82
|
export { default as SplitView } from './components/SplitView.vue';
|
|
83
83
|
export { default as Resizer } from './components/Resizer.vue';
|
|
84
84
|
export { default as CodeBlockEditor } from './components/CodeBlockEditor.vue';
|
|
85
|
+
export { default as FloatingBox } from './components/FloatingBox.vue';
|
|
85
86
|
export { default as PageFragmentSelect } from './fields/PageFragmentSelect.vue';
|
|
86
87
|
|
|
87
88
|
const defaultInstallOpt: InstallOptions = {
|
package/src/initService.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
createDataSourceCondTarget,
|
|
8
8
|
createDataSourceMethodTarget,
|
|
9
9
|
createDataSourceTarget,
|
|
10
|
-
|
|
10
|
+
createRelatedTargetForCopy,
|
|
11
11
|
DepTargetType,
|
|
12
12
|
Target,
|
|
13
13
|
} from '@tmagic/dep';
|
|
@@ -412,7 +412,17 @@ export const initServiceEvents = (
|
|
|
412
412
|
|
|
413
413
|
// 初始化复制组件相关的依赖收集器
|
|
414
414
|
if (props.collectorOptions && !depService.hasTarget(DepTargetType.RELATED_COMP_WHEN_COPY)) {
|
|
415
|
-
depService.addTarget(
|
|
415
|
+
depService.addTarget(createRelatedTargetForCopy(props.collectorOptions, DepTargetType.RELATED_COMP_WHEN_COPY));
|
|
416
|
+
}
|
|
417
|
+
if (props.collectorOptionsForCode && !depService.hasTarget(DepTargetType.RELATED_CODE_WHEN_COPY)) {
|
|
418
|
+
depService.addTarget(
|
|
419
|
+
createRelatedTargetForCopy(props.collectorOptionsForCode, DepTargetType.RELATED_CODE_WHEN_COPY),
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
if (props.collectorOptionsForDataSource && !depService.hasTarget(DepTargetType.RELATED_DS_WHEN_COPY)) {
|
|
423
|
+
depService.addTarget(
|
|
424
|
+
createRelatedTargetForCopy(props.collectorOptionsForDataSource, DepTargetType.RELATED_DS_WHEN_COPY),
|
|
425
|
+
);
|
|
416
426
|
}
|
|
417
427
|
|
|
418
428
|
onBeforeUnmount(() => {
|
|
@@ -17,21 +17,26 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { reactive } from 'vue';
|
|
20
|
-
import { keys, pick } from 'lodash-es';
|
|
20
|
+
import { cloneDeep, get, keys, pick } from 'lodash-es';
|
|
21
21
|
import type { Writable } from 'type-fest';
|
|
22
22
|
|
|
23
|
+
import { DepTargetType } from '@tmagic/dep';
|
|
23
24
|
import type { ColumnConfig } from '@tmagic/form';
|
|
24
|
-
import type { CodeBlockContent, CodeBlockDSL, Id } from '@tmagic/schema';
|
|
25
|
+
import type { CodeBlockContent, CodeBlockDSL, Id, MNode } from '@tmagic/schema';
|
|
25
26
|
|
|
27
|
+
import depService from '@editor/services/dep';
|
|
28
|
+
import editorService from '@editor/services/editor';
|
|
29
|
+
import storageService, { Protocol } from '@editor/services/storage';
|
|
26
30
|
import type { AsyncHookPlugin, CodeState } from '@editor/type';
|
|
27
31
|
import { CODE_DRAFT_STORAGE_KEY } from '@editor/type';
|
|
28
32
|
import { getConfig } from '@editor/utils/config';
|
|
33
|
+
import { COPY_CODE_STORAGE_KEY } from '@editor/utils/editor';
|
|
29
34
|
|
|
30
35
|
import BaseService from './BaseService';
|
|
31
36
|
|
|
32
37
|
const canUsePluginMethods = {
|
|
33
38
|
async: ['setCodeDslById', 'setEditStatus', 'setCombineIds', 'setUndeleteableList', 'deleteCodeDslByIds'] as const,
|
|
34
|
-
sync: [],
|
|
39
|
+
sync: ['setCodeDslByIdSync'],
|
|
35
40
|
};
|
|
36
41
|
|
|
37
42
|
type AsyncMethodName = Writable<(typeof canUsePluginMethods)['async']>;
|
|
@@ -46,7 +51,10 @@ class CodeBlock extends BaseService {
|
|
|
46
51
|
});
|
|
47
52
|
|
|
48
53
|
constructor() {
|
|
49
|
-
super(
|
|
54
|
+
super([
|
|
55
|
+
...canUsePluginMethods.async.map((methodName) => ({ name: methodName, isAsync: true })),
|
|
56
|
+
...canUsePluginMethods.sync.map((methodName) => ({ name: methodName, isAsync: false })),
|
|
57
|
+
]);
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
/**
|
|
@@ -88,20 +96,32 @@ class CodeBlock extends BaseService {
|
|
|
88
96
|
* @returns {void}
|
|
89
97
|
*/
|
|
90
98
|
public async setCodeDslById(id: Id, codeConfig: Partial<CodeBlockContent>): Promise<void> {
|
|
99
|
+
this.setCodeDslByIdSync(id, codeConfig, true);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 为了兼容历史原因
|
|
104
|
+
* 设置代码块ID和代码内容到源dsl
|
|
105
|
+
* @param {Id} id 代码块id
|
|
106
|
+
* @param {CodeBlockContent} codeConfig 代码块内容配置信息
|
|
107
|
+
* @param {boolean} force 是否强制写入,默认true
|
|
108
|
+
* @returns {void}
|
|
109
|
+
*/
|
|
110
|
+
public setCodeDslByIdSync(id: Id, codeConfig: Partial<CodeBlockContent>, force = true): void {
|
|
91
111
|
const codeDsl = this.getCodeDsl();
|
|
92
112
|
|
|
93
113
|
if (!codeDsl) {
|
|
94
114
|
throw new Error('dsl中没有codeBlocks');
|
|
95
115
|
}
|
|
116
|
+
if (codeDsl[id] && !force) return;
|
|
96
117
|
|
|
97
|
-
const codeConfigProcessed = codeConfig;
|
|
98
|
-
if (
|
|
118
|
+
const codeConfigProcessed = cloneDeep(codeConfig);
|
|
119
|
+
if (codeConfigProcessed.content) {
|
|
99
120
|
// 在保存的时候转换代码内容
|
|
100
121
|
const parseDSL = getConfig('parseDSL');
|
|
101
|
-
if (typeof
|
|
102
|
-
|
|
122
|
+
if (typeof codeConfigProcessed.content === 'string') {
|
|
123
|
+
codeConfigProcessed.content = parseDSL<(...args: any[]) => any>(codeConfigProcessed.content);
|
|
103
124
|
}
|
|
104
|
-
codeConfigProcessed.content = codeConfig.content;
|
|
105
125
|
}
|
|
106
126
|
|
|
107
127
|
const existContent = codeDsl[id] || {};
|
|
@@ -233,6 +253,54 @@ class CodeBlock extends BaseService {
|
|
|
233
253
|
return await this.getUniqueId();
|
|
234
254
|
}
|
|
235
255
|
|
|
256
|
+
/**
|
|
257
|
+
* 复制时会带上组件关联的代码块
|
|
258
|
+
* @param config 组件节点配置
|
|
259
|
+
* @returns
|
|
260
|
+
*/
|
|
261
|
+
public copyWithRelated(config: MNode | MNode[]): void {
|
|
262
|
+
const copyNodes: MNode[] = Array.isArray(config) ? config : [config];
|
|
263
|
+
// 关联的代码块也一并复制
|
|
264
|
+
depService.clearByType(DepTargetType.RELATED_CODE_WHEN_COPY);
|
|
265
|
+
depService.collect(copyNodes, true, DepTargetType.RELATED_CODE_WHEN_COPY);
|
|
266
|
+
const customTarget = depService.getTarget(
|
|
267
|
+
DepTargetType.RELATED_CODE_WHEN_COPY,
|
|
268
|
+
DepTargetType.RELATED_CODE_WHEN_COPY,
|
|
269
|
+
);
|
|
270
|
+
const copyData: CodeBlockDSL = {};
|
|
271
|
+
if (customTarget) {
|
|
272
|
+
Object.keys(customTarget.deps).forEach((nodeId: Id) => {
|
|
273
|
+
const node = editorService.getNodeById(nodeId);
|
|
274
|
+
if (!node) return;
|
|
275
|
+
customTarget!.deps[nodeId].keys.forEach((key) => {
|
|
276
|
+
const relateCodeId = get(node, key);
|
|
277
|
+
const isExist = Object.keys(copyData).find((codeId: Id) => codeId === relateCodeId);
|
|
278
|
+
if (!isExist) {
|
|
279
|
+
const relateCode = this.getCodeContentById(relateCodeId);
|
|
280
|
+
if (relateCode) {
|
|
281
|
+
copyData[relateCodeId] = relateCode;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
storageService.setItem(COPY_CODE_STORAGE_KEY, copyData, {
|
|
288
|
+
protocol: Protocol.OBJECT,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* 粘贴代码块
|
|
294
|
+
* @returns
|
|
295
|
+
*/
|
|
296
|
+
public paste() {
|
|
297
|
+
const codeDsl: CodeBlockDSL = storageService.getItem(COPY_CODE_STORAGE_KEY);
|
|
298
|
+
Object.keys(codeDsl).forEach((codeId: Id) => {
|
|
299
|
+
// 不覆盖同样id的代码块
|
|
300
|
+
this.setCodeDslByIdSync(codeId, codeDsl[codeId], false);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
236
304
|
public resetState() {
|
|
237
305
|
this.state.codeDsl = null;
|
|
238
306
|
this.state.editable = true;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { reactive } from 'vue';
|
|
2
|
-
import { cloneDeep } from 'lodash-es';
|
|
2
|
+
import { cloneDeep, get } from 'lodash-es';
|
|
3
3
|
import { Writable } from 'type-fest';
|
|
4
4
|
|
|
5
5
|
import type { EventOption } from '@tmagic/core';
|
|
6
|
+
import { DepTargetType } from '@tmagic/dep';
|
|
6
7
|
import type { FormConfig } from '@tmagic/form';
|
|
7
|
-
import type { DataSourceSchema } from '@tmagic/schema';
|
|
8
|
+
import type { DataSourceSchema, Id, MNode } from '@tmagic/schema';
|
|
8
9
|
import { guid, toLine } from '@tmagic/utils';
|
|
9
10
|
|
|
11
|
+
import depService from '@editor/services/dep';
|
|
12
|
+
import editorService from '@editor/services/editor';
|
|
13
|
+
import storageService, { Protocol } from '@editor/services/storage';
|
|
10
14
|
import type { DatasourceTypeOption, SyncHookPlugin } from '@editor/type';
|
|
11
15
|
import { getFormConfig, getFormValue } from '@editor/utils/data-source';
|
|
16
|
+
import { COPY_DS_STORAGE_KEY } from '@editor/utils/editor';
|
|
12
17
|
|
|
13
18
|
import BaseService from './BaseService';
|
|
14
19
|
|
|
@@ -102,7 +107,7 @@ class DataSource extends BaseService {
|
|
|
102
107
|
public add(config: DataSourceSchema) {
|
|
103
108
|
const newConfig = {
|
|
104
109
|
...config,
|
|
105
|
-
id: this.createId(),
|
|
110
|
+
id: config.id && !this.getDataSourceById(config.id) ? config.id : this.createId(),
|
|
106
111
|
};
|
|
107
112
|
|
|
108
113
|
this.get('dataSources').push(newConfig);
|
|
@@ -116,7 +121,6 @@ class DataSource extends BaseService {
|
|
|
116
121
|
const dataSources = this.get('dataSources');
|
|
117
122
|
|
|
118
123
|
const index = dataSources.findIndex((ds) => ds.id === config.id);
|
|
119
|
-
|
|
120
124
|
dataSources[index] = cloneDeep(config);
|
|
121
125
|
|
|
122
126
|
this.emit('update', config);
|
|
@@ -153,6 +157,51 @@ class DataSource extends BaseService {
|
|
|
153
157
|
public usePlugin(options: SyncHookPlugin<SyncMethodName, DataSource>): void {
|
|
154
158
|
super.usePlugin(options);
|
|
155
159
|
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 复制时会带上组件关联的数据源
|
|
163
|
+
* @param config 组件节点配置
|
|
164
|
+
* @returns
|
|
165
|
+
*/
|
|
166
|
+
public copyWithRelated(config: MNode | MNode[]): void {
|
|
167
|
+
const copyNodes: MNode[] = Array.isArray(config) ? config : [config];
|
|
168
|
+
depService.clearByType(DepTargetType.RELATED_DS_WHEN_COPY);
|
|
169
|
+
depService.collect(copyNodes, true, DepTargetType.RELATED_DS_WHEN_COPY);
|
|
170
|
+
const customTarget = depService.getTarget(DepTargetType.RELATED_DS_WHEN_COPY, DepTargetType.RELATED_DS_WHEN_COPY);
|
|
171
|
+
const copyData: DataSourceSchema[] = [];
|
|
172
|
+
if (customTarget) {
|
|
173
|
+
Object.keys(customTarget.deps).forEach((nodeId: Id) => {
|
|
174
|
+
const node = editorService.getNodeById(nodeId);
|
|
175
|
+
if (!node) return;
|
|
176
|
+
customTarget!.deps[nodeId].keys.forEach((key) => {
|
|
177
|
+
const [relateDsId] = get(node, key);
|
|
178
|
+
const isExist = copyData.find((dsItem) => dsItem.id === relateDsId);
|
|
179
|
+
if (!isExist) {
|
|
180
|
+
const relateDs = this.getDataSourceById(relateDsId);
|
|
181
|
+
if (relateDs) {
|
|
182
|
+
copyData.push(relateDs);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
storageService.setItem(COPY_DS_STORAGE_KEY, copyData, {
|
|
189
|
+
protocol: Protocol.OBJECT,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 粘贴数据源
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
196
|
+
public paste() {
|
|
197
|
+
const dataSource: DataSourceSchema[] = storageService.getItem(COPY_DS_STORAGE_KEY);
|
|
198
|
+
dataSource.forEach((item: DataSourceSchema) => {
|
|
199
|
+
// 不覆盖同样id的数据源
|
|
200
|
+
if (!this.getDataSourceById(item.id)) {
|
|
201
|
+
this.add(item);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
156
205
|
}
|
|
157
206
|
|
|
158
207
|
export type DataSourceService = DataSource;
|
package/src/services/props.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { Writable } from 'type-fest';
|
|
|
23
23
|
import { DepTargetType } from '@tmagic/dep';
|
|
24
24
|
import type { FormConfig } from '@tmagic/form';
|
|
25
25
|
import type { Id, MComponent, MNode } from '@tmagic/schema';
|
|
26
|
-
import { getValueByKeyPath, guid, setValueByKeyPath, toLine } from '@tmagic/utils';
|
|
26
|
+
import { getNodePath, getValueByKeyPath, guid, setValueByKeyPath, toLine } from '@tmagic/utils';
|
|
27
27
|
|
|
28
28
|
import depService from '@editor/services/dep';
|
|
29
29
|
import editorService from '@editor/services/editor';
|
|
@@ -199,13 +199,14 @@ class Props extends BaseService {
|
|
|
199
199
|
public replaceRelateId(originConfigs: MNode[], targetConfigs: MNode[]) {
|
|
200
200
|
const relateIdMap = this.getRelateIdMap();
|
|
201
201
|
if (Object.keys(relateIdMap).length === 0) return;
|
|
202
|
-
|
|
202
|
+
depService.clearByType(DepTargetType.RELATED_COMP_WHEN_COPY);
|
|
203
|
+
depService.collect(originConfigs, true, DepTargetType.RELATED_COMP_WHEN_COPY);
|
|
203
204
|
const target = depService.getTarget(DepTargetType.RELATED_COMP_WHEN_COPY, DepTargetType.RELATED_COMP_WHEN_COPY);
|
|
204
205
|
if (!target) return;
|
|
205
|
-
|
|
206
206
|
originConfigs.forEach((config: MNode) => {
|
|
207
207
|
const newId = relateIdMap[config.id];
|
|
208
|
-
const
|
|
208
|
+
const path = getNodePath(newId, targetConfigs);
|
|
209
|
+
const targetConfig = path[path.length - 1];
|
|
209
210
|
|
|
210
211
|
if (!targetConfig) return;
|
|
211
212
|
|
|
@@ -213,9 +214,13 @@ class Props extends BaseService {
|
|
|
213
214
|
const relateOriginId = getValueByKeyPath(fullKey, config);
|
|
214
215
|
const relateTargetId = relateIdMap[relateOriginId];
|
|
215
216
|
if (!relateTargetId) return;
|
|
216
|
-
|
|
217
217
|
setValueByKeyPath(fullKey, relateTargetId, targetConfig);
|
|
218
218
|
});
|
|
219
|
+
|
|
220
|
+
// 递归items
|
|
221
|
+
if (config.items && Array.isArray(config.items)) {
|
|
222
|
+
this.replaceRelateId(config.items, targetConfigs);
|
|
223
|
+
}
|
|
219
224
|
});
|
|
220
225
|
}
|
|
221
226
|
|
package/src/type.ts
CHANGED
package/src/utils/editor.ts
CHANGED
|
@@ -25,6 +25,8 @@ import { calcValueByFontsize, getNodePath, isNumber, isPage, isPageFragment, isP
|
|
|
25
25
|
|
|
26
26
|
import { Layout } from '@editor/type';
|
|
27
27
|
export const COPY_STORAGE_KEY = '$MagicEditorCopyData';
|
|
28
|
+
export const COPY_CODE_STORAGE_KEY = '$MagicEditorCopyCode';
|
|
29
|
+
export const COPY_DS_STORAGE_KEY = '$MagicEditorCopyDataSource';
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* 获取所有页面配置
|
package/types/editorProps.d.ts
CHANGED
|
@@ -60,8 +60,12 @@ export interface EditorProps {
|
|
|
60
60
|
};
|
|
61
61
|
/** 禁用鼠标左键按下时就开始拖拽,需要先选中再可以拖拽 */
|
|
62
62
|
disabledDragStart?: boolean;
|
|
63
|
-
/**
|
|
63
|
+
/** 自定义依赖收集器,复制组件时会将关联组件一并复制 */
|
|
64
64
|
collectorOptions?: CustomTargetOptions;
|
|
65
|
+
/** 自定义依赖收集器,复制组件时会将关联代码块一并复制 */
|
|
66
|
+
collectorOptionsForCode?: CustomTargetOptions;
|
|
67
|
+
/** 自定义依赖收集器,复制组件时会将关联数据源一并复制 */
|
|
68
|
+
collectorOptionsForDataSource?: CustomTargetOptions;
|
|
65
69
|
/** 标尺配置 */
|
|
66
70
|
guidesOptions?: Partial<GuidesOptions>;
|
|
67
71
|
/** 禁止多选 */
|
package/types/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export { default as LayoutContainer } from './components/SplitView.vue';
|
|
|
43
43
|
export { default as SplitView } from './components/SplitView.vue';
|
|
44
44
|
export { default as Resizer } from './components/Resizer.vue';
|
|
45
45
|
export { default as CodeBlockEditor } from './components/CodeBlockEditor.vue';
|
|
46
|
+
export { default as FloatingBox } from './components/FloatingBox.vue';
|
|
46
47
|
export { default as PageFragmentSelect } from './fields/PageFragmentSelect.vue';
|
|
47
48
|
declare const _default: {
|
|
48
49
|
install: (app: App, opt?: Partial<InstallOptions>) => void;
|
|
@@ -5,14 +5,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
5
5
|
extendState?: ((state: FormState) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
6
6
|
}>, {
|
|
7
7
|
configForm: import("vue").Ref<import("vue").CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
|
|
8
|
-
labelWidth: {
|
|
9
|
-
type: import("vue").PropType<string>;
|
|
10
|
-
default: string;
|
|
11
|
-
};
|
|
12
|
-
disabled: {
|
|
13
|
-
type: import("vue").PropType<boolean>;
|
|
14
|
-
default: boolean;
|
|
15
|
-
};
|
|
16
8
|
size: {
|
|
17
9
|
type: import("vue").PropType<"default" | "small" | "large">;
|
|
18
10
|
};
|
|
@@ -23,11 +15,19 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
23
15
|
type: import("vue").PropType<string>;
|
|
24
16
|
default: string;
|
|
25
17
|
};
|
|
18
|
+
disabled: {
|
|
19
|
+
type: import("vue").PropType<boolean>;
|
|
20
|
+
default: boolean;
|
|
21
|
+
};
|
|
26
22
|
config: {
|
|
27
23
|
type: import("vue").PropType<import("@tmagic/form").FormConfig>;
|
|
28
24
|
required: true;
|
|
29
25
|
default: () => never[];
|
|
30
26
|
};
|
|
27
|
+
labelWidth: {
|
|
28
|
+
type: import("vue").PropType<string>;
|
|
29
|
+
default: string;
|
|
30
|
+
};
|
|
31
31
|
initValues: {
|
|
32
32
|
type: import("vue").PropType<Record<string, any>>;
|
|
33
33
|
required: true;
|
|
@@ -83,14 +83,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
83
83
|
"field-input": (...args: any[]) => void;
|
|
84
84
|
"field-change": (...args: any[]) => void;
|
|
85
85
|
}, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
86
|
-
labelWidth: {
|
|
87
|
-
type: import("vue").PropType<string>;
|
|
88
|
-
default: string;
|
|
89
|
-
};
|
|
90
|
-
disabled: {
|
|
91
|
-
type: import("vue").PropType<boolean>;
|
|
92
|
-
default: boolean;
|
|
93
|
-
};
|
|
94
86
|
size: {
|
|
95
87
|
type: import("vue").PropType<"default" | "small" | "large">;
|
|
96
88
|
};
|
|
@@ -101,11 +93,19 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
101
93
|
type: import("vue").PropType<string>;
|
|
102
94
|
default: string;
|
|
103
95
|
};
|
|
96
|
+
disabled: {
|
|
97
|
+
type: import("vue").PropType<boolean>;
|
|
98
|
+
default: boolean;
|
|
99
|
+
};
|
|
104
100
|
config: {
|
|
105
101
|
type: import("vue").PropType<import("@tmagic/form").FormConfig>;
|
|
106
102
|
required: true;
|
|
107
103
|
default: () => never[];
|
|
108
104
|
};
|
|
105
|
+
labelWidth: {
|
|
106
|
+
type: import("vue").PropType<string>;
|
|
107
|
+
default: string;
|
|
108
|
+
};
|
|
109
109
|
initValues: {
|
|
110
110
|
type: import("vue").PropType<Record<string, any>>;
|
|
111
111
|
required: true;
|
|
@@ -168,14 +168,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
168
168
|
M: {};
|
|
169
169
|
Defaults: {};
|
|
170
170
|
}, Readonly<import("vue").ExtractPropTypes<{
|
|
171
|
-
labelWidth: {
|
|
172
|
-
type: import("vue").PropType<string>;
|
|
173
|
-
default: string;
|
|
174
|
-
};
|
|
175
|
-
disabled: {
|
|
176
|
-
type: import("vue").PropType<boolean>;
|
|
177
|
-
default: boolean;
|
|
178
|
-
};
|
|
179
171
|
size: {
|
|
180
172
|
type: import("vue").PropType<"default" | "small" | "large">;
|
|
181
173
|
};
|
|
@@ -186,11 +178,19 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
186
178
|
type: import("vue").PropType<string>;
|
|
187
179
|
default: string;
|
|
188
180
|
};
|
|
181
|
+
disabled: {
|
|
182
|
+
type: import("vue").PropType<boolean>;
|
|
183
|
+
default: boolean;
|
|
184
|
+
};
|
|
189
185
|
config: {
|
|
190
186
|
type: import("vue").PropType<import("@tmagic/form").FormConfig>;
|
|
191
187
|
required: true;
|
|
192
188
|
default: () => never[];
|
|
193
189
|
};
|
|
190
|
+
labelWidth: {
|
|
191
|
+
type: import("vue").PropType<string>;
|
|
192
|
+
default: string;
|
|
193
|
+
};
|
|
194
194
|
initValues: {
|
|
195
195
|
type: import("vue").PropType<Record<string, any>>;
|
|
196
196
|
required: true;
|
|
@@ -10,8 +10,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
10
10
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<{
|
|
11
11
|
customError?: ((id: Id, errorType: CodeDeleteErrorType) => any) | undefined;
|
|
12
12
|
}>>> & {
|
|
13
|
-
onEdit?: ((id: string) => any) | undefined;
|
|
14
13
|
onRemove?: ((id: string) => any) | undefined;
|
|
14
|
+
onEdit?: ((id: string) => any) | undefined;
|
|
15
15
|
}, {}, {}>, Readonly<CodeBlockListSlots> & CodeBlockListSlots>;
|
|
16
16
|
export default _default;
|
|
17
17
|
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
@@ -5,8 +5,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}
|
|
|
5
5
|
remove: (id: string) => void;
|
|
6
6
|
edit: (id: string) => void;
|
|
7
7
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>> & {
|
|
8
|
-
onEdit?: ((id: string) => any) | undefined;
|
|
9
8
|
onRemove?: ((id: string) => any) | undefined;
|
|
9
|
+
onEdit?: ((id: string) => any) | undefined;
|
|
10
10
|
}, {}, {}>, Readonly<DataSourceListSlots> & DataSourceListSlots>;
|
|
11
11
|
export default _default;
|
|
12
12
|
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Writable } from 'type-fest';
|
|
2
2
|
import type { ColumnConfig } from '@tmagic/form';
|
|
3
|
-
import type { CodeBlockContent, CodeBlockDSL, Id } from '@tmagic/schema';
|
|
3
|
+
import type { CodeBlockContent, CodeBlockDSL, Id, MNode } from '@tmagic/schema';
|
|
4
4
|
import type { AsyncHookPlugin } from '../type';
|
|
5
5
|
import BaseService from './BaseService';
|
|
6
6
|
declare const canUsePluginMethods: {
|
|
7
7
|
async: readonly ["setCodeDslById", "setEditStatus", "setCombineIds", "setUndeleteableList", "deleteCodeDslByIds"];
|
|
8
|
-
sync:
|
|
8
|
+
sync: string[];
|
|
9
9
|
};
|
|
10
10
|
type AsyncMethodName = Writable<(typeof canUsePluginMethods)['async']>;
|
|
11
11
|
declare class CodeBlock extends BaseService {
|
|
@@ -37,6 +37,15 @@ declare class CodeBlock extends BaseService {
|
|
|
37
37
|
* @returns {void}
|
|
38
38
|
*/
|
|
39
39
|
setCodeDslById(id: Id, codeConfig: Partial<CodeBlockContent>): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* 为了兼容历史原因
|
|
42
|
+
* 设置代码块ID和代码内容到源dsl
|
|
43
|
+
* @param {Id} id 代码块id
|
|
44
|
+
* @param {CodeBlockContent} codeConfig 代码块内容配置信息
|
|
45
|
+
* @param {boolean} force 是否强制写入,默认true
|
|
46
|
+
* @returns {void}
|
|
47
|
+
*/
|
|
48
|
+
setCodeDslByIdSync(id: Id, codeConfig: Partial<CodeBlockContent>, force?: boolean): void;
|
|
40
49
|
/**
|
|
41
50
|
* 根据代码块id数组获取代码dsl
|
|
42
51
|
* @param {string[]} ids 代码块id数组
|
|
@@ -100,6 +109,17 @@ declare class CodeBlock extends BaseService {
|
|
|
100
109
|
* @returns {Id} 代码块唯一id
|
|
101
110
|
*/
|
|
102
111
|
getUniqueId(): Promise<string>;
|
|
112
|
+
/**
|
|
113
|
+
* 复制时会带上组件关联的代码块
|
|
114
|
+
* @param config 组件节点配置
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
copyWithRelated(config: MNode | MNode[]): void;
|
|
118
|
+
/**
|
|
119
|
+
* 粘贴代码块
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
paste(): void;
|
|
103
123
|
resetState(): void;
|
|
104
124
|
destroy(): void;
|
|
105
125
|
usePlugin(options: AsyncHookPlugin<AsyncMethodName, CodeBlock>): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Writable } from 'type-fest';
|
|
2
2
|
import type { EventOption } from '@tmagic/core';
|
|
3
3
|
import type { FormConfig } from '@tmagic/form';
|
|
4
|
-
import type { DataSourceSchema } from '@tmagic/schema';
|
|
4
|
+
import type { DataSourceSchema, MNode } from '@tmagic/schema';
|
|
5
5
|
import type { DatasourceTypeOption, SyncHookPlugin } from '../type';
|
|
6
6
|
import BaseService from './BaseService';
|
|
7
7
|
interface State {
|
|
@@ -50,6 +50,17 @@ declare class DataSource extends BaseService {
|
|
|
50
50
|
resetState(): void;
|
|
51
51
|
destroy(): void;
|
|
52
52
|
usePlugin(options: SyncHookPlugin<SyncMethodName, DataSource>): void;
|
|
53
|
+
/**
|
|
54
|
+
* 复制时会带上组件关联的数据源
|
|
55
|
+
* @param config 组件节点配置
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
copyWithRelated(config: MNode | MNode[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* 粘贴数据源
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
paste(): void;
|
|
53
64
|
}
|
|
54
65
|
export type DataSourceService = DataSource;
|
|
55
66
|
declare const _default: DataSource;
|
package/types/type.d.ts
CHANGED
package/types/utils/editor.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { NodeType } from '@tmagic/schema';
|
|
|
3
3
|
import type StageCore from '@tmagic/stage';
|
|
4
4
|
import { Layout } from '../type';
|
|
5
5
|
export declare const COPY_STORAGE_KEY = "$MagicEditorCopyData";
|
|
6
|
+
export declare const COPY_CODE_STORAGE_KEY = "$MagicEditorCopyCode";
|
|
7
|
+
export declare const COPY_DS_STORAGE_KEY = "$MagicEditorCopyDataSource";
|
|
6
8
|
/**
|
|
7
9
|
* 获取所有页面配置
|
|
8
10
|
* @param root DSL跟节点
|