Add popup model
This commit is contained in:
parent
04060902e0
commit
3357960f61
@ -1,5 +1,5 @@
|
|||||||
import { AllI18nKeys, I18N } from "@Component/Localization/Localization";
|
import { AllI18nKeys, I18N } from "@Component/Localization/Localization";
|
||||||
import { useStatusWithEvent, IMixinSettingProps, Themes, Language } from "@Context/Setting";
|
import { useSettingWithEvent, IMixinSettingProps, Themes, Language } from "@Context/Setting";
|
||||||
import { FunctionComponent } from "react";
|
import { FunctionComponent } from "react";
|
||||||
import "./Message.scss";
|
import "./Message.scss";
|
||||||
|
|
||||||
@ -38,5 +38,5 @@ const MessageView: FunctionComponent<IMessageProps & IMixinSettingProps> = (prop
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
const Message = useStatusWithEvent("language", "themes")(MessageView);
|
const Message = useSettingWithEvent("language", "themes")(MessageView);
|
||||||
export { Message };
|
export { Message };
|
@ -36,18 +36,27 @@ class Popup {
|
|||||||
/**
|
/**
|
||||||
* 渲染函数
|
* 渲染函数
|
||||||
*/
|
*/
|
||||||
public rendererFunction: undefined | ((p: Popup) => ReactNode);
|
public onRender(p: Popup): ReactNode {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭回调
|
||||||
|
*/
|
||||||
|
public onClose(): void {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染节点
|
* 渲染节点
|
||||||
*/
|
*/
|
||||||
public render(): ReactNode {
|
public render(): ReactNode {
|
||||||
if (this.rendererFunction) {
|
this.reactNode = this.onRender(this);
|
||||||
this.reactNode = this.rendererFunction(this);
|
|
||||||
}
|
|
||||||
return this.reactNode;
|
return this.reactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public close() {
|
||||||
|
return this.controller.closePopup(this);
|
||||||
|
}
|
||||||
|
|
||||||
public constructor(controller: PopupController, id: string) {
|
public constructor(controller: PopupController, id: string) {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@ -82,6 +91,7 @@ class PopupController extends Emitter<IPopupControllerEvent> {
|
|||||||
popup.index = (index + 1);
|
popup.index = (index + 1);
|
||||||
return popup;
|
return popup;
|
||||||
});
|
});
|
||||||
|
this.emit("popupChange");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,7 +100,7 @@ class PopupController extends Emitter<IPopupControllerEvent> {
|
|||||||
public showPopup<P extends IPopupConstructor>(popup?: P): Popup {
|
public showPopup<P extends IPopupConstructor>(popup?: P): Popup {
|
||||||
let newPopup = new (popup ?? Popup)(this, `P-${this.idIndex ++}`);
|
let newPopup = new (popup ?? Popup)(this, `P-${this.idIndex ++}`);
|
||||||
this.popups.push(newPopup);
|
this.popups.push(newPopup);
|
||||||
this.emit("popupChange");
|
this.sortPopup();
|
||||||
return newPopup;
|
return newPopup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +120,8 @@ class PopupController extends Emitter<IPopupControllerEvent> {
|
|||||||
let isDelete = currentPopup.id === id;
|
let isDelete = currentPopup.id === id;
|
||||||
if (isDelete) {
|
if (isDelete) {
|
||||||
closePopup = currentPopup;
|
closePopup = currentPopup;
|
||||||
|
currentPopup.isClose = true;
|
||||||
|
currentPopup.onClose();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
@ -117,6 +129,7 @@ class PopupController extends Emitter<IPopupControllerEvent> {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (closePopup) {
|
if (closePopup) {
|
||||||
|
this.sortPopup();
|
||||||
this.emit("popupChange");
|
this.emit("popupChange");
|
||||||
}
|
}
|
||||||
return closePopup;
|
return closePopup;
|
||||||
|
@ -14,7 +14,7 @@ enum Themes {
|
|||||||
type Language = "ZH_CN" | "EN_US";
|
type Language = "ZH_CN" | "EN_US";
|
||||||
|
|
||||||
interface ISettingEvents extends Setting {
|
interface ISettingEvents extends Setting {
|
||||||
change: keyof Setting;
|
attrChange: keyof Setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Setting extends Emitter<ISettingEvents> {
|
class Setting extends Emitter<ISettingEvents> {
|
||||||
@ -39,7 +39,7 @@ class Setting extends Emitter<ISettingEvents> {
|
|||||||
*/
|
*/
|
||||||
public setProps<P extends keyof Setting>(key: P, value: Setting[P]) {
|
public setProps<P extends keyof Setting>(key: P, value: Setting[P]) {
|
||||||
this[key] = value as any;
|
this[key] = value as any;
|
||||||
this.emit("change", key);
|
this.emit("attrChange", key);
|
||||||
this.emit(key as any, value as any);
|
this.emit(key as any, value as any);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,9 +59,9 @@ const SettingConsumer = SettingContext.Consumer;
|
|||||||
*/
|
*/
|
||||||
const useSetting = superConnect<Setting>(SettingConsumer, "setting");
|
const useSetting = superConnect<Setting>(SettingConsumer, "setting");
|
||||||
|
|
||||||
const useStatusWithEvent = superConnectWithEvent<Setting, ISettingEvents>(SettingConsumer, "setting");
|
const useSettingWithEvent = superConnectWithEvent<Setting, ISettingEvents>(SettingConsumer, "setting");
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Themes, Setting, SettingContext, useSetting, Language, useStatusWithEvent,
|
Themes, Setting, SettingContext, useSetting, Language, useSettingWithEvent,
|
||||||
IMixinSettingProps, SettingProvider, SettingConsumer
|
IMixinSettingProps, SettingProvider, SettingConsumer
|
||||||
};
|
};
|
@ -1,4 +1,4 @@
|
|||||||
import { createContext, Component, FunctionComponent, ReactNode } from "react";
|
import { createContext } from "react";
|
||||||
import { Emitter } from "@Model/Emitter";
|
import { Emitter } from "@Model/Emitter";
|
||||||
import { Model, ObjectID } from "@Model/Model";
|
import { Model, ObjectID } from "@Model/Model";
|
||||||
import { Label } from "@Model/Label";
|
import { Label } from "@Model/Label";
|
||||||
@ -10,6 +10,7 @@ import { ClassicRenderer, MouseMod } from "@GLRender/ClassicRenderer";
|
|||||||
import { Setting } from "./Setting";
|
import { Setting } from "./Setting";
|
||||||
import { I18N } from "@Component/Localization/Localization";
|
import { I18N } from "@Component/Localization/Localization";
|
||||||
import { superConnectWithEvent, superConnect } from "./Context";
|
import { superConnectWithEvent, superConnect } from "./Context";
|
||||||
|
import { PopupController } from "./Popups";
|
||||||
|
|
||||||
function randomColor(unNormal: boolean = false) {
|
function randomColor(unNormal: boolean = false) {
|
||||||
const color = [
|
const color = [
|
||||||
@ -39,6 +40,7 @@ interface IStatusEvent {
|
|||||||
labelAttrChange: void;
|
labelAttrChange: void;
|
||||||
groupAttrChange: void;
|
groupAttrChange: void;
|
||||||
individualChange: void;
|
individualChange: void;
|
||||||
|
popupChange: void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Status extends Emitter<IStatusEvent> {
|
class Status extends Emitter<IStatusEvent> {
|
||||||
@ -66,6 +68,11 @@ class Status extends Emitter<IStatusEvent> {
|
|||||||
*/
|
*/
|
||||||
public model: Model = new Model();
|
public model: Model = new Model();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弹窗
|
||||||
|
*/
|
||||||
|
public popup: PopupController = new PopupController();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 焦点对象
|
* 焦点对象
|
||||||
*/
|
*/
|
||||||
@ -96,6 +103,9 @@ class Status extends Emitter<IStatusEvent> {
|
|||||||
this.model.on("objectChange", () => this.emit("objectChange"));
|
this.model.on("objectChange", () => this.emit("objectChange"));
|
||||||
this.model.on("labelChange", () => this.emit("labelChange"));
|
this.model.on("labelChange", () => this.emit("labelChange"));
|
||||||
|
|
||||||
|
// 弹窗事件
|
||||||
|
this.popup.on("popupChange", () => this.emit("popupChange"));
|
||||||
|
|
||||||
// 对象变换时执行渲染,更新渲染器数据
|
// 对象变换时执行渲染,更新渲染器数据
|
||||||
this.on("objectChange", this.delayDraw);
|
this.on("objectChange", this.delayDraw);
|
||||||
this.model.on("individualChange", this.delayDraw);
|
this.model.on("individualChange", this.delayDraw);
|
||||||
|
Loading…
Reference in New Issue
Block a user