| @@ -40,7 +40,7 class DomInject { | |||||
| 40 | 
             | 
        40 | |||
| 41 | const noerr = on(node, "error", e => { | 
             | 
        41 | const noerr = on(node, "error", e => { | |
| 42 | fail({ | 
             | 
        42 | fail({ | |
| 43 | 
            
                                er | 
        
             | 
        43 | error: e, | |
| 44 | node | 
             | 
        44 | node | |
| 45 | }); | 
             | 
        45 | }); | |
| 46 | cleanup(); | 
             | 
        46 | cleanup(); | |
| @@ -1,7 +1,7 | |||||
| 1 | import { djbase, djclass } from "../declare"; | 
             | 
        1 | import { djbase, djclass } from "../declare"; | |
| 2 | import _WidgetBase = require("dijit/_WidgetBase"); | 
             | 
        2 | import _WidgetBase = require("dijit/_WidgetBase"); | |
| 3 | import _AttachMixin = require("dijit/_AttachMixin"); | 
             | 
        3 | import _AttachMixin = require("dijit/_AttachMixin"); | |
| 4 | import { BuildContext, isNode } from "./traits"; | 
             | 
        4 | import { BuildContext, isNode, startupWidgets } from "./traits"; | |
| 5 | import registry = require("dijit/registry"); | 
             | 
        5 | import registry = require("dijit/registry"); | |
| 6 | 
             | 
        6 | |||
| 7 | // type Handle = dojo.Handle; | 
             | 
        7 | // type Handle = dojo.Handle; | |
| @@ -66,4 +66,12 export abstract class DjxWidgetBase<Attr | |||||
| 66 | } | 
             | 
        66 | } | |
| 67 | return super._processTemplateNode(baseNode, getAttrFunc, attachFunc); | 
             | 
        67 | return super._processTemplateNode(baseNode, getAttrFunc, attachFunc); | |
| 68 | } | 
             | 
        68 | } | |
| 
             | 
        69 | ||||
| 
             | 
        70 | /** Starts current widget and all its supporting widgets (placed outside | |||
| 
             | 
        71 | * `containerNode`) and child widgets (placed inside `containerNode`)*/ | |||
| 
             | 
        72 | startup() { | |||
| 
             | 
        73 | // startup supporting widgets | |||
| 
             | 
        74 | startupWidgets(this.domNode, this.containerNode); | |||
| 
             | 
        75 | super.startup(); | |||
| 
             | 
        76 | } | |||
| 69 | } | 
             | 
        77 | } | |
| @@ -1,8 +1,6 | |||||
| 1 | import dom = require("dojo/dom-construct"); | 
             | 
        1 | import dom = require("dojo/dom-construct"); | |
| 2 | import attr = require("dojo/dom-attr"); | 
             | 
        |||
| 3 | import { argumentNotEmptyString } from "@implab/core-amd/safe"; | 
             | 
        2 | import { argumentNotEmptyString } from "@implab/core-amd/safe"; | |
| 4 | import { BuildContextBase } from "./BuildContextBase"; | 
             | 
        3 | import { BuildContextBase } from "./BuildContextBase"; | |
| 5 | import registry = require("dijit/registry"); | 
             | 
        |||
| 6 | 
             | 
        4 | |||
