/// namespace Leaf { export class Namespace { private Widgets: { [index: string]: WidgetConstructor } = {} public include(W, name: string = W.prototype.widgetName) { if (W.prototype instanceof Widget) { if (this.Widgets[name]) { throw new Error(`Widget namespace conflicting: ${name}`) } this.Widgets[name] = W } else { console.warn(W, "not inherit WidgetBase") } } public getWidgetByName(name: string) { name = Leaf.Util.slugToCamel(name) name = Leaf.Util.capitalize(name) for (let widgetName in this.Widgets) { let W = this.Widgets[widgetName] if (widgetName == name || W["widgetName"] === name || W.prototype.widgetName === name || W.constructor["widgetName"] == name) { return W } } return null } public createWidgetByName(name: string, props?: any): WidgetAny { let W = this.getWidgetByName(name) if (!W) return let w = new W(props) as WidgetAny return w } public isTagWidgetName(name: string, who: WidgetAny) { name = Leaf.Util.slugToCamel(name) name = Leaf.Util.capitalize(name) if (name === who.widgetName) { return true } return false } public clear() { this.Widgets = {} } public has(name: string) { name = Leaf.Util.capitalize(Leaf.Util.slugToCamel(name)) if (this.Widgets[name]) return true return false } } }