|
|
import { Constructor } from "@implab/core-amd/interfaces";
|
|
|
import { HtmlElementContext } from "./tsx/HtmlElementContext";
|
|
|
import { WidgetContext } from "./tsx/WidgetContext";
|
|
|
import { isWidgetConstructor, BuildContext } from "./tsx/traits";
|
|
|
import { FunctionComponentContext } from "./tsx/FunctionComponentContext";
|
|
|
|
|
|
export function createElement<T extends Constructor | string | ((props: any) => Element)>(elementType: T, ...args: any[]): BuildContext {
|
|
|
if (typeof elementType === "string") {
|
|
|
const ctx = new HtmlElementContext(elementType);
|
|
|
if (args)
|
|
|
args.forEach(x => ctx.visitNext(x));
|
|
|
|
|
|
return ctx;
|
|
|
} else if (isWidgetConstructor(elementType)) {
|
|
|
const ctx = new WidgetContext(elementType);
|
|
|
if (args)
|
|
|
args.forEach(x => ctx.visitNext(x));
|
|
|
|
|
|
return ctx;
|
|
|
} else if (typeof elementType === "function") {
|
|
|
const ctx = new FunctionComponentContext(elementType as (props: any) => Element);
|
|
|
if (args)
|
|
|
args.forEach(x => ctx.visitNext(x));
|
|
|
|
|
|
return ctx;
|
|
|
} else {
|
|
|
throw new Error(`The element type '${elementType}' is unsupported`);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export interface EventDetails<T = any> {
|
|
|
detail: T;
|
|
|
}
|
|
|
|
|
|
export interface EventSelector {
|
|
|
selectorTarget: HTMLElement;
|
|
|
target: HTMLElement;
|
|
|
}
|
|
|
|
|
|
export type DojoMouseEvent<T = any> = MouseEvent & EventSelector & EventDetails<T>;
|
|
|
|