| 7 | export class HtmlElementContext extends BuildContextBase<HTMLElement> { | 
             | 
        5 | export class HtmlElementContext extends BuildContextBase<HTMLElement> { | |
| 8 | elementType: string; | 
             | 
        6 | elementType: string; | |
| @@ -1,4 +1,8 | |||||
| 
             | 
        1 | import { IDestroyable } from "@implab/core-amd/interfaces"; | |||
| 
             | 
        2 | import { isDestroyable } from "@implab/core-amd/safe"; | |||
| 1 | import _WidgetBase = require("dijit/_WidgetBase"); | 
             | 
        3 | import _WidgetBase = require("dijit/_WidgetBase"); | |
| 
             | 
        4 | import registry = require("dijit/registry"); | |||
| 
             | 
        5 | import dom = require("dojo/dom-construct"); | |||
| 2 | 
             | 
        6 | |||
| 3 | type _WidgetBaseConstructor = typeof _WidgetBase; | 
             | 
        7 | type _WidgetBaseConstructor = typeof _WidgetBase; | |
| 4 | 
             | 
        8 | |||
| @@ -10,6 +14,10 export interface BuildContext<TNode exte | |||||
| 10 | placeAt(refNode: string | Node, position?: DojoNodePosition): void; | 
             | 
        14 | placeAt(refNode: string | Node, position?: DojoNodePosition): void; | |
| 11 | } | 
             | 
        15 | } | |
| 12 | 
             | 
        16 | |||
| 
             | 
        17 | export interface IRecursivelyDestroyable { | |||
| 
             | 
        18 | destroyRecursive(): void; | |||
| 
             | 
        19 | } | |||
| 
             | 
        20 | ||||
| 13 | export function isNode(el: any): el is Node { | 
             | 
        21 | export function isNode(el: any): el is Node { | |
| 14 | return el && el.nodeName && el.nodeType; | 
             | 
        22 | return el && el.nodeName && el.nodeType; | |
| 15 | } | 
             | 
        23 | } | |
| @@ -71,3 +79,52 export function isWidgetConstructor(v: a | |||||
| 71 | export function isInPage(node: Node) { | 
             | 
        79 | export function isInPage(node: Node) { | |
| 72 | return (node === document.body) ? false : document.body.contains(node); | 
             | 
        80 | return (node === document.body) ? false : document.body.contains(node); | |
| 73 | } | 
             | 
        81 | } | |
| 
             | 
        82 | ||||
| 
             | 
        83 | export function isRecursivelyDestroyable(target: any): target is IRecursivelyDestroyable { | |||
| 
             | 
        84 | return target && typeof target.destroyRecursive === "function"; | |||
| 
             | 
        85 | } | |||
| 
             | 
        86 | ||||
| 
             | 
        87 | ||||
| 
             | 
        88 | /** Destroys DOM Node with all contained widgets. | |||
| 
             | 
        89 | * If the specified node is the root node of a widget, then the | |||
| 
             | 
        90 | * widget will be destroyed. | |||
| 
             | 
        91 | * | |||
| 
             | 
        92 | * @param target DOM Node or widget to destroy | |||
| 
             | 
        93 | */ | |||
| 
             | 
        94 | export function destroy(target: Node | IDestroyable | IRecursivelyDestroyable) { | |||
| 
             | 
        95 | if (isRecursivelyDestroyable(target)) { | |||
| 
             | 
        96 | target.destroyRecursive(); | |||
| 
             | 
        97 | } else if (isDestroyable(target)) { | |||
| 
             | 
        98 | target.destroy(); | |||
| 
             | 
        99 | } else if (isNode(target)) { | |||
| 
             | 
        100 | const self = registry.byNode(target); | |||
| 
             | 
        101 | if (self) { | |||
| 
             | 
        102 | self.destroyRecursive(); | |||
| 
             | 
        103 | } else { | |||
| 
             | 
        104 | registry.findWidgets(target).forEach(destroy); | |||
| 
             | 
        105 | dom.destroy(target); | |||
| 
             | 
        106 | } | |||
| 
             | 
        107 | } | |||
| 
             | 
        108 | } | |||
| 
             | 
        109 | ||||
| 
             | 
        110 | /** Empties a content of the specified node and destroys all contained widgets. | |||
| 
             | 
        111 | * | |||
| 
             | 
        112 | * @param target DOM node to . | |||
| 
             | 
        113 | */ | |||
| 
             | 
        114 | export function emptyNode(target: Node) { | |||
| 
             | 
        115 | registry.findWidgets(target).forEach(destroy); | |||
| 
             | 
        116 | dom.empty(target); | |||
| 
             | 
        117 | } | |||
| 
             | 
        118 | ||||
| 
             | 
        119 | /** This function starts all widgets inside the DOM node if the target is a node, | |||
| 
             | 
        120 | * or starts widget itself if the target is the widget. | |||
| 
             | 
        121 | * | |||
| 
             | 
        122 | * @param target DOM node to find and start widgets or the widget itself. | |||
| 
             | 
        123 | */ | |||
| 
             | 
        124 | export function startupWidgets(target: Node | _WidgetBase, skipNode?: Node) { | |||
| 
             | 
        125 | if (isNode(target)) { | |||
| 
             | 
        126 | registry.findWidgets(target, skipNode).forEach(w => w.startup()); | |||
| 
             | 
        127 | } else { | |||
| 
             | 
        128 | target.startup(); | |||
| 
             | 
        129 | } | |||
| 
             | 
        130 | } No newline at end of file | |||
| @@ -14,7 +14,8 declare namespace JSX { | |||||
| 14 | 
             | 
        14 | |||
| 15 | /** specifies handlers map for the events */ | 
             | 
        15 | /** specifies handlers map for the events */ | |
| 16 | "data-dojo-attach-event": string; | 
             | 
        16 | "data-dojo-attach-event": string; | |
| 17 | 
             | 
        17 | |||
| 
             | 
        18 | /** @deprecated */ | |||
| 18 | [attr: string]: any; | 
             | 
        19 | [attr: string]: any; | |
| 19 | } | 
             | 
        20 | } | |
