##// END OF EJS Templates
Added tag v1.0.9 for changeset f2499237b5bf
Added tag v1.0.9 for changeset f2499237b5bf

File last commit:

r48:030ea350f98b v1.0.3 default
r58:ca915f0520a5 default
Show More
BuildContextBase.ts
89 lines | 2.8 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / tsx / BuildContextBase.ts
cin
Added DjxFragment...
r19 import { isNull, mixin } from "@implab/core-amd/safe";
cin
Added support for ContentPane, corrected widget startup calls
r48 import { isPlainObject, isNode, isBuildContext, DojoNodePosition, BuildContext, isInPage } from "./traits";
cin
sync
r7
cin
Added placeAt() method to BuildContext
r14 import dom = require("dojo/dom-construct");
cin
Fixes in WidgetContex, added _Container.addChild support
r38 import registry = require("dijit/registry");
cin
Added placeAt() method to BuildContext
r14
cin
Added support for ContentPane, corrected widget startup calls
r48
cin
Switched to dojo-typings...
r22 export abstract class BuildContextBase<TNode extends Node> implements BuildContext<TNode> {
cin
Support for Function Components...
r34 private _attrs = {};
cin
sync
r7
cin
Support for Function Components...
r34 private _children = new Array();
cin
sync
r7
cin
Support for Function Components...
r34 private _created: boolean = false;
cin
sync
r7
visitNext(v: any) {
cin
Support for Function Components...
r34 if (this._created)
throw new Error("The Element is already created");
cin
Working on IntrisictElements to support legacy and new tsx styles
r40 if (isNull(v) || typeof v === "boolean")
// skip null, undefined, booleans ( this will work: {value && <span>{value}</span>} )
cin
sync
r7 return;
if (isPlainObject(v)) {
cin
Support for Function Components...
r34 mixin(this._attrs, v);
cin
tsx: Added auto unfolding arrays of children when constructing DOM
r13 } else if (v instanceof Array) {
cin
Support for Function Components...
r34 v.forEach(x => this.visitNext(x));
cin
sync
r7 } else {
cin
Support for Function Components...
r34 this._children.push(v);
cin
sync
r7 }
}
getChildDom(v: any) {
const tv = typeof v;
cin
Working on IntrisictElements to support legacy and new tsx styles
r40 if (tv === "string" || tv === "number" || v instanceof RegExp || v instanceof Date) {
cin
sync
r7 return document.createTextNode(v.toString());
} else if (isNode(v)) {
return v;
} else if (isBuildContext(v)) {
cin
Added DjxFragment...
r19 return v.getDomNode();
cin
sync
r7 } else {
throw new Error("Invalid parameter");
}
}
ensureCreated() {
if (!this._created) {
this._create(this._attrs, this._children);
this._children = [];
this._attrs = {};
this._created = true;
}
}
cin
Fixes in WidgetContex, added _Container.addChild support
r38 /** @deprecated will be removed in 1.0.0, use getDomNode() */
cin
sync
r7 getDomElement() {
cin
Added DjxFragment...
r19 return this.getDomNode();
}
cin
Fixes in WidgetContex, added _Container.addChild support
r38 /** Creates DOM node if not created. No additional actions are taken. */
cin
Added DjxFragment...
r19 getDomNode() {
cin
sync
r7 this.ensureCreated();
cin
Added DjxFragment...
r19 return this._getDomNode();
cin
sync
r7 }
cin
Fixes in WidgetContex, added _Container.addChild support
r38 /** Creates DOM node if not created, places it to the specified position
* and calls startup() method for all widgets contained by this node.
*
* @param {string | Node} refNode The reference node where the created
* DOM should be placed.
* @param {DojoNodePosition} position Optional parameter, specifies the
* position relative to refNode. Default is "last" (i.e. last child).
*/
cin
Added placeAt() method to BuildContext
r14 placeAt(refNode: string | Node, position?: DojoNodePosition) {
cin
Fixes in WidgetContex, added _Container.addChild support
r38 const domNode = this.getDomNode();
dom.place(domNode, refNode, position);
cin
Added support for ContentPane, corrected widget startup calls
r48 const parentWidget = domNode.parentNode ? registry.getEnclosingWidget(domNode.parentNode) : null;
if ((parentWidget && parentWidget._started) || isInPage(domNode))
this._startup();
}
_startup () {
registry.findWidgets(this._getDomNode()).forEach(w => w.startup());
cin
Added placeAt() method to BuildContext
r14 }
cin
sync
r7 abstract _create(attrs: object, children: any[]): void;
cin
Fixes in WidgetContex, added _Container.addChild support
r38
abstract _getDomNode(): TNode;
cin
sync
r7 }