refactor(core): move `ViewEncapsulation` and `ViewType` to the right places
Closes #4526
This commit is contained in:
parent
0299d4af00
commit
0b3e4fa090
|
@ -30,7 +30,7 @@ import {
|
|||
import {CompileTypeMetadata, CompileDirectiveMetadata} from './directive_metadata';
|
||||
import {SourceExpressions, SourceExpression, moduleRef} from './source_module';
|
||||
|
||||
import {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
||||
import {
|
||||
shimHostAttribute,
|
||||
shimContentAttribute,
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
ChangeDetectionStrategy,
|
||||
CHANGE_DECTION_STRATEGY_VALUES
|
||||
} from 'angular2/src/core/change_detection/change_detection';
|
||||
import {ViewEncapsulation, VIEW_ENCAPSULATION_VALUES} from 'angular2/src/core/render/api';
|
||||
import {ViewEncapsulation, VIEW_ENCAPSULATION_VALUES} from 'angular2/src/core/metadata/view';
|
||||
import {CssSelector} from 'angular2/src/core/compiler/selector';
|
||||
import {splitAtColon} from './util';
|
||||
import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/linker/interfaces';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {CompileTypeMetadata, CompileTemplateMetadata} from './directive_metadata';
|
||||
import {SourceModule, SourceExpression, moduleRef} from './source_module';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
||||
import {XHR} from 'angular2/src/core/compiler/xhr';
|
||||
import {StringWrapper, isBlank} from 'angular2/src/core/facade/lang';
|
||||
import {PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
|
||||
|
|
|
@ -11,7 +11,8 @@ import {XHR} from 'angular2/src/core/compiler/xhr';
|
|||
import {UrlResolver} from 'angular2/src/core/compiler/url_resolver';
|
||||
import {resolveStyleUrls} from './style_url_resolver';
|
||||
import {Injectable} from 'angular2/src/core/di';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
||||
|
||||
|
||||
import {
|
||||
HtmlAstVisitor,
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import {ListWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {isPresent, isBlank, Type, isArray, isNumber} from 'angular2/src/core/facade/lang';
|
||||
|
||||
import {ViewType, RenderProtoViewRef} from 'angular2/src/core/render/api';
|
||||
import {RenderProtoViewRef} from 'angular2/src/core/render/api';
|
||||
|
||||
import {Injectable, Binding, resolveForwardRef, Inject} from 'angular2/src/core/di';
|
||||
|
||||
import {PipeBinding} from '../pipes/pipe_binding';
|
||||
import {ProtoPipes} from '../pipes/pipes';
|
||||
|
||||
import {AppProtoView, AppProtoViewMergeInfo} from './view';
|
||||
import {AppProtoView, AppProtoViewMergeInfo, ViewType} from './view';
|
||||
import {ElementBinder} from './element_binder';
|
||||
import {ProtoElementInjector, DirectiveBinding} from './element_injector';
|
||||
import {DirectiveResolver} from './directive_resolver';
|
||||
|
|
|
@ -38,6 +38,18 @@ export {DebugContext} from 'angular2/src/core/change_detection/interfaces';
|
|||
|
||||
const REFLECT_PREFIX: string = 'ng-reflect-';
|
||||
|
||||
export enum ViewType {
|
||||
// A view that contains the host element with bound component directive.
|
||||
// Contains a COMPONENT view
|
||||
HOST,
|
||||
// The view of the component
|
||||
// Can contain 0 to n EMBEDDED views
|
||||
COMPONENT,
|
||||
// A view that is embedded into another View via a <template> element
|
||||
// inside of a COMPONENT view
|
||||
EMBEDDED
|
||||
}
|
||||
|
||||
export class AppViewContainer {
|
||||
// The order in this list matches the DOM order.
|
||||
views: AppView[] = [];
|
||||
|
@ -307,8 +319,8 @@ export class AppProtoView {
|
|||
textBindingCount = null;
|
||||
render: renderApi.RenderProtoViewRef = null;
|
||||
|
||||
constructor(public templateCmds: TemplateCmd[], public type: renderApi.ViewType,
|
||||
public isMergable: boolean, public changeDetectorFactory: Function,
|
||||
constructor(public templateCmds: TemplateCmd[], public type: ViewType, public isMergable: boolean,
|
||||
public changeDetectorFactory: Function,
|
||||
public templateVariableBindings: Map<string, string>, public pipes: ProtoPipes) {
|
||||
this.ref = new ProtoViewRef(this);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ import {
|
|||
Renderer,
|
||||
RenderViewRef,
|
||||
RenderFragmentRef,
|
||||
RenderViewWithFragments,
|
||||
ViewType
|
||||
RenderViewWithFragments
|
||||
} from 'angular2/src/core/render/api';
|
||||
import {AppViewManagerUtils} from './view_manager_utils';
|
||||
import {AppViewPool} from './view_pool';
|
||||
|
@ -57,7 +56,7 @@ export class AppViewManager {
|
|||
*/
|
||||
getHostElement(hostViewRef: HostViewRef): ElementRef {
|
||||
var hostView = internalView(<ViewRef>hostViewRef);
|
||||
if (hostView.proto.type !== ViewType.HOST) {
|
||||
if (hostView.proto.type !== viewModule.ViewType.HOST) {
|
||||
throw new BaseException('This operation is only allowed on host views');
|
||||
}
|
||||
return hostView.elementRefs[hostView.elementOffset];
|
||||
|
@ -205,7 +204,7 @@ export class AppViewManager {
|
|||
templateRef: TemplateRef): ViewRef {
|
||||
var s = this._createEmbeddedViewInContainerScope();
|
||||
var protoView = internalProtoView(templateRef.protoViewRef);
|
||||
if (protoView.type !== ViewType.EMBEDDED) {
|
||||
if (protoView.type !== viewModule.ViewType.EMBEDDED) {
|
||||
throw new BaseException('This method can only be called with embedded ProtoViews!');
|
||||
}
|
||||
this._protoViewFactory.initializeProtoViewIfNeeded(protoView);
|
||||
|
@ -236,7 +235,7 @@ export class AppViewManager {
|
|||
imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef {
|
||||
var s = this._createHostViewInContainerScope();
|
||||
var protoView = internalProtoView(protoViewRef);
|
||||
if (protoView.type !== ViewType.HOST) {
|
||||
if (protoView.type !== viewModule.ViewType.HOST) {
|
||||
throw new BaseException('This method can only be called with host ProtoViews!');
|
||||
}
|
||||
this._protoViewFactory.initializeProtoViewIfNeeded(protoView);
|
||||
|
@ -258,7 +257,7 @@ export class AppViewManager {
|
|||
var contextBoundElementIndex = context.boundElementIndex;
|
||||
var embeddedFragmentView = contextView.getNestedView(contextBoundElementIndex);
|
||||
var view;
|
||||
if (protoView.type === ViewType.EMBEDDED && isPresent(embeddedFragmentView) &&
|
||||
if (protoView.type === viewModule.ViewType.EMBEDDED && isPresent(embeddedFragmentView) &&
|
||||
!embeddedFragmentView.hydrated()) {
|
||||
// Case 1: instantiate the first view of a template that has been merged into a parent
|
||||
view = embeddedFragmentView;
|
||||
|
|
|
@ -9,7 +9,6 @@ import {TemplateRef} from './template_ref';
|
|||
import {Renderer, RenderViewWithFragments} from 'angular2/src/core/render/api';
|
||||
import {Locals} from 'angular2/src/core/change_detection/change_detection';
|
||||
import {Pipes} from 'angular2/src/core/pipes/pipes';
|
||||
import {RenderViewRef, RenderFragmentRef, ViewType} from 'angular2/src/core/render/api';
|
||||
|
||||
@Injectable()
|
||||
export class AppViewManagerUtils {
|
||||
|
@ -50,7 +49,7 @@ export class AppViewManagerUtils {
|
|||
.nestedProtoView :
|
||||
mergedParentViewProto;
|
||||
var renderFragment = null;
|
||||
if (viewOffset === 0 || protoView.type === ViewType.EMBEDDED) {
|
||||
if (viewOffset === 0 || protoView.type === viewModule.ViewType.EMBEDDED) {
|
||||
renderFragment = renderFragments[fragmentIdx++];
|
||||
}
|
||||
var currentView = new viewModule.AppView(renderer, protoView, viewOffset, elementOffset,
|
||||
|
@ -93,7 +92,7 @@ export class AppViewManagerUtils {
|
|||
// preBuiltObjects
|
||||
if (isPresent(elementInjector)) {
|
||||
var templateRef = isPresent(binder.nestedProtoView) &&
|
||||
binder.nestedProtoView.type === ViewType.EMBEDDED ?
|
||||
binder.nestedProtoView.type === viewModule.ViewType.EMBEDDED ?
|
||||
new TemplateRef(el) :
|
||||
null;
|
||||
preBuiltObjects[boundElementIndex] =
|
||||
|
@ -102,7 +101,7 @@ export class AppViewManagerUtils {
|
|||
}
|
||||
currentView.init(protoView.changeDetectorFactory(currentView), elementInjectors,
|
||||
rootElementInjectors, preBuiltObjects, views, elementRefs, viewContainers);
|
||||
if (isPresent(parentView) && protoView.type === ViewType.COMPONENT) {
|
||||
if (isPresent(parentView) && protoView.type === viewModule.ViewType.COMPONENT) {
|
||||
parentView.changeDetector.addShadowDomChild(currentView.changeDetector);
|
||||
}
|
||||
elementOffset += protoView.elementBinders.length;
|
||||
|
@ -180,7 +179,7 @@ export class AppViewManagerUtils {
|
|||
while (viewIdx <= endViewOffset) {
|
||||
var currView = initView.views[viewIdx];
|
||||
var currProtoView = currView.proto;
|
||||
if (currView !== initView && currView.proto.type === ViewType.EMBEDDED) {
|
||||
if (currView !== initView && currView.proto.type === viewModule.ViewType.EMBEDDED) {
|
||||
// Don't hydrate components of embedded fragment views.
|
||||
viewIdx += currView.proto.mergeInfo.viewCount;
|
||||
} else {
|
||||
|
|
|
@ -8,7 +8,7 @@ import './metadata/view.dart';
|
|||
|
||||
export './metadata/di.dart';
|
||||
export './metadata/directives.dart';
|
||||
export './metadata/view.dart';
|
||||
export './metadata/view.dart' hide VIEW_ENCAPSULATION_VALUES;
|
||||
|
||||
/**
|
||||
* See: [DirectiveMetadata] for docs.
|
||||
|
|
|
@ -1,7 +1,36 @@
|
|||
import {CONST, Type} from 'angular2/src/core/facade/lang';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
|
||||
export {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
/**
|
||||
* Defines template and style encapsulation options available for Component's {@link View}.
|
||||
*
|
||||
* See {@link ViewMetadata#encapsulation}.
|
||||
*/
|
||||
export enum ViewEncapsulation {
|
||||
/**
|
||||
* Emulate `Native` scoping of styles by adding an attribute containing surrogate id to the Host
|
||||
* Element and pre-processing the style rules provided via
|
||||
* {@link ViewMetadata#styles} or {@link ViewMetadata#stylesUrls}, and adding the new Host Element
|
||||
* attribute to all selectors.
|
||||
*
|
||||
* This is the default option.
|
||||
*/
|
||||
Emulated,
|
||||
/**
|
||||
* Use the native encapsulation mechanism of the renderer.
|
||||
*
|
||||
* For the DOM this means using [Shadow DOM](https://w3c.github.io/webcomponents/spec/shadow/) and
|
||||
* creating a ShadowRoot for Component's Host Element.
|
||||
*/
|
||||
Native,
|
||||
/**
|
||||
* Don't provide any template or style encapsulation.
|
||||
*/
|
||||
None
|
||||
}
|
||||
|
||||
export var VIEW_ENCAPSULATION_VALUES =
|
||||
[ViewEncapsulation.Emulated, ViewEncapsulation.Native, ViewEncapsulation.None];
|
||||
|
||||
|
||||
/**
|
||||
* Metadata properties available for configuring Views.
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
import {Map} from 'angular2/src/core/facade/collection';
|
||||
|
||||
export enum ViewType {
|
||||
// A view that contains the host element with bound component directive.
|
||||
// Contains a COMPONENT view
|
||||
HOST,
|
||||
// The view of the component
|
||||
// Can contain 0 to n EMBEDDED views
|
||||
COMPONENT,
|
||||
// A view that is embedded into another View via a <template> element
|
||||
// inside of a COMPONENT view
|
||||
EMBEDDED
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents an Angular ProtoView in the Rendering Context.
|
||||
*
|
||||
|
@ -89,38 +76,6 @@ export class RenderFragmentRef {}
|
|||
// TODO(i): refactor into an interface
|
||||
export class RenderViewRef {}
|
||||
|
||||
|
||||
/**
|
||||
* Defines template and style encapsulation options available for Component's {@link View}.
|
||||
*
|
||||
* See {@link ViewMetadata#encapsulation}.
|
||||
*/
|
||||
export enum ViewEncapsulation {
|
||||
/**
|
||||
* Emulate `Native` scoping of styles by adding an attribute containing surrogate id to the Host
|
||||
* Element and pre-processing the style rules provided via
|
||||
* {@link ViewMetadata#styles} or {@link ViewMetadata#stylesUrls}, and adding the new Host Element
|
||||
* attribute to all selectors.
|
||||
*
|
||||
* This is the default option.
|
||||
*/
|
||||
Emulated,
|
||||
/**
|
||||
* Use the native encapsulation mechanism of the renderer.
|
||||
*
|
||||
* For the DOM this means using [Shadow DOM](https://w3c.github.io/webcomponents/spec/shadow/) and
|
||||
* creating a ShadowRoot for Component's Host Element.
|
||||
*/
|
||||
Native,
|
||||
/**
|
||||
* Don't provide any template or style encapsulation.
|
||||
*/
|
||||
None
|
||||
}
|
||||
|
||||
export var VIEW_ENCAPSULATION_VALUES =
|
||||
[ViewEncapsulation.Emulated, ViewEncapsulation.Native, ViewEncapsulation.None];
|
||||
|
||||
export interface RenderTemplateCmd { visit(visitor: RenderCommandVisitor, context: any): any; }
|
||||
|
||||
export interface RenderBeginCmd extends RenderTemplateCmd {
|
||||
|
|
|
@ -13,8 +13,6 @@ import {
|
|||
RenderViewRef,
|
||||
RenderFragmentRef,
|
||||
RenderElementRef,
|
||||
ViewType,
|
||||
ViewEncapsulation,
|
||||
RenderTemplateCmd,
|
||||
RenderCommandVisitor,
|
||||
RenderTextCmd,
|
||||
|
@ -46,23 +44,8 @@ export const PRIMITIVE: Type = String;
|
|||
|
||||
@Injectable()
|
||||
export class Serializer {
|
||||
private _enumRegistry: Map<any, Map<number, any>>;
|
||||
constructor(private _protoViewStore: RenderProtoViewRefStore,
|
||||
private _renderViewStore: RenderViewWithFragmentsStore) {
|
||||
this._enumRegistry = new Map<any, Map<number, any>>();
|
||||
|
||||
var viewTypeMap = new Map<number, any>();
|
||||
viewTypeMap[0] = ViewType.HOST;
|
||||
viewTypeMap[1] = ViewType.COMPONENT;
|
||||
viewTypeMap[2] = ViewType.EMBEDDED;
|
||||
this._enumRegistry.set(ViewType, viewTypeMap);
|
||||
|
||||
var viewEncapsulationMap = new Map<number, any>();
|
||||
viewEncapsulationMap[0] = ViewEncapsulation.Emulated;
|
||||
viewEncapsulationMap[1] = ViewEncapsulation.Native;
|
||||
viewEncapsulationMap[2] = ViewEncapsulation.None;
|
||||
this._enumRegistry.set(ViewEncapsulation, viewEncapsulationMap);
|
||||
}
|
||||
private _renderViewStore: RenderViewWithFragmentsStore) {}
|
||||
|
||||
serialize(obj: any, type: Type): Object {
|
||||
if (!isPresent(obj)) {
|
||||
|
|
|
@ -35,7 +35,7 @@ import {
|
|||
CompileTemplateMetadata
|
||||
} from 'angular2/src/core/compiler/directive_metadata';
|
||||
import {SourceModule, SourceExpression, moduleRef} from 'angular2/src/core/compiler/source_module';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
||||
import {evalModule} from './eval_module';
|
||||
import {
|
||||
escapeSingleQuoteString,
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
CompileTypeMetadata,
|
||||
CompileTemplateMetadata
|
||||
} from 'angular2/src/core/compiler/directive_metadata';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
||||
import {ChangeDetectionStrategy} from 'angular2/src/core/change_detection';
|
||||
import {LifecycleHooks} from 'angular2/src/core/linker/interfaces';
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import {
|
|||
CompileTypeMetadata
|
||||
} from 'angular2/src/core/compiler/directive_metadata';
|
||||
import {SourceExpression, SourceModule} from 'angular2/src/core/compiler/source_module';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
||||
import {TEST_BINDINGS} from './test_bindings';
|
||||
import {
|
||||
codeGenValueFn,
|
||||
|
|
|
@ -26,7 +26,7 @@ import {evalModule} from './eval_module';
|
|||
import {SourceModule, moduleRef} from 'angular2/src/core/compiler/source_module';
|
||||
import {XHR} from 'angular2/src/core/compiler/xhr';
|
||||
import {MockXHR} from 'angular2/src/core/compiler/xhr_mock';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
||||
|
||||
import {Locals} from 'angular2/src/core/change_detection/change_detection';
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
CompileTypeMetadata,
|
||||
CompileTemplateMetadata
|
||||
} from 'angular2/src/core/compiler/directive_metadata';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/render/api';
|
||||
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
||||
|
||||
import {TemplateNormalizer} from 'angular2/src/core/compiler/template_normalizer';
|
||||
import {XHR} from 'angular2/src/core/compiler/xhr';
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
import {SpyRenderer, SpyAppViewPool, SpyAppViewListener, SpyProtoViewFactory} from '../spies';
|
||||
import {Injector, bind} from 'angular2/core';
|
||||
|
||||
import {AppProtoView, AppView, AppViewContainer} from 'angular2/src/core/linker/view';
|
||||
import {AppProtoView, AppView, AppViewContainer, ViewType} from 'angular2/src/core/linker/view';
|
||||
import {ProtoViewRef, ViewRef, internalView} from 'angular2/src/core/linker/view_ref';
|
||||
import {ElementRef} from 'angular2/src/core/linker/element_ref';
|
||||
import {TemplateRef} from 'angular2/src/core/linker/template_ref';
|
||||
|
@ -25,7 +25,6 @@ import {
|
|||
RenderViewRef,
|
||||
RenderProtoViewRef,
|
||||
RenderFragmentRef,
|
||||
ViewType,
|
||||
RenderViewWithFragments
|
||||
} from 'angular2/src/core/render/api';
|
||||
import {AppViewManager} from 'angular2/src/core/linker/view_manager';
|
||||
|
|
|
@ -26,7 +26,12 @@ import {
|
|||
import {Injector, bind} from 'angular2/core';
|
||||
import {isBlank, isPresent} from 'angular2/src/core/facade/lang';
|
||||
|
||||
import {AppProtoView, AppView, AppProtoViewMergeInfo} from 'angular2/src/core/linker/view';
|
||||
import {
|
||||
AppProtoView,
|
||||
AppView,
|
||||
AppProtoViewMergeInfo,
|
||||
ViewType
|
||||
} from 'angular2/src/core/linker/view';
|
||||
import {ElementBinder} from 'angular2/src/core/linker/element_binder';
|
||||
import {
|
||||
DirectiveBinding,
|
||||
|
@ -37,7 +42,7 @@ import {
|
|||
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
|
||||
import {Component} from 'angular2/src/core/metadata';
|
||||
import {AppViewManagerUtils} from 'angular2/src/core/linker/view_manager_utils';
|
||||
import {ViewType, RenderViewWithFragments} from 'angular2/src/core/render/render';
|
||||
import {RenderViewWithFragments} from 'angular2/src/core/render/render';
|
||||
|
||||
export function main() {
|
||||
// TODO(tbosch): add more tests here!
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'package:angular2/src/core/compiler/directive_metadata.dart';
|
|||
import 'package:angular2/src/core/compiler/template_compiler.dart';
|
||||
import 'package:angular2/src/core/change_detection/change_detection.dart';
|
||||
import 'package:angular2/src/core/linker/interfaces.dart' show LifecycleHooks;
|
||||
import 'package:angular2/src/core/render/api.dart' show ViewEncapsulation;
|
||||
import 'package:angular2/src/core/metadata/view.dart' show ViewEncapsulation;
|
||||
import 'package:angular2/src/transform/common/annotation_matcher.dart';
|
||||
import 'package:angular2/src/transform/common/interface_matcher.dart';
|
||||
import 'package:barback/barback.dart' show AssetId;
|
||||
|
|
Loading…
Reference in New Issue