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