@tmagic/editor 1.5.4 → 1.5.5
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 +218 -190
- package/dist/tmagic-editor.umd.cjs +218 -190
- package/package.json +7 -7
- package/src/initService.ts +264 -233
- package/src/services/dep.ts +3 -3
- package/src/utils/idle-task.ts +1 -1
package/dist/tmagic-editor.js
CHANGED
|
@@ -2867,7 +2867,7 @@ class IdleTask extends EventEmitter {
|
|
|
2867
2867
|
}
|
|
2868
2868
|
runTaskQueue(deadline) {
|
|
2869
2869
|
const { hightLevelTaskList, taskList } = this;
|
|
2870
|
-
while (deadline.timeRemaining() > 0 && taskList.length) {
|
|
2870
|
+
while (deadline.timeRemaining() > 0 && (taskList.length || hightLevelTaskList.length)) {
|
|
2871
2871
|
const timeRemaining = deadline.timeRemaining();
|
|
2872
2872
|
let times = 0;
|
|
2873
2873
|
if (timeRemaining <= 5) {
|
|
@@ -13134,20 +13134,20 @@ class Dep extends BaseService {
|
|
|
13134
13134
|
idleTask.once("finish", () => {
|
|
13135
13135
|
this.emit("collected", nodes, deep);
|
|
13136
13136
|
this.set("collecting", false);
|
|
13137
|
-
resolve();
|
|
13138
13137
|
});
|
|
13139
13138
|
idleTask.once("hight-level-finish", () => {
|
|
13140
13139
|
this.emit("ds-collected", nodes, deep);
|
|
13140
|
+
resolve();
|
|
13141
13141
|
});
|
|
13142
13142
|
});
|
|
13143
13143
|
}
|
|
13144
13144
|
collectNode(node, target, depExtendedData = {}, deep = false) {
|
|
13145
13145
|
if (isPage(node)) {
|
|
13146
|
-
Object.entries(target.deps)
|
|
13146
|
+
for (const [depKey, dep] of Object.entries(target.deps)) {
|
|
13147
13147
|
if (dep.data?.pageId && dep.data.pageId === depExtendedData.pageId) {
|
|
13148
13148
|
delete target.deps[depKey];
|
|
13149
13149
|
}
|
|
13150
|
-
}
|
|
13150
|
+
}
|
|
13151
13151
|
} else {
|
|
13152
13152
|
this.watcher.removeTargetDep(target, node);
|
|
13153
13153
|
}
|
|
@@ -13677,10 +13677,12 @@ const initServiceState = (props, {
|
|
|
13677
13677
|
(eventMethodList) => {
|
|
13678
13678
|
const eventsList = {};
|
|
13679
13679
|
const methodsList = {};
|
|
13680
|
-
|
|
13681
|
-
|
|
13682
|
-
|
|
13683
|
-
|
|
13680
|
+
if (eventMethodList) {
|
|
13681
|
+
for (const type of Object.keys(eventMethodList)) {
|
|
13682
|
+
eventsList[type] = eventMethodList[type].events;
|
|
13683
|
+
methodsList[type] = eventMethodList[type].methods;
|
|
13684
|
+
}
|
|
13685
|
+
}
|
|
13684
13686
|
eventsService.setEvents(eventsList);
|
|
13685
13687
|
eventsService.setMethods(methodsList);
|
|
13686
13688
|
},
|
|
@@ -13691,9 +13693,12 @@ const initServiceState = (props, {
|
|
|
13691
13693
|
watch(
|
|
13692
13694
|
() => props.datasourceConfigs,
|
|
13693
13695
|
(configs) => {
|
|
13694
|
-
|
|
13696
|
+
if (!configs) {
|
|
13697
|
+
return;
|
|
13698
|
+
}
|
|
13699
|
+
for (const [key, value] of Object.entries(configs)) {
|
|
13695
13700
|
dataSourceService.setFormConfig(key, value);
|
|
13696
|
-
}
|
|
13701
|
+
}
|
|
13697
13702
|
},
|
|
13698
13703
|
{
|
|
13699
13704
|
immediate: true
|
|
@@ -13702,9 +13707,12 @@ const initServiceState = (props, {
|
|
|
13702
13707
|
watch(
|
|
13703
13708
|
() => props.datasourceValues,
|
|
13704
13709
|
(values) => {
|
|
13705
|
-
|
|
13710
|
+
if (!values) {
|
|
13711
|
+
return;
|
|
13712
|
+
}
|
|
13713
|
+
for (const [key, value] of Object.entries(values)) {
|
|
13706
13714
|
dataSourceService.setFormValue(key, value);
|
|
13707
|
-
}
|
|
13715
|
+
}
|
|
13708
13716
|
},
|
|
13709
13717
|
{
|
|
13710
13718
|
immediate: true
|
|
@@ -13715,16 +13723,18 @@ const initServiceState = (props, {
|
|
|
13715
13723
|
(eventMethodList) => {
|
|
13716
13724
|
const eventsList = {};
|
|
13717
13725
|
const methodsList = {};
|
|
13718
|
-
|
|
13719
|
-
|
|
13720
|
-
|
|
13721
|
-
|
|
13722
|
-
|
|
13726
|
+
if (eventMethodList) {
|
|
13727
|
+
for (const type of Object.keys(eventMethodList)) {
|
|
13728
|
+
eventsList[type] = eventMethodList[type].events;
|
|
13729
|
+
methodsList[type] = eventMethodList[type].methods;
|
|
13730
|
+
}
|
|
13731
|
+
}
|
|
13732
|
+
for (const [key, value] of Object.entries(eventsList)) {
|
|
13723
13733
|
dataSourceService.setFormEvent(key, value);
|
|
13724
|
-
}
|
|
13725
|
-
|
|
13734
|
+
}
|
|
13735
|
+
for (const [key, value] of Object.entries(methodsList)) {
|
|
13726
13736
|
dataSourceService.setFormMethod(key, value);
|
|
13727
|
-
}
|
|
13737
|
+
}
|
|
13728
13738
|
},
|
|
13729
13739
|
{
|
|
13730
13740
|
immediate: true
|
|
@@ -13755,59 +13765,8 @@ const initServiceState = (props, {
|
|
|
13755
13765
|
});
|
|
13756
13766
|
};
|
|
13757
13767
|
const initServiceEvents = (props, emit, { editorService, codeBlockService, dataSourceService, depService }) => {
|
|
13758
|
-
const
|
|
13759
|
-
|
|
13760
|
-
value.codeBlocks = value.codeBlocks || {};
|
|
13761
|
-
value.dataSources = value.dataSources || [];
|
|
13762
|
-
codeBlockService.setCodeDsl(value.codeBlocks);
|
|
13763
|
-
dataSourceService.set("dataSources", value.dataSources);
|
|
13764
|
-
depService.removeTargets(DepTargetType.CODE_BLOCK);
|
|
13765
|
-
Object.entries(value.codeBlocks).forEach(([id, code]) => {
|
|
13766
|
-
depService.addTarget(createCodeBlockTarget(id, code));
|
|
13767
|
-
});
|
|
13768
|
-
dataSourceService.get("dataSources").forEach((ds) => {
|
|
13769
|
-
initDataSourceDepTarget(ds);
|
|
13770
|
-
});
|
|
13771
|
-
if (Array.isArray(value.items)) {
|
|
13772
|
-
depService.clearIdleTasks();
|
|
13773
|
-
collectIdle(value.items, true);
|
|
13774
|
-
} else {
|
|
13775
|
-
depService.clear();
|
|
13776
|
-
delete value.dataSourceDeps;
|
|
13777
|
-
delete value.dataSourceCondDeps;
|
|
13778
|
-
}
|
|
13779
|
-
const nodeId = editorService.get("node")?.id || props.defaultSelected;
|
|
13780
|
-
let node;
|
|
13781
|
-
if (nodeId) {
|
|
13782
|
-
node = editorService.getNodeById(nodeId);
|
|
13783
|
-
}
|
|
13784
|
-
if (node && node !== value) {
|
|
13785
|
-
await editorService.select(node.id);
|
|
13786
|
-
} else if (value.items?.length) {
|
|
13787
|
-
await editorService.select(value.items[0]);
|
|
13788
|
-
} else if (value.id) {
|
|
13789
|
-
editorService.set("nodes", [value]);
|
|
13790
|
-
editorService.set("parent", null);
|
|
13791
|
-
editorService.set("page", null);
|
|
13792
|
-
}
|
|
13793
|
-
if (toRaw(value) !== toRaw(preValue)) {
|
|
13794
|
-
emit("update:modelValue", value);
|
|
13795
|
-
}
|
|
13796
|
-
};
|
|
13797
|
-
const stage = computed(() => editorService.get("stage"));
|
|
13798
|
-
watch(stage, (stage2) => {
|
|
13799
|
-
if (!stage2) {
|
|
13800
|
-
return;
|
|
13801
|
-
}
|
|
13802
|
-
stage2.on("rerender", () => {
|
|
13803
|
-
const node = editorService.get("node");
|
|
13804
|
-
if (!node) return;
|
|
13805
|
-
collectIdle([node], true);
|
|
13806
|
-
updateStage([node]);
|
|
13807
|
-
});
|
|
13808
|
-
});
|
|
13809
|
-
const getApp = () => {
|
|
13810
|
-
const renderer = stage.value?.renderer;
|
|
13768
|
+
const getTMagicApp = () => {
|
|
13769
|
+
const renderer = editorService.get("stage")?.renderer;
|
|
13811
13770
|
if (!renderer) {
|
|
13812
13771
|
return void 0;
|
|
13813
13772
|
}
|
|
@@ -13826,101 +13785,41 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
|
|
|
13826
13785
|
});
|
|
13827
13786
|
});
|
|
13828
13787
|
};
|
|
13829
|
-
const
|
|
13830
|
-
const
|
|
13831
|
-
|
|
13832
|
-
if (root && app?.dsl) {
|
|
13833
|
-
app.dsl.dataSourceDeps = root.dataSourceDeps;
|
|
13834
|
-
app.dsl.dataSources = root.dataSources;
|
|
13835
|
-
}
|
|
13836
|
-
if (root?.dataSources) {
|
|
13837
|
-
app?.dataSourceManager?.updateSchema(root.dataSources);
|
|
13838
|
-
}
|
|
13839
|
-
};
|
|
13840
|
-
const targetAddHandler = (target) => {
|
|
13841
|
-
const root = editorService.get("root");
|
|
13842
|
-
if (!root) return;
|
|
13843
|
-
if (target.type === DepTargetType.DATA_SOURCE) {
|
|
13844
|
-
if (!root.dataSourceDeps) {
|
|
13845
|
-
root.dataSourceDeps = {};
|
|
13846
|
-
}
|
|
13847
|
-
root.dataSourceDeps[target.id] = target.deps;
|
|
13848
|
-
}
|
|
13849
|
-
if (target.type === DepTargetType.DATA_SOURCE_COND) {
|
|
13850
|
-
if (!root.dataSourceCondDeps) {
|
|
13851
|
-
root.dataSourceCondDeps = {};
|
|
13852
|
-
}
|
|
13853
|
-
root.dataSourceCondDeps[target.id] = target.deps;
|
|
13854
|
-
}
|
|
13855
|
-
};
|
|
13856
|
-
const targetRemoveHandler = (id) => {
|
|
13857
|
-
const root = editorService.get("root");
|
|
13858
|
-
if (!root) return;
|
|
13859
|
-
if (root.dataSourceDeps) {
|
|
13860
|
-
delete root.dataSourceDeps[id];
|
|
13861
|
-
}
|
|
13862
|
-
if (root.dataSourceCondDeps) {
|
|
13863
|
-
delete root.dataSourceCondDeps[id];
|
|
13788
|
+
const updateStageNodes = (nodes) => {
|
|
13789
|
+
for (const node of nodes) {
|
|
13790
|
+
updateStageNode(node);
|
|
13864
13791
|
}
|
|
13865
13792
|
};
|
|
13866
|
-
const
|
|
13793
|
+
const updateStageNode = (node) => {
|
|
13867
13794
|
const root = editorService.get("root");
|
|
13868
13795
|
if (!root) return;
|
|
13869
|
-
|
|
13796
|
+
return editorService.get("stage")?.update({
|
|
13870
13797
|
config: cloneDeep(node),
|
|
13871
13798
|
parentId: editorService.getParentById(node.id)?.id,
|
|
13872
13799
|
root: cloneDeep(root)
|
|
13873
13800
|
});
|
|
13874
|
-
nodes.forEach((node) => {
|
|
13875
|
-
const inDepsNodeId = [];
|
|
13876
|
-
const deps = Object.values(root.dataSourceDeps || {});
|
|
13877
|
-
deps.forEach((dep) => {
|
|
13878
|
-
Object.keys(dep).forEach((id) => {
|
|
13879
|
-
inDepsNodeId.push(id);
|
|
13880
|
-
});
|
|
13881
|
-
});
|
|
13882
|
-
if (inDeps) {
|
|
13883
|
-
if (inDepsNodeId.includes(node.id)) {
|
|
13884
|
-
update(node);
|
|
13885
|
-
}
|
|
13886
|
-
} else {
|
|
13887
|
-
if (!inDepsNodeId.includes(node.id)) {
|
|
13888
|
-
update(node);
|
|
13889
|
-
}
|
|
13890
|
-
}
|
|
13891
|
-
});
|
|
13892
13801
|
};
|
|
13893
|
-
const
|
|
13802
|
+
const updateDataSourceSchema = async () => {
|
|
13894
13803
|
const root = editorService.get("root");
|
|
13895
|
-
|
|
13896
|
-
|
|
13897
|
-
|
|
13898
|
-
app.dsl.dataSourceDeps = root.dataSourceDeps;
|
|
13804
|
+
const app = await getTMagicApp();
|
|
13805
|
+
if (!app || !root) {
|
|
13806
|
+
return;
|
|
13899
13807
|
}
|
|
13900
|
-
if (
|
|
13901
|
-
|
|
13902
|
-
|
|
13903
|
-
|
|
13904
|
-
|
|
13905
|
-
updateStage([node2], true);
|
|
13906
|
-
},
|
|
13907
|
-
[],
|
|
13908
|
-
true
|
|
13909
|
-
);
|
|
13910
|
-
});
|
|
13911
|
-
} else {
|
|
13912
|
-
updateStage(nodes, true);
|
|
13808
|
+
if (app.dsl) {
|
|
13809
|
+
app.dsl.dataSources = root.dataSources;
|
|
13810
|
+
}
|
|
13811
|
+
if (root.dataSources) {
|
|
13812
|
+
app.dataSourceManager?.updateSchema(root.dataSources);
|
|
13913
13813
|
}
|
|
13914
13814
|
};
|
|
13915
|
-
|
|
13916
|
-
|
|
13917
|
-
|
|
13918
|
-
|
|
13919
|
-
|
|
13920
|
-
|
|
13921
|
-
depService.addTarget(createDataSourceCondTarget(ds, reactive({})));
|
|
13815
|
+
const dsDepCollectedHandler = async () => {
|
|
13816
|
+
const root = editorService.get("root");
|
|
13817
|
+
const app = await getTMagicApp();
|
|
13818
|
+
if (root && app?.dsl) {
|
|
13819
|
+
app.dsl.dataSourceDeps = root.dataSourceDeps;
|
|
13820
|
+
}
|
|
13922
13821
|
};
|
|
13923
|
-
const collectIdle = (nodes, deep) => Promise.all(
|
|
13822
|
+
const collectIdle = (nodes, deep, type) => Promise.all(
|
|
13924
13823
|
nodes.map((node) => {
|
|
13925
13824
|
let pageId;
|
|
13926
13825
|
if (isPage(node)) {
|
|
@@ -13929,75 +13828,146 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
|
|
|
13929
13828
|
const info = editorService.getNodeInfo(node.id);
|
|
13930
13829
|
pageId = info.page?.id;
|
|
13931
13830
|
}
|
|
13932
|
-
return depService.collectIdle([node], { pageId }, deep);
|
|
13831
|
+
return depService.collectIdle([node], { pageId }, deep, type);
|
|
13933
13832
|
})
|
|
13934
13833
|
);
|
|
13935
|
-
|
|
13936
|
-
|
|
13937
|
-
|
|
13834
|
+
watch(
|
|
13835
|
+
() => editorService.get("stage"),
|
|
13836
|
+
(stage) => {
|
|
13837
|
+
if (!stage) {
|
|
13838
|
+
return;
|
|
13839
|
+
}
|
|
13840
|
+
stage.on("rerender", async () => {
|
|
13841
|
+
const node = editorService.get("node");
|
|
13842
|
+
if (!node) return;
|
|
13843
|
+
await collectIdle([node], true, DepTargetType.DATA_SOURCE);
|
|
13844
|
+
updateStageNode(node);
|
|
13845
|
+
});
|
|
13846
|
+
}
|
|
13847
|
+
);
|
|
13848
|
+
const initDataSourceDepTarget = (ds) => {
|
|
13849
|
+
depService.addTarget(createDataSourceTarget(ds, reactive({})));
|
|
13850
|
+
depService.addTarget(createDataSourceMethodTarget(ds, reactive({})));
|
|
13851
|
+
depService.addTarget(createDataSourceCondTarget(ds, reactive({})));
|
|
13938
13852
|
};
|
|
13939
|
-
const
|
|
13853
|
+
const rootChangeHandler = async (value, preValue) => {
|
|
13854
|
+
if (!value) return;
|
|
13855
|
+
value.codeBlocks = value.codeBlocks || {};
|
|
13856
|
+
value.dataSources = value.dataSources || [];
|
|
13857
|
+
codeBlockService.setCodeDsl(value.codeBlocks);
|
|
13858
|
+
dataSourceService.set("dataSources", value.dataSources);
|
|
13859
|
+
depService.removeTargets(DepTargetType.CODE_BLOCK);
|
|
13860
|
+
for (const [id, code] of Object.entries(value.codeBlocks)) {
|
|
13861
|
+
depService.addTarget(createCodeBlockTarget(id, code));
|
|
13862
|
+
}
|
|
13863
|
+
for (const ds of dataSourceService.get("dataSources")) {
|
|
13864
|
+
initDataSourceDepTarget(ds);
|
|
13865
|
+
}
|
|
13866
|
+
if (Array.isArray(value.items)) {
|
|
13867
|
+
depService.clearIdleTasks();
|
|
13868
|
+
collectIdle(value.items, true).then(() => {
|
|
13869
|
+
updateStageNodes(value.items);
|
|
13870
|
+
});
|
|
13871
|
+
} else {
|
|
13872
|
+
depService.clear();
|
|
13873
|
+
delete value.dataSourceDeps;
|
|
13874
|
+
delete value.dataSourceCondDeps;
|
|
13875
|
+
}
|
|
13876
|
+
const nodeId = editorService.get("node")?.id || props.defaultSelected;
|
|
13877
|
+
let node;
|
|
13878
|
+
if (nodeId) {
|
|
13879
|
+
node = editorService.getNodeById(nodeId);
|
|
13880
|
+
}
|
|
13881
|
+
if (node && node !== value) {
|
|
13882
|
+
await editorService.select(node.id);
|
|
13883
|
+
} else if (value.items?.length) {
|
|
13884
|
+
await editorService.select(value.items[0]);
|
|
13885
|
+
} else if (value.id) {
|
|
13886
|
+
editorService.set("nodes", [value]);
|
|
13887
|
+
editorService.set("parent", null);
|
|
13888
|
+
editorService.set("page", null);
|
|
13889
|
+
}
|
|
13890
|
+
if (toRaw(value) !== toRaw(preValue)) {
|
|
13891
|
+
emit("update:modelValue", value);
|
|
13892
|
+
}
|
|
13893
|
+
};
|
|
13894
|
+
const nodeAddHandler = async (nodes) => {
|
|
13895
|
+
await collectIdle(nodes, true);
|
|
13896
|
+
updateStageNodes(nodes);
|
|
13897
|
+
};
|
|
13898
|
+
const nodeUpdateHandler = async (data) => {
|
|
13940
13899
|
const needRecollectNodes = [];
|
|
13941
13900
|
const normalNodes = [];
|
|
13942
|
-
|
|
13901
|
+
for (const { newNode, oldNode, changeRecords } of data) {
|
|
13943
13902
|
if (changeRecords?.length) {
|
|
13944
|
-
for (const record of changeRecords) {
|
|
13945
|
-
if (!record.propPath
|
|
13903
|
+
forChangeRecords: for (const record of changeRecords) {
|
|
13904
|
+
if (!record.propPath) {
|
|
13946
13905
|
needRecollectNodes.push(newNode);
|
|
13947
|
-
|
|
13948
|
-
|
|
13906
|
+
break forChangeRecords;
|
|
13907
|
+
}
|
|
13908
|
+
if (new RegExp(`${NODE_CONDS_KEY}.(\\d)+.cond`).test(record.propPath) || new RegExp(`${NODE_CONDS_KEY}.(\\d)+.cond.(\\d)+.value`).test(record.propPath) || record.propPath === NODE_CONDS_KEY || isValueIncludeDataSource(record.value)) {
|
|
13909
|
+
needRecollectNodes.push(newNode);
|
|
13910
|
+
break forChangeRecords;
|
|
13949
13911
|
}
|
|
13912
|
+
for (const target of Object.values(depService.getTargets(DepTargetType.DATA_SOURCE))) {
|
|
13913
|
+
if (!target.deps[newNode.id]) {
|
|
13914
|
+
continue;
|
|
13915
|
+
}
|
|
13916
|
+
if (target.deps[newNode.id].keys.includes(record.propPath)) {
|
|
13917
|
+
needRecollectNodes.push(newNode);
|
|
13918
|
+
break forChangeRecords;
|
|
13919
|
+
}
|
|
13920
|
+
}
|
|
13921
|
+
normalNodes.push(newNode);
|
|
13950
13922
|
}
|
|
13951
13923
|
} else if (isIncludeDataSource(newNode, oldNode)) {
|
|
13952
13924
|
needRecollectNodes.push(newNode);
|
|
13953
13925
|
} else {
|
|
13954
13926
|
normalNodes.push(newNode);
|
|
13955
13927
|
}
|
|
13956
|
-
}
|
|
13928
|
+
}
|
|
13957
13929
|
if (needRecollectNodes.length) {
|
|
13958
|
-
collectIdle(needRecollectNodes, true);
|
|
13959
|
-
|
|
13960
|
-
|
|
13961
|
-
|
|
13930
|
+
await collectIdle(needRecollectNodes, true, DepTargetType.DATA_SOURCE);
|
|
13931
|
+
await collectIdle(needRecollectNodes, true, DepTargetType.DATA_SOURCE_COND);
|
|
13932
|
+
updateStageNodes(needRecollectNodes);
|
|
13933
|
+
} else {
|
|
13934
|
+
updateStageNodes(normalNodes);
|
|
13935
|
+
Promise.all([
|
|
13936
|
+
collectIdle(normalNodes, true, DepTargetType.CODE_BLOCK),
|
|
13937
|
+
collectIdle(normalNodes, true, DepTargetType.DATA_SOURCE_METHOD)
|
|
13938
|
+
]);
|
|
13962
13939
|
}
|
|
13963
13940
|
};
|
|
13964
13941
|
const nodeRemoveHandler = (nodes) => {
|
|
13965
13942
|
depService.clear(nodes);
|
|
13966
13943
|
};
|
|
13967
|
-
const historyChangeHandler = (page) => {
|
|
13968
|
-
collectIdle([page], true)
|
|
13969
|
-
|
|
13970
|
-
});
|
|
13944
|
+
const historyChangeHandler = async (page) => {
|
|
13945
|
+
await collectIdle([page], true);
|
|
13946
|
+
updateStageNode(page);
|
|
13971
13947
|
};
|
|
13972
13948
|
editorService.on("history-change", historyChangeHandler);
|
|
13973
13949
|
editorService.on("root-change", rootChangeHandler);
|
|
13974
13950
|
editorService.on("add", nodeAddHandler);
|
|
13975
13951
|
editorService.on("remove", nodeRemoveHandler);
|
|
13976
13952
|
editorService.on("update", nodeUpdateHandler);
|
|
13977
|
-
const codeBlockAddOrUpdateHandler = (id, codeBlock) => {
|
|
13978
|
-
if (depService.hasTarget(id, DepTargetType.CODE_BLOCK)) {
|
|
13979
|
-
depService.getTarget(id, DepTargetType.CODE_BLOCK).name = codeBlock.name;
|
|
13980
|
-
return;
|
|
13981
|
-
}
|
|
13982
|
-
depService.addTarget(createCodeBlockTarget(id, codeBlock));
|
|
13983
|
-
};
|
|
13984
|
-
const codeBlockRemoveHandler = (id) => {
|
|
13985
|
-
depService.removeTarget(id, DepTargetType.CODE_BLOCK);
|
|
13986
|
-
};
|
|
13987
|
-
codeBlockService.on("addOrUpdate", codeBlockAddOrUpdateHandler);
|
|
13988
|
-
codeBlockService.on("remove", codeBlockRemoveHandler);
|
|
13989
13953
|
const dataSourceAddHandler = async (config) => {
|
|
13990
13954
|
initDataSourceDepTarget(config);
|
|
13991
|
-
const app = await
|
|
13955
|
+
const app = await getTMagicApp();
|
|
13992
13956
|
app?.dataSourceManager?.addDataSource(config);
|
|
13993
13957
|
};
|
|
13994
13958
|
const dataSourceUpdateHandler = async (config, { changeRecords }) => {
|
|
13995
13959
|
let needRecollectDep = false;
|
|
13960
|
+
let isModifyField = false;
|
|
13961
|
+
let isModifyMock = false;
|
|
13962
|
+
let isModifyMethod = false;
|
|
13996
13963
|
for (const changeRecord of changeRecords) {
|
|
13997
13964
|
if (!changeRecord.propPath) {
|
|
13998
13965
|
continue;
|
|
13999
13966
|
}
|
|
14000
|
-
|
|
13967
|
+
isModifyField = changeRecord.propPath === "fields" || /fields.(\d)+.name/.test(changeRecord.propPath) || /fields.(\d)+$/.test(changeRecord.propPath);
|
|
13968
|
+
isModifyMock = changeRecord.propPath === "mocks";
|
|
13969
|
+
isModifyMethod = changeRecord.propPath === "methods" || /methods.(\d)+.name/.test(changeRecord.propPath) || /methods.(\d)+$/.test(changeRecord.propPath);
|
|
13970
|
+
needRecollectDep = isModifyField || isModifyMock || isModifyMethod;
|
|
14001
13971
|
if (needRecollectDep) {
|
|
14002
13972
|
break;
|
|
14003
13973
|
}
|
|
@@ -14008,12 +13978,24 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
|
|
|
14008
13978
|
depService.clearIdleTasks();
|
|
14009
13979
|
removeDataSourceTarget(config.id);
|
|
14010
13980
|
initDataSourceDepTarget(config);
|
|
14011
|
-
|
|
13981
|
+
let collectIdlePromises = [];
|
|
13982
|
+
if (isModifyField) {
|
|
13983
|
+
collectIdlePromises = [
|
|
13984
|
+
collectIdle(root.items, true, DepTargetType.DATA_SOURCE),
|
|
13985
|
+
collectIdle(root.items, true, DepTargetType.DATA_SOURCE_COND)
|
|
13986
|
+
];
|
|
13987
|
+
} else if (isModifyMock) {
|
|
13988
|
+
collectIdlePromises = [collectIdle(root.items, true, DepTargetType.DATA_SOURCE)];
|
|
13989
|
+
} else if (isModifyMethod) {
|
|
13990
|
+
collectIdlePromises = [collectIdle(root.items, true, DepTargetType.DATA_SOURCE_METHOD)];
|
|
13991
|
+
}
|
|
13992
|
+
Promise.all(collectIdlePromises).then(() => {
|
|
14012
13993
|
updateDataSourceSchema();
|
|
13994
|
+
updateStageNodes(root.items);
|
|
14013
13995
|
});
|
|
14014
13996
|
}
|
|
14015
13997
|
} else if (root?.dataSources) {
|
|
14016
|
-
const app = await
|
|
13998
|
+
const app = await getTMagicApp();
|
|
14017
13999
|
app?.dataSourceManager?.updateSchema(root.dataSources);
|
|
14018
14000
|
}
|
|
14019
14001
|
};
|
|
@@ -14026,14 +14008,60 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
|
|
|
14026
14008
|
const root = editorService.get("root");
|
|
14027
14009
|
const nodeIds = Object.keys(root?.dataSourceDeps?.[id] || {});
|
|
14028
14010
|
const nodes = getNodes(nodeIds, root?.items);
|
|
14029
|
-
|
|
14011
|
+
Promise.all([
|
|
14012
|
+
collectIdle(nodes, false, DepTargetType.DATA_SOURCE),
|
|
14013
|
+
collectIdle(nodes, false, DepTargetType.DATA_SOURCE_COND),
|
|
14014
|
+
collectIdle(nodes, false, DepTargetType.DATA_SOURCE_METHOD)
|
|
14015
|
+
]).then(() => {
|
|
14030
14016
|
updateDataSourceSchema();
|
|
14017
|
+
updateStageNodes(nodes);
|
|
14031
14018
|
});
|
|
14032
14019
|
removeDataSourceTarget(id);
|
|
14033
14020
|
};
|
|
14034
14021
|
dataSourceService.on("add", dataSourceAddHandler);
|
|
14035
14022
|
dataSourceService.on("update", dataSourceUpdateHandler);
|
|
14036
14023
|
dataSourceService.on("remove", dataSourceRemoveHandler);
|
|
14024
|
+
const codeBlockAddOrUpdateHandler = (id, codeBlock) => {
|
|
14025
|
+
if (depService.hasTarget(id, DepTargetType.CODE_BLOCK)) {
|
|
14026
|
+
depService.getTarget(id, DepTargetType.CODE_BLOCK).name = codeBlock.name;
|
|
14027
|
+
return;
|
|
14028
|
+
}
|
|
14029
|
+
depService.addTarget(createCodeBlockTarget(id, codeBlock));
|
|
14030
|
+
};
|
|
14031
|
+
const codeBlockRemoveHandler = (id) => {
|
|
14032
|
+
depService.removeTarget(id, DepTargetType.CODE_BLOCK);
|
|
14033
|
+
};
|
|
14034
|
+
codeBlockService.on("addOrUpdate", codeBlockAddOrUpdateHandler);
|
|
14035
|
+
codeBlockService.on("remove", codeBlockRemoveHandler);
|
|
14036
|
+
const targetAddHandler = (target) => {
|
|
14037
|
+
const root = editorService.get("root");
|
|
14038
|
+
if (!root) return;
|
|
14039
|
+
if (target.type === DepTargetType.DATA_SOURCE) {
|
|
14040
|
+
if (!root.dataSourceDeps) {
|
|
14041
|
+
root.dataSourceDeps = {};
|
|
14042
|
+
}
|
|
14043
|
+
root.dataSourceDeps[target.id] = target.deps;
|
|
14044
|
+
}
|
|
14045
|
+
if (target.type === DepTargetType.DATA_SOURCE_COND) {
|
|
14046
|
+
if (!root.dataSourceCondDeps) {
|
|
14047
|
+
root.dataSourceCondDeps = {};
|
|
14048
|
+
}
|
|
14049
|
+
root.dataSourceCondDeps[target.id] = target.deps;
|
|
14050
|
+
}
|
|
14051
|
+
};
|
|
14052
|
+
const targetRemoveHandler = (id) => {
|
|
14053
|
+
const root = editorService.get("root");
|
|
14054
|
+
if (!root) return;
|
|
14055
|
+
if (root.dataSourceDeps) {
|
|
14056
|
+
delete root.dataSourceDeps[id];
|
|
14057
|
+
}
|
|
14058
|
+
if (root.dataSourceCondDeps) {
|
|
14059
|
+
delete root.dataSourceCondDeps[id];
|
|
14060
|
+
}
|
|
14061
|
+
};
|
|
14062
|
+
depService.on("add-target", targetAddHandler);
|
|
14063
|
+
depService.on("remove-target", targetRemoveHandler);
|
|
14064
|
+
depService.on("ds-collected", dsDepCollectedHandler);
|
|
14037
14065
|
onBeforeUnmount(() => {
|
|
14038
14066
|
depService.off("add-target", targetAddHandler);
|
|
14039
14067
|
depService.off("remove-target", targetRemoveHandler);
|