##// END OF EJS Templates
corrected i18n, css modules to support requirejs optimizer...
corrected i18n, css modules to support requirejs optimizer i18n bundles now conforms js modules with default exports (breaking change!)

File last commit:

r52:0b9593714536 default
r53:deb0ed6fb680 v1.0.7 default
Show More
DjxWidgetBase.ts
77 lines | 2.8 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / tsx / DjxWidgetBase.ts
import { djbase, djclass } from "../declare";
import _WidgetBase = require("dijit/_WidgetBase");
import _AttachMixin = require("dijit/_AttachMixin");
import { BuildContext, isNode, startupWidgets } from "./traits";
import registry = require("dijit/registry");
// type Handle = dojo.Handle;
export interface EventArgs {
bubbles?: boolean;
cancelable?: boolean;
composed?: boolean;
}
export interface DjxWidgetBase<Attrs = any, Events extends { [name in keyof Events]: Event } = any> {
set<K extends keyof Attrs & string>(key: K, value: Attrs[K]): this;
set(props: Partial<Attrs>): this;
get<K extends keyof Attrs & string>(key: K): Attrs[K];
on<K extends keyof Events & string>(eventName: K, cb: (evt: Events[K]) => void): dojo.WatchHandle;
emit<K extends keyof Events & string>(eventName: K, evt: Omit<Events[K], keyof Event> & EventArgs ): void;
}
@djclass
export abstract class DjxWidgetBase<Attrs = any, Events = any> extends djbase(_WidgetBase, _AttachMixin) {
buildRendering() {
this.domNode = this.render().getDomNode();
super.buildRendering();
}
abstract render(): BuildContext<HTMLElement>;
_processTemplateNode<T extends (Element | Node | _WidgetBase)>(
baseNode: T,
getAttrFunc: (baseNode: T, attr: string) => string,
// tslint:disable-next-line: ban-types
attachFunc: (node: T, type: string, func?: Function) => dojo.Handle
): boolean {
if (isNode(baseNode)) {
const w = registry.byNode(baseNode);
if (w) {
// from dijit/_WidgetsInTemplateMixin
this._processTemplateNode(w,
(n, p) => n.get(p), // callback to get a property of a widget
(widget, type, callback) => {
if (!callback)
throw new Error("The callback must be specified");
// callback to do data-dojo-attach-event to a widget
if (type in widget) {
// back-compat, remove for 2.0
return widget.connect(widget, type, callback as EventListener);
} else {
// 1.x may never hit this branch, but it's the default for 2.0
return widget.on(type, callback);
}
});
// don't process widgets internals
return false;
}
}
return super._processTemplateNode(baseNode, getAttrFunc, attachFunc);
}
/** Starts current widget and all its supporting widgets (placed outside
* `containerNode`) and child widgets (placed inside `containerNode`)*/
startup() {
// startup supporting widgets
startupWidgets(this.domNode, this.containerNode);
super.startup();
}
}