|
@@ -12,11 +12,28 @@ export const helpers = EditorModule.helper({
|
|
},
|
|
},
|
|
findParentComp(compId: string): DesignComp | undefined {
|
|
findParentComp(compId: string): DesignComp | undefined {
|
|
const comp = this.helper.findComp(compId);
|
|
const comp = this.helper.findComp(compId);
|
|
- if (comp?.pid) {
|
|
|
|
- return this.helper.findComp(comp?.pid);
|
|
|
|
- }
|
|
|
|
|
|
+ const parentComp = Object.values(this.store.designData.compMap).find(
|
|
|
|
+ (comp) => {
|
|
|
|
+ const ids = this.helper.getCompChildIds(comp);
|
|
|
|
+ return ids.includes(compId);
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ return parentComp;
|
|
},
|
|
},
|
|
findRootComp() {
|
|
findRootComp() {
|
|
return this.store.designData.compMap["root"];
|
|
return this.store.designData.compMap["root"];
|
|
},
|
|
},
|
|
|
|
+ getCompChildIds(comp: DesignComp) {
|
|
|
|
+ function getIds(data: any, ids: string[] = []) {
|
|
|
|
+ if (data instanceof Array) {
|
|
|
|
+ data.forEach((item) => getIds(item, ids));
|
|
|
|
+ } else if (data instanceof Object) {
|
|
|
|
+ Object.values(data).forEach((item) => getIds(item, ids));
|
|
|
|
+ } else if (typeof data === "string") {
|
|
|
|
+ ids.push(data);
|
|
|
|
+ }
|
|
|
|
+ return ids;
|
|
|
|
+ }
|
|
|
|
+ return getIds(comp.children);
|
|
|
|
+ },
|
|
});
|
|
});
|