tsx.ts
40 lines
| 1.3 KiB
| video/mp2t
|
TypeScriptLexer
cin
|
r6 | import { Constructor } from "@implab/core-amd/interfaces"; | ||
cin
|
r63 | import { HtmlRendition } from "./tsx/HtmlRendition"; | ||
import { WidgetRendition } from "./tsx/WidgetRendition"; | ||||
import { isWidgetConstructor, Rendition } from "./tsx/traits"; | ||||
import { FunctionRendition } from "./tsx/FunctionRendition"; | ||||
cin
|
r6 | |||
cin
|
r63 | export function createElement<T extends Constructor | string | ((props: any) => Element)>(elementType: T, ...args: any[]): Rendition { | ||
cin
|
r6 | if (typeof elementType === "string") { | ||
cin
|
r63 | const ctx = new HtmlRendition(elementType); | ||
cin
|
r6 | if (args) | ||
args.forEach(x => ctx.visitNext(x)); | ||||
return ctx; | ||||
} else if (isWidgetConstructor(elementType)) { | ||||
cin
|
r63 | const ctx = new WidgetRendition(elementType); | ||
cin
|
r6 | if (args) | ||
args.forEach(x => ctx.visitNext(x)); | ||||
return ctx; | ||||
cin
|
r34 | } else if (typeof elementType === "function") { | ||
cin
|
r63 | const ctx = new FunctionRendition(elementType as (props: any) => Element); | ||
cin
|
r34 | if (args) | ||
args.forEach(x => ctx.visitNext(x)); | ||||
return ctx; | ||||
cin
|
r6 | } 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>; | ||||