| 20 | 
             | 
        21 | |||
| @@ -40,7 +41,23 declare namespace JSX { | |||||
| 40 | 
             | 
        41 | |||
| 41 | type ElementAttrType<E, K extends keyof any> = K extends keyof E ? RecursivePartial<E[K]> : string; | 
             | 
        42 | type ElementAttrType<E, K extends keyof any> = K extends keyof E ? RecursivePartial<E[K]> : string; | |
| 42 | 
             | 
        43 | |||
| 43 | type LaxElement<E extends object> = ExcludeMembers<Omit<E, "children">, (...args: any[]) => any> & DjxIntrinsicAttributes; | 
             | 
        44 | ||
| 
             | 
        45 | type ElementAttrNamesBlacklist = "children" | "getRootNode" | keyof EventTarget; | |||
| 
             | 
        46 | ||||
| 
             | 
        47 | /** This type extracts keys of the specified parameter E by the following rule: | |||
| 
             | 
        48 | * 1. skips all ElementAttrNamesBlacklist | |||
| 
             | 
        49 | * 2. skips all methods except with the signature of event handlers | |||
| 
             | 
        50 | */ | |||
| 
             | 
        51 | type AssignableElementAttrNames<E> = { | |||
| 
             | 
        52 | [K in keyof E]: K extends ElementAttrNamesBlacklist ? never : | |||
| 
             | 
        53 | ((evt: Event) => any) extends E[K] ? K : | |||
| 
             | 
        54 | E[K] extends ((...args: any[]) => any) ? never : | |||
| 
             | 
        55 | K; | |||
| 
             | 
        56 | }[keyof E]; | |||
| 
             | 
        57 | ||||
| 
             | 
        58 | type LaxElement<E extends object> = | |||
| 
             | 
        59 | Pick<E, AssignableElementAttrNames<E>> & | |||
| 
             | 
        60 | DjxIntrinsicAttributes; | |||
| 44 | 
             | 
        61 | |||
| 45 | type LaxIntrinsicElementsMap = { | 
             | 
        62 | type LaxIntrinsicElementsMap = { | |
| 46 | [tag in keyof HTMLElementTagNameMap]: LaxElement<HTMLElementTagNameMap[tag]> | 
             | 
        63 | [tag in keyof HTMLElementTagNameMap]: LaxElement<HTMLElementTagNameMap[tag]> | |
        
        General Comments 0
    
    
  
  
                      You need to be logged in to leave comments.
                      Login now
                    
                