@@ -0,0 +1,23 | |||
|
1 | import { _Widget } from "./WidgetContext"; | |
|
2 | import { MapOf } from "@implab/core-amd/interfaces"; | |
|
3 | ||
|
4 | /** Special widget used to create a document fragment */ | |
|
5 | export class DjxFragment implements _Widget { | |
|
6 | ||
|
7 | domNode: Node; | |
|
8 | ||
|
9 | containerNode?: Node; | |
|
10 | ||
|
11 | constructor() { | |
|
12 | this.domNode = this.containerNode = document.createDocumentFragment(); | |
|
13 | } | |
|
14 | ||
|
15 | get(attr: string) { | |
|
16 | return undefined; | |
|
17 | } | |
|
18 | set(attr: string, value: any): void; | |
|
19 | set(attrs: MapOf<any>): void; | |
|
20 | set() { | |
|
21 | /* do nothing */ | |
|
22 | } | |
|
23 | } No newline at end of file |
@@ -68,6 +68,7 class DomInject { | |||
|
68 | 68 | trace.log("done {0}", url); |
|
69 | 69 | } catch (e) { |
|
70 | 70 | trace.error("failed {0}: {1}", url, e); |
|
71 | throw e; | |
|
71 | 72 | } |
|
72 | 73 | } |
|
73 | 74 | |
@@ -87,6 +88,7 class DomInject { | |||
|
87 | 88 | trace.log("done {0}", url); |
|
88 | 89 | } catch (e) { |
|
89 | 90 | trace.error("failed {0}: {1}", url, e); |
|
91 | throw e; | |
|
90 | 92 | } |
|
91 | 93 | } |
|
92 | 94 | }; |
@@ -1,4 +1,4 | |||
|
1 |
import { isNull, mixin |
|
|
1 | import { isNull, mixin } from "@implab/core-amd/safe"; | |
|
2 | 2 | import { isPlainObject, isNode, isBuildContext, DojoNodePosition, BuildContext } from "./traits"; |
|
3 | 3 | |
|
4 | 4 | import dom = require("dojo/dom-construct"); |
@@ -37,13 +37,13 export abstract class BuildContextBase i | |||
|
37 | 37 | } else if (isNode(v)) { |
|
38 | 38 | return v; |
|
39 | 39 | } else if (isBuildContext(v)) { |
|
40 |
return v.getDom |
|
|
40 | return v.getDomNode(); | |
|
41 | 41 | } else { |
|
42 | 42 | throw new Error("Invalid parameter"); |
|
43 | 43 | } |
|
44 | 44 | } |
|
45 | 45 | |
|
46 |
abstract _getDom |
|
|
46 | abstract _getDomNode(): Node; | |
|
47 | 47 | |
|
48 | 48 | ensureCreated() { |
|
49 | 49 | if (!this._created) { |
@@ -54,13 +54,18 export abstract class BuildContextBase i | |||
|
54 | 54 | } |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | /** @deprecated use getDomNode() */ | |
|
57 | 58 | getDomElement() { |
|
59 | return this.getDomNode(); | |
|
60 | } | |
|
61 | ||
|
62 | getDomNode() { | |
|
58 | 63 | this.ensureCreated(); |
|
59 |
return this._getDom |
|
|
64 | return this._getDomNode(); | |
|
60 | 65 | } |
|
61 | 66 | |
|
62 | 67 | placeAt(refNode: string | Node, position?: DojoNodePosition) { |
|
63 |
dom.place(this.getDom |
|
|
68 | dom.place(this.getDomNode(), refNode, position); | |
|
64 | 69 | } |
|
65 | 70 | |
|
66 | 71 | abstract _addChild(child: any): void; |
@@ -11,7 +11,7 import { Handle } from "dojo/interfaces" | |||
|
11 | 11 | export abstract class DjxWidgetBase extends djbase(_WidgetBase, _AttachMixin) { |
|
12 | 12 | |
|
13 | 13 | buildRendering() { |
|
14 |
this.domNode = this.render().getDom |
|
|
14 | this.domNode = this.render().getDomNode(); | |
|
15 | 15 | super.buildRendering(); |
|
16 | 16 | } |
|
17 | 17 |
@@ -35,7 +35,7 export class HtmlElementContext extends | |||
|
35 | 35 | children.forEach(v => this._addChild(v)); |
|
36 | 36 | } |
|
37 | 37 | |
|
38 |
_getDom |
|
|
38 | _getDomNode() { | |
|
39 | 39 | if (!this._element) |
|
40 | 40 | throw new Error("The HTML element isn't created"); |
|
41 | 41 |
@@ -1,16 +1,28 | |||
|
1 | 1 | import dom = require("dojo/dom-construct"); |
|
2 | 2 | import { argumentNotNull } from "@implab/core-amd/safe"; |
|
3 | import _WidgetBase = require("dijit/_WidgetBase"); | |
|
4 | 3 | import { BuildContextBase } from "./BuildContextBase"; |
|
4 | import { MapOf } from "@implab/core-amd/interfaces"; | |
|
5 | 5 | |
|
6 | type _WidgetBaseConstructor = typeof _WidgetBase; | |
|
6 | // tslint:disable-next-line: class-name | |
|
7 | export interface _Widget { | |
|
8 | domNode: Node; | |
|
9 | ||
|
10 | get(attr: string): any; | |
|
11 | ||
|
12 | set(attr: string, value: any): void; | |
|
13 | set(attrs: MapOf<any>): void; | |
|
14 | ||
|
15 | containerNode?: Node | |
|
16 | } | |
|
17 | ||
|
18 | export type _WidgetCtor = new (attrs: any, srcNode?: string | Node) => _Widget; | |
|
7 | 19 | |
|
8 | 20 | export class WidgetContext extends BuildContextBase { |
|
9 |
widgetClass: _Widget |
|
|
21 | widgetClass: _WidgetCtor; | |
|
10 | 22 | |
|
11 |
_instance: _Widget |
|
|
23 | _instance: _Widget | undefined; | |
|
12 | 24 | |
|
13 |
constructor(widgetClass: _Widget |
|
|
25 | constructor(widgetClass: _WidgetCtor) { | |
|
14 | 26 | super(); |
|
15 | 27 | argumentNotNull(widgetClass, "widgetClass"); |
|
16 | 28 | |
@@ -34,7 +46,7 export class WidgetContext extends Build | |||
|
34 | 46 | children.forEach(x => this._addChild(x)); |
|
35 | 47 | } |
|
36 | 48 | |
|
37 |
_getDom |
|
|
49 | _getDomNode() { | |
|
38 | 50 | if (!this._instance) |
|
39 | 51 | throw new Error("The instance of the widget isn't created"); |
|
40 | 52 | return this._instance.domNode; |
@@ -5,15 +5,43 type _WidgetBaseConstructor = typeof _Wi | |||
|
5 | 5 | export type DojoNodePosition = "first" | "after" | "before" | "last" | "replace" | "only" | number; |
|
6 | 6 | |
|
7 | 7 | export interface BuildContext { |
|
8 |
getDom |
|
|
8 | getDomNode(): Node; | |
|
9 | 9 | |
|
10 | 10 | placeAt(refNode: string | Node, position?: DojoNodePosition): void; |
|
11 | 11 | } |
|
12 | 12 | |
|
13 |
export function isNode(el: any): el is |
|
|
13 | export function isNode(el: any): el is Node { | |
|
14 | 14 | return el && el.nodeName && el.nodeType; |
|
15 | 15 | } |
|
16 | 16 | |
|
17 | export function isElementNode(el: any): el is Element { | |
|
18 | return isNode(el) && el.nodeType === 1; | |
|
19 | } | |
|
20 | ||
|
21 | export function isTextNode(el: any): el is Text { | |
|
22 | return isNode(el) && el.nodeType === 3; | |
|
23 | } | |
|
24 | ||
|
25 | export function isProcessingInstructionNode(el: any): el is ProcessingInstruction { | |
|
26 | return isNode(el) && el.nodeType === 7; | |
|
27 | } | |
|
28 | ||
|
29 | export function isCommentNode(el: any): el is Comment { | |
|
30 | return isNode(el) && el.nodeType === 8; | |
|
31 | } | |
|
32 | ||
|
33 | export function isDocumentNode(el: any): el is Document { | |
|
34 | return isNode(el) && el.nodeType === 9; | |
|
35 | } | |
|
36 | ||
|
37 | export function isDocumentTypeNode(el: any): el is DocumentType { | |
|
38 | return isNode(el) && el.nodeType === 10; | |
|
39 | } | |
|
40 | ||
|
41 | export function isDocumentFragmentNode(el: any): el is DocumentFragment { | |
|
42 | return isNode(el) && el.nodeType === 11; | |
|
43 | } | |
|
44 | ||
|
17 | 45 | export function isWidget(v: any): v is _WidgetBase { |
|
18 | 46 | return v && "domNode" in v; |
|
19 | 47 | } |
General Comments 0
You need to be logged in to leave comments.
Login now