2016-11-02 19:59:24 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2017-02-13 18:17:40 -05:00
|
|
|
import {DomElementSchemaRegistry} from '@angular/compiler';
|
2017-01-27 20:39:48 -05:00
|
|
|
import {
|
|
|
|
APP_ID, Inject, Injectable, NgZone, RenderComponentType, Renderer, RendererFactoryV2, RendererV2, RootRenderer,
|
|
|
|
ViewEncapsulation, ɵAnimationKeyframe as AnimationKeyframe, ɵAnimationPlayer as AnimationPlayer,
|
|
|
|
ɵAnimationStyles as AnimationStyles, ɵRenderDebugInfo as RenderDebugInfo, RendererTypeV2
|
|
|
|
} from '@angular/core';
|
2017-02-17 15:55:55 -05:00
|
|
|
import {AnimationDriver, DOCUMENT, ɵNAMESPACE_URIS as NAMESPACE_URIS, ɵSharedStylesHost as SharedStylesHost, ɵflattenStyles as flattenStyles, ɵgetDOM as getDOM, ɵisNamespaced as isNamespaced, ɵshimContentAttribute as shimContentAttribute, ɵshimHostAttribute as shimHostAttribute, ɵsplitNamespace as splitNamespace} from '@angular/platform-browser';
|
2016-11-02 19:59:24 -04:00
|
|
|
import {isBlank, isPresent, stringify} from './facade/lang';
|
|
|
|
|
|
|
|
const TEMPLATE_COMMENT_TEXT = 'template bindings={}';
|
|
|
|
const TEMPLATE_BINDINGS_EXP = /^template bindings=(.*)$/;
|
|
|
|
|
2017-02-13 18:17:40 -05:00
|
|
|
const EMPTY_ARRAY: any[] = [];
|
|
|
|
|
2016-11-02 19:59:24 -04:00
|
|
|
@Injectable()
|
2017-02-15 00:03:18 -05:00
|
|
|
export class ServerRootRenderer implements RootRenderer {
|
2016-11-02 19:59:24 -04:00
|
|
|
protected registeredComponents: Map<string, ServerRenderer> = new Map<string, ServerRenderer>();
|
2017-02-13 18:17:40 -05:00
|
|
|
private _schema = new DomElementSchemaRegistry();
|
|
|
|
|
2016-11-02 19:59:24 -04:00
|
|
|
constructor(
|
|
|
|
@Inject(DOCUMENT) public document: any, public sharedStylesHost: SharedStylesHost,
|
|
|
|
public animationDriver: AnimationDriver, @Inject(APP_ID) public appId: string,
|
|
|
|
private _zone: NgZone) {}
|
|
|
|
renderComponent(componentProto: RenderComponentType): Renderer {
|
2016-11-12 08:08:58 -05:00
|
|
|
let renderer = this.registeredComponents.get(componentProto.id);
|
2016-11-02 19:59:24 -04:00
|
|
|
if (!renderer) {
|
|
|
|
renderer = new ServerRenderer(
|
|
|
|
this, componentProto, this.animationDriver, `${this.appId}-${componentProto.id}`,
|
2017-02-13 18:17:40 -05:00
|
|
|
this._zone, this._schema);
|
2016-11-02 19:59:24 -04:00
|
|
|
this.registeredComponents.set(componentProto.id, renderer);
|
|
|
|
}
|
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ServerRenderer implements Renderer {
|
|
|
|
private _contentAttr: string;
|
|
|
|
private _hostAttr: string;
|
|
|
|
private _styles: string[];
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private _rootRenderer: ServerRootRenderer, private componentProto: RenderComponentType,
|
2017-02-13 18:17:40 -05:00
|
|
|
private _animationDriver: AnimationDriver, styleShimId: string, private _zone: NgZone,
|
|
|
|
private _schema: DomElementSchemaRegistry) {
|
2016-11-02 19:59:24 -04:00
|
|
|
this._styles = flattenStyles(styleShimId, componentProto.styles, []);
|
|
|
|
if (componentProto.encapsulation === ViewEncapsulation.Native) {
|
|
|
|
throw new Error('Native encapsulation is not supported on the server!');
|
|
|
|
}
|
2017-02-14 14:34:05 -05:00
|
|
|
this._rootRenderer.sharedStylesHost.addStyles(this._styles);
|
2016-11-02 19:59:24 -04:00
|
|
|
if (this.componentProto.encapsulation === ViewEncapsulation.Emulated) {
|
|
|
|
this._contentAttr = shimContentAttribute(styleShimId);
|
|
|
|
this._hostAttr = shimHostAttribute(styleShimId);
|
|
|
|
} else {
|
|
|
|
this._contentAttr = null;
|
|
|
|
this._hostAttr = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectRootElement(selectorOrNode: string|any, debugInfo: RenderDebugInfo): Element {
|
2016-11-12 08:08:58 -05:00
|
|
|
let el: any /** TODO #9100 */;
|
2016-11-02 19:59:24 -04:00
|
|
|
if (typeof selectorOrNode === 'string') {
|
|
|
|
el = getDOM().querySelector(this._rootRenderer.document, selectorOrNode);
|
|
|
|
if (isBlank(el)) {
|
|
|
|
throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
el = selectorOrNode;
|
|
|
|
}
|
|
|
|
getDOM().clearNodes(el);
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
|
|
|
createElement(parent: Element, name: string, debugInfo: RenderDebugInfo): Node {
|
2016-11-12 08:08:58 -05:00
|
|
|
let el: any;
|
2016-11-02 19:59:24 -04:00
|
|
|
if (isNamespaced(name)) {
|
2016-11-12 08:08:58 -05:00
|
|
|
const nsAndName = splitNamespace(name);
|
2016-11-02 19:59:24 -04:00
|
|
|
el = getDOM().createElementNS(NAMESPACE_URIS[nsAndName[0]], nsAndName[1]);
|
|
|
|
} else {
|
|
|
|
el = getDOM().createElement(name);
|
|
|
|
}
|
|
|
|
if (isPresent(this._contentAttr)) {
|
|
|
|
getDOM().setAttribute(el, this._contentAttr, '');
|
|
|
|
}
|
|
|
|
if (isPresent(parent)) {
|
|
|
|
getDOM().appendChild(parent, el);
|
|
|
|
}
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
|
|
|
createViewRoot(hostElement: any): any {
|
2016-11-12 08:08:58 -05:00
|
|
|
let nodesParent: any /** TODO #9100 */;
|
2016-11-02 19:59:24 -04:00
|
|
|
if (isPresent(this._hostAttr)) {
|
|
|
|
getDOM().setAttribute(hostElement, this._hostAttr, '');
|
|
|
|
}
|
|
|
|
nodesParent = hostElement;
|
|
|
|
return nodesParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
createTemplateAnchor(parentElement: any, debugInfo: RenderDebugInfo): any {
|
2016-11-12 08:08:58 -05:00
|
|
|
const comment = getDOM().createComment(TEMPLATE_COMMENT_TEXT);
|
2016-11-02 19:59:24 -04:00
|
|
|
if (isPresent(parentElement)) {
|
|
|
|
getDOM().appendChild(parentElement, comment);
|
|
|
|
}
|
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
createText(parentElement: any, value: string, debugInfo: RenderDebugInfo): any {
|
2016-11-12 08:08:58 -05:00
|
|
|
const node = getDOM().createTextNode(value);
|
2016-11-02 19:59:24 -04:00
|
|
|
if (isPresent(parentElement)) {
|
|
|
|
getDOM().appendChild(parentElement, node);
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
projectNodes(parentElement: any, nodes: any[]) {
|
|
|
|
if (isBlank(parentElement)) return;
|
|
|
|
appendNodes(parentElement, nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
attachViewAfter(node: any, viewRootNodes: any[]) { moveNodesAfterSibling(node, viewRootNodes); }
|
|
|
|
|
|
|
|
detachView(viewRootNodes: any[]) {
|
2016-11-12 08:08:58 -05:00
|
|
|
for (let i = 0; i < viewRootNodes.length; i++) {
|
2016-11-02 19:59:24 -04:00
|
|
|
getDOM().remove(viewRootNodes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyView(hostElement: any, viewAllNodes: any[]) {}
|
|
|
|
|
|
|
|
listen(renderElement: any, name: string, callback: Function): Function {
|
2016-11-03 14:16:28 -04:00
|
|
|
// Note: We are not using the EventsPlugin here as this is not needed
|
|
|
|
// to run our tests.
|
2016-11-12 08:08:58 -05:00
|
|
|
const outsideHandler = (event: any) => this._zone.runGuarded(() => callback(event));
|
2016-11-02 19:59:24 -04:00
|
|
|
return this._zone.runOutsideAngular(
|
|
|
|
() => getDOM().onAndCancel(renderElement, name, outsideHandler));
|
|
|
|
}
|
|
|
|
|
|
|
|
listenGlobal(target: string, name: string, callback: Function): Function {
|
2017-02-14 19:14:40 -05:00
|
|
|
const renderElement = getDOM().getGlobalEventTarget(this._rootRenderer.document, target);
|
2016-11-02 19:59:24 -04:00
|
|
|
return this.listen(renderElement, name, callback);
|
|
|
|
}
|
|
|
|
|
2017-02-13 18:17:40 -05:00
|
|
|
// The value was validated already as a property binding, against the property name.
|
|
|
|
// To know this value is safe to use as an attribute, the security context of the
|
|
|
|
// attribute with the given name is checked against that security context of the
|
|
|
|
// property.
|
|
|
|
private _isSafeToReflectProperty(tagName: string, propertyName: string): boolean {
|
|
|
|
return this._schema.securityContext(tagName, propertyName, true) ===
|
|
|
|
this._schema.securityContext(tagName, propertyName, false);
|
|
|
|
}
|
|
|
|
|
2016-11-02 19:59:24 -04:00
|
|
|
setElementProperty(renderElement: any, propertyName: string, propertyValue: any): void {
|
|
|
|
getDOM().setProperty(renderElement, propertyName, propertyValue);
|
2017-02-13 18:17:40 -05:00
|
|
|
|
|
|
|
// Mirror property values for known HTML element properties in the attributes.
|
|
|
|
const tagName = (renderElement.tagName as string).toLowerCase();
|
|
|
|
if (isPresent(propertyValue) &&
|
|
|
|
(typeof propertyValue === 'number' || typeof propertyValue == 'string') &&
|
|
|
|
this._schema.hasElement(tagName, EMPTY_ARRAY) &&
|
|
|
|
this._schema.hasProperty(tagName, propertyName, EMPTY_ARRAY) &&
|
|
|
|
this._isSafeToReflectProperty(tagName, propertyName)) {
|
|
|
|
this.setElementAttribute(renderElement, propertyName, propertyValue.toString());
|
|
|
|
}
|
2016-11-02 19:59:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setElementAttribute(renderElement: any, attributeName: string, attributeValue: string): void {
|
|
|
|
let attrNs: string;
|
|
|
|
let attrNameWithoutNs = attributeName;
|
|
|
|
if (isNamespaced(attributeName)) {
|
|
|
|
const nsAndName = splitNamespace(attributeName);
|
|
|
|
attrNameWithoutNs = nsAndName[1];
|
|
|
|
attributeName = nsAndName[0] + ':' + nsAndName[1];
|
|
|
|
attrNs = NAMESPACE_URIS[nsAndName[0]];
|
|
|
|
}
|
|
|
|
if (isPresent(attributeValue)) {
|
|
|
|
if (isPresent(attrNs)) {
|
|
|
|
getDOM().setAttributeNS(renderElement, attrNs, attributeName, attributeValue);
|
|
|
|
} else {
|
|
|
|
getDOM().setAttribute(renderElement, attributeName, attributeValue);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isPresent(attrNs)) {
|
|
|
|
getDOM().removeAttributeNS(renderElement, attrNs, attrNameWithoutNs);
|
|
|
|
} else {
|
|
|
|
getDOM().removeAttribute(renderElement, attributeName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setBindingDebugInfo(renderElement: any, propertyName: string, propertyValue: string): void {
|
|
|
|
if (getDOM().isCommentNode(renderElement)) {
|
|
|
|
const existingBindings =
|
|
|
|
getDOM().getText(renderElement).replace(/\n/g, '').match(TEMPLATE_BINDINGS_EXP);
|
2016-11-12 08:08:58 -05:00
|
|
|
const parsedBindings = JSON.parse(existingBindings[1]);
|
2016-11-02 19:59:24 -04:00
|
|
|
(parsedBindings as any /** TODO #9100 */)[propertyName] = propertyValue;
|
|
|
|
getDOM().setText(
|
|
|
|
renderElement,
|
|
|
|
TEMPLATE_COMMENT_TEXT.replace('{}', JSON.stringify(parsedBindings, null, 2)));
|
|
|
|
} else {
|
2017-02-16 16:55:55 -05:00
|
|
|
propertyName = propertyName.replace(/\$/g, '_');
|
2016-11-02 19:59:24 -04:00
|
|
|
this.setElementAttribute(renderElement, propertyName, propertyValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setElementClass(renderElement: any, className: string, isAdd: boolean): void {
|
|
|
|
if (isAdd) {
|
|
|
|
getDOM().addClass(renderElement, className);
|
|
|
|
} else {
|
|
|
|
getDOM().removeClass(renderElement, className);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setElementStyle(renderElement: any, styleName: string, styleValue: string): void {
|
|
|
|
if (isPresent(styleValue)) {
|
|
|
|
getDOM().setStyle(renderElement, styleName, stringify(styleValue));
|
|
|
|
} else {
|
|
|
|
getDOM().removeStyle(renderElement, styleName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
invokeElementMethod(renderElement: any, methodName: string, args: any[]): void {
|
|
|
|
getDOM().invoke(renderElement, methodName, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
setText(renderNode: any, text: string): void { getDOM().setText(renderNode, text); }
|
|
|
|
|
|
|
|
animate(
|
|
|
|
element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[],
|
2016-11-14 19:59:06 -05:00
|
|
|
duration: number, delay: number, easing: string,
|
|
|
|
previousPlayers: AnimationPlayer[] = []): AnimationPlayer {
|
2017-01-05 14:33:40 -05:00
|
|
|
return this._animationDriver.animate(
|
|
|
|
element, startingStyles, keyframes, duration, delay, easing, previousPlayers);
|
2016-11-02 19:59:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 00:03:18 -05:00
|
|
|
function moveNodesAfterSibling(ref: any, nodes: any) {
|
|
|
|
const parent = getDOM().parentElement(ref);
|
|
|
|
if (nodes.length > 0 && parent) {
|
|
|
|
const nextSibling = getDOM().nextSibling(ref);
|
|
|
|
if (nextSibling) {
|
2016-11-12 08:08:58 -05:00
|
|
|
for (let i = 0; i < nodes.length; i++) {
|
2017-02-15 00:03:18 -05:00
|
|
|
getDOM().insertBefore(parent, nextSibling, nodes[i]);
|
2016-11-02 19:59:24 -04:00
|
|
|
}
|
|
|
|
} else {
|
2016-11-12 08:08:58 -05:00
|
|
|
for (let i = 0; i < nodes.length; i++) {
|
2016-11-02 19:59:24 -04:00
|
|
|
getDOM().appendChild(parent, nodes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 00:03:18 -05:00
|
|
|
function appendNodes(parent: any, nodes: any) {
|
2016-11-12 08:08:58 -05:00
|
|
|
for (let i = 0; i < nodes.length; i++) {
|
2016-11-02 19:59:24 -04:00
|
|
|
getDOM().appendChild(parent, nodes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 00:03:18 -05:00
|
|
|
@Injectable()
|
2017-02-16 16:55:55 -05:00
|
|
|
export class ServerRendererFactoryV2 implements RendererFactoryV2 {
|
|
|
|
private rendererByCompId = new Map<string, RendererV2>();
|
|
|
|
private defaultRenderer: RendererV2;
|
2017-02-20 17:34:15 -05:00
|
|
|
private schema = new DomElementSchemaRegistry();
|
2017-02-16 16:55:55 -05:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private ngZone: NgZone, @Inject(DOCUMENT) private document: any,
|
|
|
|
private sharedStylesHost: SharedStylesHost) {
|
2017-02-20 17:34:15 -05:00
|
|
|
this.defaultRenderer = new DefaultServerRendererV2(document, ngZone, this.schema);
|
2017-02-16 16:55:55 -05:00
|
|
|
};
|
|
|
|
|
2017-02-17 12:01:37 -05:00
|
|
|
createRenderer(element: any, type: RendererTypeV2): RendererV2 {
|
2017-02-16 16:55:55 -05:00
|
|
|
if (!element || !type) {
|
|
|
|
return this.defaultRenderer;
|
|
|
|
}
|
|
|
|
switch (type.encapsulation) {
|
|
|
|
case ViewEncapsulation.Emulated: {
|
|
|
|
let renderer = this.rendererByCompId.get(type.id);
|
|
|
|
if (!renderer) {
|
|
|
|
renderer = new EmulatedEncapsulationServerRendererV2(
|
2017-02-20 17:34:15 -05:00
|
|
|
this.document, this.ngZone, this.sharedStylesHost, this.schema, type);
|
2017-02-16 16:55:55 -05:00
|
|
|
this.rendererByCompId.set(type.id, renderer);
|
|
|
|
}
|
|
|
|
(<EmulatedEncapsulationServerRendererV2>renderer).applyToHost(element);
|
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
case ViewEncapsulation.Native:
|
|
|
|
throw new Error('Native encapsulation is not supported on the server!');
|
|
|
|
default: {
|
|
|
|
if (!this.rendererByCompId.has(type.id)) {
|
|
|
|
const styles = flattenStyles(type.id, type.styles, []);
|
|
|
|
this.sharedStylesHost.addStyles(styles);
|
|
|
|
this.rendererByCompId.set(type.id, this.defaultRenderer);
|
|
|
|
}
|
|
|
|
return this.defaultRenderer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DefaultServerRendererV2 implements RendererV2 {
|
2017-02-20 17:34:15 -05:00
|
|
|
constructor(
|
|
|
|
private document: any, private ngZone: NgZone, private schema: DomElementSchemaRegistry) {}
|
2017-02-16 16:55:55 -05:00
|
|
|
|
|
|
|
destroy(): void {}
|
|
|
|
|
|
|
|
destroyNode: null;
|
2017-02-15 00:03:18 -05:00
|
|
|
|
|
|
|
createElement(name: string, namespace?: string, debugInfo?: any): any {
|
|
|
|
if (namespace) {
|
|
|
|
return getDOM().createElementNS(NAMESPACE_URIS[namespace], name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return getDOM().createElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
createComment(value: string, debugInfo?: any): any { return getDOM().createComment(value); }
|
|
|
|
|
|
|
|
createText(value: string, debugInfo?: any): any { return getDOM().createTextNode(value); }
|
|
|
|
|
|
|
|
appendChild(parent: any, newChild: any): void { getDOM().appendChild(parent, newChild); }
|
|
|
|
|
|
|
|
insertBefore(parent: any, newChild: any, refChild: any): void {
|
|
|
|
if (parent) {
|
|
|
|
getDOM().insertBefore(parent, refChild, newChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 11:36:49 -05:00
|
|
|
removeChild(parent: any, oldChild: any): void {
|
|
|
|
if (parent) {
|
|
|
|
getDOM().removeChild(parent, oldChild);
|
|
|
|
}
|
|
|
|
}
|
2017-02-15 00:03:18 -05:00
|
|
|
|
|
|
|
selectRootElement(selectorOrNode: string|any, debugInfo?: any): any {
|
|
|
|
let el: any;
|
|
|
|
if (typeof selectorOrNode === 'string') {
|
|
|
|
el = getDOM().querySelector(this.document, selectorOrNode);
|
|
|
|
if (!el) {
|
|
|
|
throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
el = selectorOrNode;
|
|
|
|
}
|
|
|
|
getDOM().clearNodes(el);
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
|
|
|
parentNode(node: any): any { return getDOM().parentElement(node); }
|
|
|
|
|
|
|
|
nextSibling(node: any): any { return getDOM().nextSibling(node); }
|
|
|
|
|
|
|
|
setAttribute(el: any, name: string, value: string, namespace?: string): void {
|
|
|
|
if (namespace) {
|
|
|
|
getDOM().setAttributeNS(el, NAMESPACE_URIS[namespace], namespace + ':' + name, value);
|
|
|
|
} else {
|
|
|
|
getDOM().setAttribute(el, name, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
removeAttribute(el: any, name: string, namespace?: string): void {
|
|
|
|
if (namespace) {
|
|
|
|
getDOM().removeAttributeNS(el, NAMESPACE_URIS[namespace], name);
|
|
|
|
} else {
|
|
|
|
getDOM().removeAttribute(el, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addClass(el: any, name: string): void { getDOM().addClass(el, name); }
|
|
|
|
|
|
|
|
removeClass(el: any, name: string): void { getDOM().removeClass(el, name); }
|
|
|
|
|
|
|
|
setStyle(el: any, style: string, value: any, hasVendorPrefix: boolean, hasImportant: boolean):
|
|
|
|
void {
|
|
|
|
getDOM().setStyle(el, style, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeStyle(el: any, style: string, hasVendorPrefix: boolean): void {
|
|
|
|
getDOM().removeStyle(el, style);
|
|
|
|
}
|
|
|
|
|
2017-02-20 17:34:15 -05:00
|
|
|
// The value was validated already as a property binding, against the property name.
|
|
|
|
// To know this value is safe to use as an attribute, the security context of the
|
|
|
|
// attribute with the given name is checked against that security context of the
|
|
|
|
// property.
|
|
|
|
private _isSafeToReflectProperty(tagName: string, propertyName: string): boolean {
|
|
|
|
return this.schema.securityContext(tagName, propertyName, true) ===
|
|
|
|
this.schema.securityContext(tagName, propertyName, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
setProperty(el: any, name: string, value: any): void {
|
|
|
|
getDOM().setProperty(el, name, value);
|
|
|
|
// Mirror property values for known HTML element properties in the attributes.
|
|
|
|
const tagName = (el.tagName as string).toLowerCase();
|
|
|
|
if (isPresent(value) && (typeof value === 'number' || typeof value == 'string') &&
|
|
|
|
this.schema.hasElement(tagName, EMPTY_ARRAY) &&
|
|
|
|
this.schema.hasProperty(tagName, name, EMPTY_ARRAY) &&
|
|
|
|
this._isSafeToReflectProperty(tagName, name)) {
|
|
|
|
this.setAttribute(el, name, value.toString());
|
|
|
|
}
|
|
|
|
}
|
2017-02-15 00:03:18 -05:00
|
|
|
|
2017-02-16 16:55:55 -05:00
|
|
|
setValue(node: any, value: string): void { getDOM().setText(node, value); }
|
2017-02-15 00:03:18 -05:00
|
|
|
|
|
|
|
listen(
|
|
|
|
target: 'document'|'window'|'body'|any, eventName: string,
|
|
|
|
callback: (event: any) => boolean): () => void {
|
|
|
|
// Note: We are not using the EventsPlugin here as this is not needed
|
|
|
|
// to run our tests.
|
|
|
|
const el =
|
|
|
|
typeof target === 'string' ? getDOM().getGlobalEventTarget(this.document, target) : target;
|
|
|
|
const outsideHandler = (event: any) => this.ngZone.runGuarded(() => callback(event));
|
|
|
|
return this.ngZone.runOutsideAngular(() => getDOM().onAndCancel(el, eventName, outsideHandler));
|
|
|
|
}
|
2016-11-02 19:59:24 -04:00
|
|
|
}
|
2017-02-16 16:55:55 -05:00
|
|
|
|
|
|
|
class EmulatedEncapsulationServerRendererV2 extends DefaultServerRendererV2 {
|
|
|
|
private contentAttr: string;
|
|
|
|
private hostAttr: string;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
document: any, ngZone: NgZone, sharedStylesHost: SharedStylesHost,
|
2017-02-20 17:34:15 -05:00
|
|
|
schema: DomElementSchemaRegistry, private component: RendererTypeV2) {
|
|
|
|
super(document, ngZone, schema);
|
2017-02-16 16:55:55 -05:00
|
|
|
const styles = flattenStyles(component.id, component.styles, []);
|
|
|
|
sharedStylesHost.addStyles(styles);
|
|
|
|
|
|
|
|
this.contentAttr = shimContentAttribute(component.id);
|
|
|
|
this.hostAttr = shimHostAttribute(component.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
applyToHost(element: any) { super.setAttribute(element, this.hostAttr, ''); }
|
|
|
|
|
|
|
|
createElement(parent: any, name: string): Element {
|
|
|
|
const el = super.createElement(parent, name);
|
|
|
|
super.setAttribute(el, this.contentAttr, '');
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
}
|