All 16 managers now receive ManagerRegistry instance through constructor instead of calling ManagerRegistry.getInstance(). This enables each BimEngine instance to have its own isolated set of managers. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
/**
|
|
* 按钮组管理器
|
|
* 负责创建和管理按钮组实例
|
|
*/
|
|
import { BimButtonGroup } from '../components/button-group';
|
|
import type { ButtonGroupOptions } from '../components/button-group/index.type';
|
|
import type { ThemeConfig } from '../themes/types';
|
|
import { BaseManager } from '../core/base-manager';
|
|
import { ManagerRegistry } from '../core/manager-registry';
|
|
|
|
/**
|
|
* 按钮组管理器
|
|
* 统一管理多个按钮组的创建、主题更新和销毁
|
|
*/
|
|
export class ButtonGroupManager extends BaseManager {
|
|
/** 按钮组映射表 */
|
|
private groups: Map<string, BimButtonGroup> = new Map();
|
|
/** 容器元素 */
|
|
private container: HTMLElement;
|
|
|
|
constructor(container: HTMLElement, registry: ManagerRegistry) {
|
|
super(registry);
|
|
this.container = container;
|
|
}
|
|
|
|
/**
|
|
* 创建按钮组
|
|
* @param id 按钮组 ID
|
|
* @param options 按钮组配置
|
|
* @returns 按钮组实例
|
|
*/
|
|
public create(id: string, options: Omit<ButtonGroupOptions, 'container'>): BimButtonGroup {
|
|
const group = new BimButtonGroup({
|
|
container: this.container,
|
|
registry: this.registry,
|
|
...options
|
|
});
|
|
|
|
group.init();
|
|
this.groups.set(id, group);
|
|
return group;
|
|
}
|
|
|
|
/**
|
|
* 获取按钮组
|
|
* @param id 按钮组 ID
|
|
* @returns 按钮组实例
|
|
*/
|
|
public get(id: string): BimButtonGroup | undefined {
|
|
return this.groups.get(id);
|
|
}
|
|
|
|
/**
|
|
* 更新所有按钮组的主题
|
|
* @param theme 主题配置
|
|
*/
|
|
public updateTheme(theme: ThemeConfig) {
|
|
this.groups.forEach(group => group.setTheme(theme));
|
|
}
|
|
|
|
/** 销毁管理器和所有按钮组 */
|
|
public destroy() {
|
|
this.groups.forEach(group => group.destroy());
|
|
this.groups.clear();
|
|
super.destroy();
|
|
}
|
|
}
|