|
@@ -9,25 +9,45 @@ import type { PanelFactory, PanelConfig } from '../types';
|
|
|
|
|
|
|
|
export interface PanelElement {
|
|
export interface PanelElement {
|
|
|
key: string;
|
|
key: string;
|
|
|
|
|
+ style?: React.CSSProperties;
|
|
|
el: React.ReactNode;
|
|
el: React.ReactNode;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const PANEL_SIZE_DEFAULT = 400;
|
|
|
|
|
+
|
|
|
export class FloatPanel {
|
|
export class FloatPanel {
|
|
|
elements: PanelElement[] = [];
|
|
elements: PanelElement[] = [];
|
|
|
|
|
|
|
|
private onUpdateEmitter = new Emitter<void>();
|
|
private onUpdateEmitter = new Emitter<void>();
|
|
|
|
|
|
|
|
|
|
+ sizeMap = new Map<string, number>();
|
|
|
|
|
+
|
|
|
onUpdate = this.onUpdateEmitter.event;
|
|
onUpdate = this.onUpdateEmitter.event;
|
|
|
|
|
|
|
|
|
|
+ currentFactoryKey = '';
|
|
|
|
|
+
|
|
|
|
|
+ updateSize(newSize: number) {
|
|
|
|
|
+ this.sizeMap.set(this.currentFactoryKey, newSize);
|
|
|
|
|
+ this.onUpdateEmitter.fire();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ get currentSize(): number {
|
|
|
|
|
+ return this.sizeMap.get(this.currentFactoryKey) || PANEL_SIZE_DEFAULT;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
constructor(private config: PanelConfig) {}
|
|
constructor(private config: PanelConfig) {}
|
|
|
|
|
|
|
|
open(factory: PanelFactory<any>, options: any) {
|
|
open(factory: PanelFactory<any>, options: any) {
|
|
|
const el = factory.render(options?.props);
|
|
const el = factory.render(options?.props);
|
|
|
const idx = this.elements.findIndex((e) => e.key === factory.key);
|
|
const idx = this.elements.findIndex((e) => e.key === factory.key);
|
|
|
|
|
+ this.currentFactoryKey = factory.key;
|
|
|
|
|
+ if (!this.sizeMap.has(factory.key)) {
|
|
|
|
|
+ this.sizeMap.set(factory.key, factory.defaultSize || PANEL_SIZE_DEFAULT);
|
|
|
|
|
+ }
|
|
|
if (idx >= 0) {
|
|
if (idx >= 0) {
|
|
|
- this.elements[idx] = { el, key: factory.key };
|
|
|
|
|
|
|
+ this.elements[idx] = { el, key: factory.key, style: factory.style };
|
|
|
} else {
|
|
} else {
|
|
|
- this.elements.push({ el, key: factory.key });
|
|
|
|
|
|
|
+ this.elements.push({ el, key: factory.key, style: factory.style });
|
|
|
if (this.elements.length > this.config.max) {
|
|
if (this.elements.length > this.config.max) {
|
|
|
this.elements.shift();
|
|
this.elements.shift();
|
|
|
}
|
|
}
|
|
@@ -35,6 +55,10 @@ export class FloatPanel {
|
|
|
this.onUpdateEmitter.fire();
|
|
this.onUpdateEmitter.fire();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ get visible() {
|
|
|
|
|
+ return this.elements.length > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
close(key?: string) {
|
|
close(key?: string) {
|
|
|
if (!key) {
|
|
if (!key) {
|
|
|
this.elements = [];
|
|
this.elements = [];
|