traits.ts
66 lines
| 1.8 KiB
| video/mp2t
|
TypeScriptLexer
|
|
r7 | import _WidgetBase = require("dijit/_WidgetBase"); | ||
| type _WidgetBaseConstructor = typeof _WidgetBase; | ||||
|
|
r14 | export type DojoNodePosition = "first" | "after" | "before" | "last" | "replace" | "only" | number; | ||
|
|
r7 | |||
|
|
r22 | export interface BuildContext<TNode extends Node = Node> { | ||
| getDomNode(): TNode; | ||||
|
|
r14 | |||
| placeAt(refNode: string | Node, position?: DojoNodePosition): void; | ||||
|
|
r7 | } | ||
|
|
r19 | export function isNode(el: any): el is Node { | ||
|
|
r7 | return el && el.nodeName && el.nodeType; | ||
| } | ||||
|
|
r19 | export function isElementNode(el: any): el is Element { | ||
| return isNode(el) && el.nodeType === 1; | ||||
| } | ||||
| export function isTextNode(el: any): el is Text { | ||||
| return isNode(el) && el.nodeType === 3; | ||||
| } | ||||
| export function isProcessingInstructionNode(el: any): el is ProcessingInstruction { | ||||
| return isNode(el) && el.nodeType === 7; | ||||
| } | ||||
| export function isCommentNode(el: any): el is Comment { | ||||
| return isNode(el) && el.nodeType === 8; | ||||
| } | ||||
| export function isDocumentNode(el: any): el is Document { | ||||
| return isNode(el) && el.nodeType === 9; | ||||
| } | ||||
| export function isDocumentTypeNode(el: any): el is DocumentType { | ||||
| return isNode(el) && el.nodeType === 10; | ||||
| } | ||||
| export function isDocumentFragmentNode(el: any): el is DocumentFragment { | ||||
| return isNode(el) && el.nodeType === 11; | ||||
| } | ||||
|
|
r7 | export function isWidget(v: any): v is _WidgetBase { | ||
| return v && "domNode" in v; | ||||
| } | ||||
| export function isBuildContext(v: any): v is BuildContext { | ||||
| return typeof v === "object" && typeof v.getDomElement === "function"; | ||||
| } | ||||
| export function isPlainObject(v: object) { | ||||
| if (typeof v !== "object") | ||||
| return false; | ||||
| const vp = Object.getPrototypeOf(v); | ||||
| return !vp || vp === Object.prototype; | ||||
| } | ||||
| export function isWidgetConstructor(v: any): v is _WidgetBaseConstructor { | ||||
|
|
r38 | return typeof v === "function" && v.prototype && ( | ||
| "domNode" in v.prototype || | ||||
| "buildRendering" in v.prototype | ||||
| ); | ||||
|
|
r7 | } | ||
