|
|
|
import { map, isWidget } from "../2.base";
|
|
|
|
import { Direction } from "../constant";
|
|
|
|
import { Logic } from "./logic";
|
|
|
|
import { VerticalLayoutLogic, HorizontalLayoutLogic, TableLayoutLogic, HorizontalFillLayoutLogic } from "./logic.layout";
|
|
|
|
|
|
|
|
export const LogicFactory = {
|
|
|
|
Type: {
|
|
|
|
Vertical: "vertical",
|
|
|
|
Horizontal: "horizontal",
|
|
|
|
Table: "table",
|
|
|
|
HorizontalFill: "horizontal_fill",
|
|
|
|
},
|
|
|
|
createLogic (key, options) {
|
|
|
|
let LogicCls;
|
|
|
|
switch (key) {
|
|
|
|
case LogicFactory.Type.Vertical:
|
|
|
|
LogicCls = VerticalLayoutLogic;
|
|
|
|
break;
|
|
|
|
case LogicFactory.Type.Horizontal:
|
|
|
|
LogicCls = HorizontalLayoutLogic;
|
|
|
|
break;
|
|
|
|
case LogicFactory.Type.Table:
|
|
|
|
LogicCls = TableLayoutLogic;
|
|
|
|
break;
|
|
|
|
case LogicFactory.Type.HorizontalFill:
|
|
|
|
LogicCls = HorizontalFillLayoutLogic;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LogicCls = Logic;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new LogicCls(options).createLogic();
|
|
|
|
},
|
|
|
|
|
|
|
|
createLogicTypeByDirection (direction) {
|
|
|
|
switch (direction) {
|
|
|
|
case Direction.Top:
|
|
|
|
case Direction.Bottom:
|
|
|
|
case Direction.Custom:
|
|
|
|
return LogicFactory.Type.Vertical;
|
|
|
|
case Direction.Left:
|
|
|
|
case Direction.Right:
|
|
|
|
return LogicFactory.Type.Horizontal;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
createLogicItemsByDirection (direction) {
|
|
|
|
let items = Array.prototype.slice.call(arguments, 1);
|
|
|
|
items = map(items, (i, item) => {
|
|
|
|
if (isWidget(item)) {
|
|
|
|
return {
|
|
|
|
el: item,
|
|
|
|
width: item.options.width,
|
|
|
|
height: item.options.height,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
switch (direction) {
|
|
|
|
case Direction.Bottom:
|
|
|
|
items.reverse();
|
|
|
|
break;
|
|
|
|
case Direction.Right:
|
|
|
|
items.reverse();
|
|
|
|
break;
|
|
|
|
case Direction.Custom:
|
|
|
|
items = items.slice(1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export {
|
|
|
|
Logic,
|
|
|
|
VerticalLayoutLogic,
|
|
|
|
HorizontalLayoutLogic,
|
|
|
|
TableLayoutLogic,
|
|
|
|
HorizontalFillLayoutLogic
|
|
|
|
};
|