##// END OF EJS Templates
fixed NlsBundle locale package loading...
fixed NlsBundle locale package loading corrected DjxFragment params and return value fixed regression in DjxWidgetBase attach points processing fixed empty RenditionBase startup

File last commit:

r108:d644dced936e default
r112:2ccfaae984e9 v1.4.4 default
Show More
traits.ts
214 lines | 6.9 KiB | video/mp2t | TypeScriptLexer
cin
fixed cyclic module references tsx/traits, tsx/FunctionRendition, tsx/RenditionBase
r89 import { IDestroyable } from "@implab/core-amd/interfaces";
cin
Converted to subproject djx, removed dojo-typings
r65 import { isDestroyable } from "@implab/core-amd/safe";
import _WidgetBase = require("dijit/_WidgetBase");
import registry = require("dijit/registry");
cin
Added playground project
r97 interface _WidgetBaseConstructor {
cin
linting
r108 new <E extends { [k in keyof E]: Event } = object>(params?: Partial<_WidgetBase<E>> & ThisType<_WidgetBase<E>>, srcNodeRef?: string | Node): _WidgetBase<E> & dojo._base.DeclareCreatedObject;
cin
Working on WatchForRendition
r107 prototype: _WidgetBase;
cin
Added playground project
r97 }
cin
Converted to subproject djx, removed dojo-typings
r65
export type DojoNodePosition = "first" | "after" | "before" | "last" | "replace" | "only" | number;
cin
refactoring, adding scope to rendering methods
r96 export type DojoNodeLocation = [Node, DojoNodePosition];
cin
Added Renderer, WatchRendition
r94
cin
Converted to subproject djx, removed dojo-typings
r65 export interface Rendition<TNode extends Node = Node> {
cin
Testing nested watch, release candidate
r101 getDomNode(): TNode;
cin
Converted to subproject djx, removed dojo-typings
r65
placeAt(refNode: string | Node, position?: DojoNodePosition): void;
}
cin
temp commit, working on @on() decorator
r72 /**
cin
Converted to subproject djx, removed dojo-typings
r65 * @deprecated use Rendition
*/
export type BuildContext<TNode extends Node = Node> = Rendition<TNode>;
export interface IRecursivelyDestroyable {
destroyRecursive(): void;
}
cin
refactoring, adding scope to rendering methods
r96 export const isNode = (el: unknown): el is Node => !!(el && (el as Node).nodeName && (el as Node).nodeType);
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isElementNode = (el: unknown): el is Element => isNode(el) && el.nodeType === 1;
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isTextNode = (el: unknown): el is Text => isNode(el) && el.nodeType === 3;
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isProcessingInstructionNode = (el: unknown): el is ProcessingInstruction => isNode(el) && el.nodeType === 7;
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isCommentNode = (el: unknown): el is Comment => isNode(el) && el.nodeType === 8;
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isDocumentNode = (el: unknown): el is Document => isNode(el) && el.nodeType === 9;
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isDocumentTypeNode = (el: unknown): el is DocumentType => isNode(el) && el.nodeType === 10;
cin
Converted to subproject djx, removed dojo-typings
r65
cin
Working on WatchForRendition
r107 export const isDocumentFragmentNode = (el: unknown): el is DocumentFragment => isNode(el) && el.nodeType === 11;
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isWidget = (v: unknown): v is _WidgetBase => !!(v && "domNode" in (v as _WidgetBase));
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isRendition = (v: unknown): v is Rendition => !!(v && typeof (v as Rendition).getDomNode === "function");
cin
Converted to subproject djx, removed dojo-typings
r65
/**
* @deprecated use isRendition
*/
export const isBuildContext = isRendition;
cin
refactoring, adding scope to rendering methods
r96 export const isPlainObject = (v: object) => {
cin
Converted to subproject djx, removed dojo-typings
r65 if (typeof v !== "object")
return false;
cin
Working on WatchForRendition
r107 const vp = Object.getPrototypeOf(v) as object;
cin
Converted to subproject djx, removed dojo-typings
r65 return !vp || vp === Object.prototype;
cin
Working on WatchForRendition
r107 };
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isWidgetConstructor = (v: unknown): v is _WidgetBaseConstructor =>
cin
Working on WatchForRendition
r107 typeof v === "function" && !!v.prototype && (
cin
Converted to subproject djx, removed dojo-typings
r65 "domNode" in v.prototype ||
"buildRendering" in v.prototype
);
cin
refactoring, adding scope to rendering methods
r96
cin
Converted to subproject djx, removed dojo-typings
r65
/** Tests whether the specified node is placed in visible dom.
* @param {Node} node The node to test
*/
cin
refactoring, adding scope to rendering methods
r96 export const isInPage = (node: Node) => node === document.body ? false : document.body.contains(node);
cin
Converted to subproject djx, removed dojo-typings
r65
cin
refactoring, adding scope to rendering methods
r96 export const isRecursivelyDestroyable = (target: unknown): target is IRecursivelyDestroyable =>
!!(target && typeof (target as IRecursivelyDestroyable).destroyRecursive === "function");
cin
Converted to subproject djx, removed dojo-typings
r65
/** Destroys DOM Node with all contained widgets.
* If the specified node is the root node of a widget, then the
* widget will be destroyed.
*
* @param target DOM Node or widget to destroy
*/
cin
refactoring, adding scope to rendering methods
r96 export const destroy = (target: Node | IDestroyable | IRecursivelyDestroyable) => {
cin
Converted to subproject djx, removed dojo-typings
r65 if (isRecursivelyDestroyable(target)) {
target.destroyRecursive();
} else if (isDestroyable(target)) {
target.destroy();
} else if (isNode(target)) {
cin
minor code cleanups
r93 if (isElementNode(target)) {
const w = registry.byNode(target);
if (w) {
w.destroyRecursive();
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 return;
cin
minor code cleanups
r93 } else {
cin
refactoring, adding scope to rendering methods
r96 emptyNode(target);
cin
minor code cleanups
r93 }
cin
Converted to subproject djx, removed dojo-typings
r65 }
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 const parent = target.parentNode;
if (parent)
parent.removeChild(target);
cin
Converted to subproject djx, removed dojo-typings
r65 }
cin
Working on WatchForRendition
r107 };
cin
Converted to subproject djx, removed dojo-typings
r65
/** Empties a content of the specified node and destroys all contained widgets.
*
cin
refactoring, adding scope to rendering methods
r96 * @param target DOM node to empty.
cin
Converted to subproject djx, removed dojo-typings
r65 */
cin
refactoring, adding scope to rendering methods
r96 export const emptyNode = (target: Node) => {
cin
Converted to subproject djx, removed dojo-typings
r65 registry.findWidgets(target).forEach(destroy);
cin
refactoring, adding scope to rendering methods
r96
cin
Working on WatchForRendition
r107 // eslint-disable-next-line no-cond-assign
cin
Testing nested watch, release candidate
r101 for (let c; c = target.lastChild;) { // intentional assignment
cin
refactoring, adding scope to rendering methods
r96 target.removeChild(c);
}
cin
Working on WatchForRendition
r107 };
cin
Converted to subproject djx, removed dojo-typings
r65
/** This function starts all widgets inside the DOM node if the target is a node
* or starts widget itself if the target is the widget. If the specified node
* associated with the widget that widget will be started.
cin
temp commit, working on @on() decorator
r72 *
cin
Converted to subproject djx, removed dojo-typings
r65 * @param target DOM node to find and start widgets or the widget itself.
*/
cin
refactoring, adding scope to rendering methods
r96 export const startupWidgets = (target: Node | _WidgetBase, skipNode?: Node) => {
cin
Converted to subproject djx, removed dojo-typings
r65 if (isNode(target)) {
cin
minor code cleanups
r93 if (isElementNode(target)) {
const w = registry.byNode(target);
if (w) {
if (w.startup)
w.startup();
} else {
registry.findWidgets(target, skipNode).forEach(x => x.startup());
}
cin
Converted to subproject djx, removed dojo-typings
r65 }
} else {
cin
temp commit, working on @on() decorator
r72 if (target.startup)
cin
Fixed startupWidgets for nodes are not of the Element type.
r69 target.startup();
cin
Converted to subproject djx, removed dojo-typings
r65 }
cin
Working on WatchForRendition
r107 };
cin
Added Renderer, WatchRendition
r94
cin
refactoring, adding scope to rendering methods
r96 /** Places the specified DOM node at the specified location.
*
* @param node The node which should be placed
* @param refNodeOrId The reference node where the created
* DOM should be placed.
* @param position Optional parameter, specifies the
* position relative to refNode. Default is "last" (i.e. last child).
*/
export const placeAt = (node: Node, refNodeOrId: string | Node, position: DojoNodePosition = "last") => {
cin
start implementing traits::placeAt
r95 const ref = typeof refNodeOrId == "string" ? document.getElementById(refNodeOrId) : refNodeOrId;
if (!ref)
return;
const parent = ref.parentNode;
cin
refactoring, adding scope to rendering methods
r96 if (typeof position == "number") {
if (ref.childNodes.length <= position) {
ref.appendChild(node);
} else {
ref.insertBefore(node, ref.childNodes[position]);
}
cin
start implementing traits::placeAt
r95 } else {
cin
refactoring, adding scope to rendering methods
r96 switch (position) {
cin
start implementing traits::placeAt
r95 case "before":
cin
Working sandbox
r99 parent && parent.insertBefore(node, ref);
cin
refactoring, adding scope to rendering methods
r96 break;
cin
start implementing traits::placeAt
r95 case "after":
cin
Working sandbox
r99 parent && parent.insertBefore(node, ref.nextSibling);
cin
refactoring, adding scope to rendering methods
r96 break;
case "first":
cin
Testing nested watch, release candidate
r101 ref.insertBefore(node, ref.firstChild);
cin
refactoring, adding scope to rendering methods
r96 break;
case "last":
cin
Working sandbox
r99 ref.appendChild(node);
cin
refactoring, adding scope to rendering methods
r96 break;
case "only":
emptyNode(ref);
ref.appendChild(node);
break;
case "replace":
cin
start implementing traits::placeAt
r95 if (parent)
cin
refactoring, adding scope to rendering methods
r96 parent.replaceChild(node, ref);
destroy(ref);
break;
cin
start implementing traits::placeAt
r95 }
}
cin
Working on WatchForRendition
r107 };
cin
start implementing traits::placeAt
r95
cin
refactoring, adding scope to rendering methods
r96 /** Collects nodes from collection to an array.
*
* @param collection The collection of nodes.
* @returns The array of nodes.
*/
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 export const collectNodes = (collection: NodeListOf<ChildNode>) => {
cin
refactoring, adding scope to rendering methods
r96 const items = [];
for (let i = 0, n = collection.length; i < n; i++) {
items.push(collection[i]);
}
return items;
};
cin
start implementing traits::placeAt
r95
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
export const isMounted = (node: Node) => {
cin
refactoring, adding scope to rendering methods
r96 if (node.parentNode) {
const parentWidget = registry.getEnclosingWidget(node.parentNode);
if (parentWidget && parentWidget._started)
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 return true;
cin
refactoring, adding scope to rendering methods
r96 }
if (isInPage(node))
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 return true;
return false;
cin
refactoring, adding scope to rendering methods
r96 };