@tmagic/editor 1.3.0-alpha.0 → 1.3.0-alpha.2
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 +57 -3
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +56 -1
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +10 -10
- package/src/fields/DataSourceFields.vue +1 -1
- package/src/index.ts +1 -0
- package/src/initService.ts +67 -0
- package/src/services/dep.ts +3 -0
- package/types/index.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.0-alpha.
|
|
2
|
+
"version": "1.3.0-alpha.2",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@babel/core": "^7.18.0",
|
|
48
48
|
"@element-plus/icons-vue": "^2.0.9",
|
|
49
|
-
"@tmagic/core": "1.3.0-alpha.
|
|
50
|
-
"@tmagic/design": "1.3.0-alpha.
|
|
51
|
-
"@tmagic/form": "1.3.0-alpha.
|
|
52
|
-
"@tmagic/schema": "1.3.0-alpha.
|
|
53
|
-
"@tmagic/stage": "1.3.0-alpha.
|
|
54
|
-
"@tmagic/table": "1.3.0-alpha.
|
|
55
|
-
"@tmagic/utils": "1.3.0-alpha.
|
|
49
|
+
"@tmagic/core": "1.3.0-alpha.2",
|
|
50
|
+
"@tmagic/design": "1.3.0-alpha.2",
|
|
51
|
+
"@tmagic/form": "1.3.0-alpha.2",
|
|
52
|
+
"@tmagic/schema": "1.3.0-alpha.2",
|
|
53
|
+
"@tmagic/stage": "1.3.0-alpha.2",
|
|
54
|
+
"@tmagic/table": "1.3.0-alpha.2",
|
|
55
|
+
"@tmagic/utils": "1.3.0-alpha.2",
|
|
56
56
|
"buffer": "^6.0.3",
|
|
57
57
|
"color": "^3.1.3",
|
|
58
58
|
"events": "^3.3.0",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"vue": "^3.2.37"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@tmagic/design": "1.3.0-alpha.
|
|
68
|
-
"@tmagic/form": "1.3.0-alpha.
|
|
67
|
+
"@tmagic/design": "1.3.0-alpha.2",
|
|
68
|
+
"@tmagic/form": "1.3.0-alpha.2",
|
|
69
69
|
"monaco-editor": "^0.34.0",
|
|
70
70
|
"vue": "^3.2.37"
|
|
71
71
|
},
|
|
@@ -136,7 +136,7 @@ const dataSourceFieldsConfig: FormConfig = [
|
|
|
136
136
|
{
|
|
137
137
|
validator: ({ value, callback }, { model, parent }) => {
|
|
138
138
|
const index = parent.findIndex((item: Record<string, any>) => item.name === value);
|
|
139
|
-
if ((model.index === -1 && index > -1) || (model.index > -1 && index !== model.index)) {
|
|
139
|
+
if ((model.index === -1 && index > -1) || (model.index > -1 && index > -1 && index !== model.index)) {
|
|
140
140
|
return callback(`属性key(${value})已存在`);
|
|
141
141
|
}
|
|
142
142
|
callback();
|
package/src/index.ts
CHANGED
|
@@ -42,6 +42,7 @@ export { default as propsService } from './services/props';
|
|
|
42
42
|
export { default as historyService } from './services/history';
|
|
43
43
|
export { default as storageService } from './services/storage';
|
|
44
44
|
export { default as eventsService } from './services/events';
|
|
45
|
+
export { default as dataSourceService } from './services/dataSource';
|
|
45
46
|
export { default as uiService } from './services/ui';
|
|
46
47
|
export { default as codeBlockService } from './services/codeBlock';
|
|
47
48
|
export { default as depService } from './services/dep';
|
package/src/initService.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ExtractPropTypes } from 'vue';
|
|
2
2
|
import { onUnmounted, toRaw, watch } from 'vue';
|
|
3
|
+
import { cloneDeep } from 'lodash-es';
|
|
3
4
|
|
|
4
5
|
import type { EventOption } from '@tmagic/core';
|
|
5
6
|
import type { CodeBlockContent, DataSourceSchema, Id, MApp, MNode, MPage } from '@tmagic/schema';
|
|
7
|
+
import { getNodes } from '@tmagic/utils';
|
|
6
8
|
|
|
7
9
|
import type { Target } from './services/dep';
|
|
8
10
|
import { createCodeBlockTarget, createDataSourceTarget } from './utils/dep';
|
|
@@ -110,6 +112,50 @@ export const initServiceEvents = (
|
|
|
110
112
|
emit: (event: 'props-panel-mounted' | 'update:modelValue', ...args: any[]) => void,
|
|
111
113
|
{ editorService, codeBlockService, dataSourceService, depService }: Services,
|
|
112
114
|
) => {
|
|
115
|
+
const getApp = () => {
|
|
116
|
+
const stage = editorService.get('stage');
|
|
117
|
+
return stage?.renderer.runtime?.getApp?.();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const updateDataSoucreSchema = () => {
|
|
121
|
+
const root = editorService.get('root');
|
|
122
|
+
|
|
123
|
+
if (root?.dataSources) {
|
|
124
|
+
getApp()?.dataSourceManager?.updateSchema(root.dataSources);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const upateNodeWhenDataSourceChange = (nodes: MNode[]) => {
|
|
129
|
+
const root = editorService.get('root');
|
|
130
|
+
const stage = editorService.get('stage');
|
|
131
|
+
|
|
132
|
+
if (!root || !stage) return;
|
|
133
|
+
|
|
134
|
+
const app = getApp();
|
|
135
|
+
|
|
136
|
+
if (!app) return;
|
|
137
|
+
|
|
138
|
+
if (app.dsl) {
|
|
139
|
+
app.dsl.dataSourceDeps = root.dataSourceDeps;
|
|
140
|
+
app.dsl.dataSources = root.dataSources;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
updateDataSoucreSchema();
|
|
144
|
+
|
|
145
|
+
nodes.forEach((node) => {
|
|
146
|
+
const deps = Object.values(root.dataSourceDeps || {});
|
|
147
|
+
deps.forEach((dep) => {
|
|
148
|
+
if (dep[node.id]) {
|
|
149
|
+
stage.update({
|
|
150
|
+
config: cloneDeep(node),
|
|
151
|
+
parentId: editorService.getParentById(node.id)?.id,
|
|
152
|
+
root: cloneDeep(root),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
113
159
|
const targetAddHandler = (target: Target) => {
|
|
114
160
|
if (target.type !== 'data-source') return;
|
|
115
161
|
|
|
@@ -130,8 +176,18 @@ export const initServiceEvents = (
|
|
|
130
176
|
delete root.dataSourceDeps[id];
|
|
131
177
|
};
|
|
132
178
|
|
|
179
|
+
const depUpdateHandler = (node: MNode) => {
|
|
180
|
+
upateNodeWhenDataSourceChange([node]);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const collectedHandler = (nodes: MNode[]) => {
|
|
184
|
+
upateNodeWhenDataSourceChange(nodes);
|
|
185
|
+
};
|
|
186
|
+
|
|
133
187
|
depService.on('add-target', targetAddHandler);
|
|
134
188
|
depService.on('remove-target', targetRemoveHandler);
|
|
189
|
+
depService.on('dep-update', depUpdateHandler);
|
|
190
|
+
depService.on('collected', collectedHandler);
|
|
135
191
|
|
|
136
192
|
const rootChangeHandler = async (value: MApp, preValue?: MApp | null) => {
|
|
137
193
|
const nodeId = editorService.get('node')?.id || props.defaultSelected;
|
|
@@ -218,16 +274,25 @@ export const initServiceEvents = (
|
|
|
218
274
|
|
|
219
275
|
const dataSourceAddHandler = (config: DataSourceSchema) => {
|
|
220
276
|
depService.addTarget(createDataSourceTarget(config.id, config));
|
|
277
|
+
getApp()?.dataSourceManager?.addDataSource(config);
|
|
221
278
|
};
|
|
222
279
|
|
|
223
280
|
const dataSourceUpdateHandler = (config: DataSourceSchema) => {
|
|
224
281
|
if (config.title) {
|
|
225
282
|
depService.getTarget(config.id)!.name = config.title;
|
|
226
283
|
}
|
|
284
|
+
const root = editorService.get('root');
|
|
285
|
+
|
|
286
|
+
const targets = depService.getTargets('data-source');
|
|
287
|
+
|
|
288
|
+
const nodes = getNodes(Object.keys(targets[config.id].deps), root?.items);
|
|
289
|
+
|
|
290
|
+
upateNodeWhenDataSourceChange(nodes);
|
|
227
291
|
};
|
|
228
292
|
|
|
229
293
|
const dataSourceRemoveHandler = (id: string) => {
|
|
230
294
|
depService.removeTarget(id);
|
|
295
|
+
getApp()?.dataSourceManager?.removeDataSource(id);
|
|
231
296
|
};
|
|
232
297
|
|
|
233
298
|
dataSourceService.on('add', dataSourceAddHandler);
|
|
@@ -237,6 +302,8 @@ export const initServiceEvents = (
|
|
|
237
302
|
onUnmounted(() => {
|
|
238
303
|
depService.off('add-target', targetAddHandler);
|
|
239
304
|
depService.off('remove-target', targetRemoveHandler);
|
|
305
|
+
depService.off('dep-update', depUpdateHandler);
|
|
306
|
+
depService.off('collected', collectedHandler);
|
|
240
307
|
|
|
241
308
|
editorService.off('history-change', historyChangeHandler);
|
|
242
309
|
editorService.off('root-change', rootChangeHandler);
|
package/src/services/dep.ts
CHANGED
|
@@ -267,6 +267,8 @@ export class Watcher extends EventEmitter {
|
|
|
267
267
|
});
|
|
268
268
|
});
|
|
269
269
|
});
|
|
270
|
+
|
|
271
|
+
this.emit('collected', nodes, deep);
|
|
270
272
|
}
|
|
271
273
|
|
|
272
274
|
/**
|
|
@@ -299,6 +301,7 @@ export class Watcher extends EventEmitter {
|
|
|
299
301
|
|
|
300
302
|
if (target.isTarget(key, value)) {
|
|
301
303
|
target.updateDep(node, fullKey);
|
|
304
|
+
this.emit('update-dep', node, fullKey);
|
|
302
305
|
} else if (!keyIsItems && Array.isArray(value)) {
|
|
303
306
|
value.forEach((item, index) => {
|
|
304
307
|
collectTarget(item, `${fullKey}.${index}`);
|
package/types/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { default as propsService } from './services/props';
|
|
|
11
11
|
export { default as historyService } from './services/history';
|
|
12
12
|
export { default as storageService } from './services/storage';
|
|
13
13
|
export { default as eventsService } from './services/events';
|
|
14
|
+
export { default as dataSourceService } from './services/dataSource';
|
|
14
15
|
export { default as uiService } from './services/ui';
|
|
15
16
|
export { default as codeBlockService } from './services/codeBlock';
|
|
16
17
|
export { default as depService } from './services/dep';
|