|
@@ -1,6 +1,5 @@
|
|
|
import { CompBase } from "./base";
|
|
|
import { HistoryController } from "./history";
|
|
|
-import { utils } from "./utils";
|
|
|
|
|
|
export type PageValue = {
|
|
|
music: string;
|
|
@@ -22,7 +21,8 @@ export class CompCard extends CompBase<CardValue> {
|
|
|
super.init();
|
|
|
|
|
|
this.state.children.forEach((c) => {
|
|
|
- c.on("transformChange", () => {
|
|
|
+ const obj = this.getObj(c)
|
|
|
+ obj.on("transformChange", () => {
|
|
|
this.extendHeight();
|
|
|
});
|
|
|
});
|
|
@@ -30,7 +30,7 @@ export class CompCard extends CompBase<CardValue> {
|
|
|
|
|
|
addComp(comp: CompBase<any>) {
|
|
|
const childrens = this.state.children.slice(0);
|
|
|
- childrens.push(comp);
|
|
|
+ childrens.push(comp.id);
|
|
|
this.state.setChildren(childrens);
|
|
|
this.extendHeight();
|
|
|
comp.on("transformChange", ()=>{
|
|
@@ -43,7 +43,7 @@ export class CompCard extends CompBase<CardValue> {
|
|
|
let maxH = 0,
|
|
|
n = childrens.length;
|
|
|
while (n--) {
|
|
|
- const c = childrens[n];
|
|
|
+ const c = this.getObj(childrens[n]) ;
|
|
|
const aabb = c.getLocalBounds();
|
|
|
maxH = Math.max(maxH, aabb.y + aabb.height);
|
|
|
}
|
|
@@ -66,44 +66,57 @@ export class CompPage extends CompBase<PageValue> {
|
|
|
insertCard(srcCardId: string, card: CompCard) {
|
|
|
const state = this.state;
|
|
|
const children = state.children.slice(0);
|
|
|
- let childs = children.map((item) => item.id);
|
|
|
- const index = childs.indexOf(srcCardId) + 1;
|
|
|
- children.splice(index, 0, card);
|
|
|
+ const index = children.indexOf(srcCardId) + 1;
|
|
|
+ children.splice(index, 0, card.id);
|
|
|
state.setChildren(children);
|
|
|
+
|
|
|
return index;
|
|
|
}
|
|
|
|
|
|
removeCard(srcCardId: string) {
|
|
|
const state = this.state;
|
|
|
const children = state.children.slice(0);
|
|
|
- let childs = children.map((item) => item.id);
|
|
|
- const index = childs.indexOf(srcCardId);
|
|
|
+ const index = children.indexOf(srcCardId);
|
|
|
children.splice(index, 1);
|
|
|
state.setChildren(children);
|
|
|
return index;
|
|
|
}
|
|
|
|
|
|
- switchCard(fromIndex: number, toIndex: number) {
|
|
|
- console.log("switch");
|
|
|
+ getCompTrees(compId: string) {
|
|
|
+ const comps: CompBase<any>[] = [];
|
|
|
+ const getParentComp = (compId: string) => {
|
|
|
+ const comp = this.getObj(compId);
|
|
|
+ if (comp) {
|
|
|
+ comps.unshift(comp);
|
|
|
+ if (comp.parent) {
|
|
|
+ getParentComp(comp.parent.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ getParentComp(compId);
|
|
|
+ return comps;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export function createPage( values: Partial<PageValue>, h: HistoryController, objMap: Map<string, any>) {
|
|
|
+export function createPage( values: Partial<PageValue>, h: HistoryController) {
|
|
|
|
|
|
const options = {music: "", volume: 100, ...values}
|
|
|
const obj = new CompPage(options);
|
|
|
- obj.state.children.push(createCard(h, objMap)); //默认有一页卡片
|
|
|
+ const card = createCard(h);
|
|
|
+
|
|
|
+
|
|
|
+ obj.state.children.push(card.id); //默认有一页卡片
|
|
|
+
|
|
|
obj.init();
|
|
|
+
|
|
|
obj.setHistory(h);
|
|
|
- objMap.set(obj.id, obj);
|
|
|
+
|
|
|
return obj;
|
|
|
}
|
|
|
|
|
|
-export function createCard(histry: HistoryController, objMap: Map<string, any>) {
|
|
|
+export function createCard(histry: HistoryController) {
|
|
|
const obj = new CompCard({ test: 1 });
|
|
|
obj.init();
|
|
|
obj.setHistory(histry);
|
|
|
-
|
|
|
- objMap.set(obj.id, obj);
|
|
|
return obj;
|
|
|
}
|