2022-05-26 15:18:53 +08:00
|
|
|
import {Wnd} from "./Wnd";
|
|
|
|
|
import {genUUID} from "../util/genID";
|
2024-04-15 11:43:46 +08:00
|
|
|
import {addResize, fixWndFlex1} from "./util";
|
2023-10-25 17:06:19 +08:00
|
|
|
import {resizeTabs} from "./tabUtil";
|
2022-06-30 18:19:05 +08:00
|
|
|
/// #if MOBILE
|
|
|
|
|
// 检测移动端是否引入了桌面端的代码
|
2023-05-16 18:51:13 +08:00
|
|
|
console.error("Need remove unused code");
|
2024-04-15 11:43:46 +08:00
|
|
|
|
2022-06-30 18:19:05 +08:00
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
export class Layout {
|
|
|
|
|
public element: HTMLElement;
|
|
|
|
|
public children?: Array<Layout | Wnd>;
|
|
|
|
|
public parent?: Layout;
|
2024-03-25 09:33:22 +08:00
|
|
|
public direction: Config.TUILayoutDirection;
|
|
|
|
|
public type?: Config.TUILayoutType;
|
2022-05-26 15:18:53 +08:00
|
|
|
public id?: string;
|
2024-03-25 09:33:22 +08:00
|
|
|
public resize?: Config.TUILayoutDirection;
|
2022-05-26 15:18:53 +08:00
|
|
|
public size?: string;
|
|
|
|
|
|
|
|
|
|
constructor(options?: ILayoutOptions) {
|
2024-03-25 09:33:22 +08:00
|
|
|
const mergedOptions: ILayoutOptions = Object.assign({
|
2022-05-26 15:18:53 +08:00
|
|
|
direction: "tb",
|
|
|
|
|
size: "auto",
|
|
|
|
|
type: "normal"
|
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
|
|
this.id = genUUID();
|
|
|
|
|
this.direction = mergedOptions.direction;
|
|
|
|
|
this.type = mergedOptions.type;
|
|
|
|
|
this.size = mergedOptions.size;
|
|
|
|
|
this.resize = options.resize;
|
|
|
|
|
this.children = [];
|
|
|
|
|
|
|
|
|
|
this.element = options.element || document.createElement("div");
|
|
|
|
|
if (this.type === "center") {
|
|
|
|
|
this.element.classList.add("layout__center");
|
|
|
|
|
}
|
|
|
|
|
if (mergedOptions.direction === "tb") {
|
|
|
|
|
this.element.classList.add("fn__flex-column");
|
|
|
|
|
} else {
|
|
|
|
|
this.element.classList.add("fn__flex");
|
|
|
|
|
}
|
|
|
|
|
if (mergedOptions.type === "left") {
|
|
|
|
|
this.element.classList.add("fn__flex-shrink");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addLayout(child: Layout, id?: string) {
|
|
|
|
|
if (!id) {
|
|
|
|
|
this.children.splice(this.children.length, 0, child);
|
|
|
|
|
if (this) {
|
|
|
|
|
this.element.append(child.element);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.children.find((item, index) => {
|
|
|
|
|
if (item.id === id) {
|
|
|
|
|
this.children.splice(index + 1, 0, child);
|
|
|
|
|
item.element.after(child.element);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (child.size === "auto") {
|
|
|
|
|
child.element.classList.add("fn__flex-1");
|
|
|
|
|
} else {
|
|
|
|
|
child.element.style[(this && this.direction === "lr") ? "width" : "height"] = child.size;
|
|
|
|
|
}
|
|
|
|
|
addResize(child);
|
|
|
|
|
child.parent = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addWnd(child: Wnd, id?: string) {
|
|
|
|
|
if (!id) {
|
|
|
|
|
this.children.splice(this.children.length, 0, child);
|
|
|
|
|
this.element.append(child.element);
|
|
|
|
|
} else {
|
|
|
|
|
this.children.find((item, index) => {
|
|
|
|
|
if (item.id === id) {
|
|
|
|
|
this.children.splice(index + 1, 0, child);
|
2022-10-26 23:12:41 +08:00
|
|
|
if (this.direction === "lr") {
|
|
|
|
|
// 向右分屏,左侧文档抖动,移除动画和边距
|
2023-02-15 15:25:25 +08:00
|
|
|
item.element.querySelectorAll(".protyle-content").forEach((element: HTMLElement) => {
|
|
|
|
|
if (!element.parentElement.classList.contains("fn__none")) {
|
|
|
|
|
element.classList.remove("protyle-content--transition");
|
2023-08-04 22:10:55 +08:00
|
|
|
(element.querySelector(".protyle-wysiwyg") as HTMLElement).style.padding = "";
|
2023-02-15 15:25:25 +08:00
|
|
|
element.classList.add("protyle-content--transition");
|
|
|
|
|
}
|
2022-10-26 23:12:41 +08:00
|
|
|
});
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
item.element.after(child.element);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-15 11:43:46 +08:00
|
|
|
fixWndFlex1(this);
|
2022-05-26 15:18:53 +08:00
|
|
|
addResize(child);
|
2023-12-31 12:27:18 +08:00
|
|
|
resizeTabs(false);
|
2022-05-26 15:18:53 +08:00
|
|
|
child.parent = this;
|
|
|
|
|
}
|
|
|
|
|
}
|