diff --git a/package.json b/package.json index 8732d21ff5..a35702479e 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "lodash": "4.17.2", "markdown-loader": "github:valorkin/markdown-loader", "marked": "0.3.6", - "ngm-cli": "^0.3.6", + "ngm-cli": "^0.3.7", "npm-run-all": "3.1.2", "pre-commit": "1.2.1", "protractor": "4.0.13", diff --git a/src/index.ts b/src/index.ts index fe2b6f12d5..79d02ad539 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,9 +42,5 @@ export * from './timepicker'; export * from './tooltip'; export * from './typeahead'; -export * from './utils/position'; -export * from './utils/common'; export * from './utils/ng2-bootstrap-config'; export * from './utils/decorators'; - -export { ComponentsHelper } from './utils/components-helper.service'; diff --git a/src/pagination/pager.component.ts b/src/pagination/pager.component.ts index 86be0bb58f..d80aa457f3 100644 --- a/src/pagination/pager.component.ts +++ b/src/pagination/pager.component.ts @@ -1,6 +1,5 @@ import { Component, ElementRef, OnInit, Renderer, Input, Output, EventEmitter, forwardRef } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; -import { KeyAttribute } from '../utils/common'; import { PageChangedEvent } from './pagination.component'; import { PaginationConfig } from './pagination.config'; @@ -26,7 +25,7 @@ const PAGER_TEMPLATE = ` template: PAGER_TEMPLATE, providers: [PAGER_CONTROL_VALUE_ACCESSOR] }) -export class PagerComponent implements ControlValueAccessor, OnInit, KeyAttribute { +export class PagerComponent implements ControlValueAccessor, OnInit { public config: any; @Input() public align: boolean; @Input() public maxSize: number; @@ -159,7 +158,7 @@ export class PagerComponent implements ControlValueAccessor, OnInit, KeyAttribut } public getText(key: string): string { - return (this as KeyAttribute)[key + 'Text'] || this.config[key + 'Text']; + return (this as any)[key + 'Text'] || this.config[key + 'Text']; } public noPrevious(): boolean { diff --git a/src/pagination/pagination.component.ts b/src/pagination/pagination.component.ts index ab00b37330..fc15ba7a9f 100644 --- a/src/pagination/pagination.component.ts +++ b/src/pagination/pagination.component.ts @@ -3,7 +3,6 @@ import { } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; -import { KeyAttribute } from '../utils/common'; import { PaginationConfig } from './pagination.config'; export interface PageChangedEvent { @@ -55,7 +54,7 @@ const PAGINATION_TEMPLATE = ` template: PAGINATION_TEMPLATE, providers: [PAGINATION_CONTROL_VALUE_ACCESSOR] }) -export class PaginationComponent implements ControlValueAccessor, OnInit, KeyAttribute { +export class PaginationComponent implements ControlValueAccessor, OnInit { public config:any; @Input() public align:boolean; @Input() public maxSize:number; @@ -188,7 +187,7 @@ export class PaginationComponent implements ControlValueAccessor, OnInit, KeyAtt } public getText(key:string):string { - return (this as KeyAttribute)[key + 'Text'] || this.config[key + 'Text']; + return (this as any)[key + 'Text'] || this.config[key + 'Text']; } public noPrevious():boolean { diff --git a/src/utils/common.ts b/src/utils/common.ts deleted file mode 100644 index 28f02efec1..0000000000 --- a/src/utils/common.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface KeyAttribute { - [key:string]:any; -} diff --git a/src/utils/components-helper.service.ts b/src/utils/components-helper.service.ts deleted file mode 100644 index dc6a21e66d..0000000000 --- a/src/utils/components-helper.service.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { - ApplicationRef, ComponentFactoryResolver, ComponentRef, Injectable, Injector, ReflectiveInjector, ViewContainerRef, - ResolvedReflectiveProvider, Type -} from '@angular/core'; -import { DOCUMENT } from '@angular/platform-browser'; - -/** - * Components helper class to easily work with - * allows to: - * - get application root view container ref - * @deprecated - */ -@Injectable() -export class ComponentsHelper { - public root:ViewContainerRef; - protected applicationRef:ApplicationRef; - protected componentFactoryResolver:ComponentFactoryResolver; - protected injector:Injector; - - public constructor(applicationRef:ApplicationRef, - componentFactoryResolver:ComponentFactoryResolver, - injector:Injector) { - console.warn(`ComponentsHelper is DEPRECATED, please check ComponentLoader and tooltips as a sample`); - this.applicationRef = applicationRef; - this.componentFactoryResolver = componentFactoryResolver; - this.injector = injector; - } - - public getDocument():any { - return this.injector.get(DOCUMENT); - } - - /** - * In some cases, like using ngUpgrate, - * you need to explicitly set view container ref - * to made this method working you need to add: - * ```typescript - * @Component({ - * selector: 'my-app', - * ... - * }) - * export class MyApp { - * constructor(componentsHelper:ComponentsHelper, viewContainerRef: ViewContainerRef) { - * // A Default view container ref, usually the app root container ref. - * // Has to be set manually until we can find a way to get it automatically. - * componentsHelper.setRootViewContainerRef(viewContainerRef) - * } - * } - * ``` - * @deprecated - */ - public setRootViewContainerRef(value:ViewContainerRef):void { - console.warn(`This hack is not needed any more, please remove any usage of ComponentsHelper`); - this.root = value; - } - /** - * This is a name conventional class to get application root view component ref - * @returns {ViewContainerRef} - application root view component ref - */ - public getRootViewContainerRef():ViewContainerRef { - // https://github.com/angular/angular/issues/9293 - if (this.root) { - return this.root; - } - - const comps = this.applicationRef.components; - - if(!comps.length) { - throw new Error(`ApplicationRef instance not found`); - } - - try { - /* one more ugly hack, read issue above for details */ - const rootComponent = (this.applicationRef as any )._rootComponents[0]; - this.root = rootComponent._hostElement.vcRef; - return this.root; - } catch (e) { - throw new Error(`ApplicationRef instance not found`); - } - } - - /** - * Creates an instance of a Component and attaches it to the View Container found at the - * `location` specified as {@link ViewContainerRef}. - * - * You can optionally provide `providers` to configure the {@link Injector} provisioned for this - * Component Instance. - * - * Returns {@link ComponentRef} representing the newly created Component. - * @param ComponentClass - @Component class - * @param location - reference to the location - * @param providers - optional array of providers - * @returns {ComponentRef} - returns ComponentRef - */ - public appendNextToLocation(ComponentClass:Type, - location:ViewContainerRef, - providers?:ResolvedReflectiveProvider[]):ComponentRef { - let componentFactory = this.componentFactoryResolver.resolveComponentFactory(ComponentClass); - let parentInjector = location.parentInjector; - let childInjector: Injector = parentInjector; - if (providers && providers.length > 0) { - childInjector = ReflectiveInjector.fromResolvedProviders(providers, parentInjector); - } - - return location.createComponent(componentFactory, location.length, childInjector); - } - - /** - * Helper methods to add ComponentClass(like modal backdrop) with options - * of type ComponentOptionsClass to element next to application root - * or next to provided instance of view container - * @param ComponentClass - @Component class - * @param ComponentOptionsClass - options class - * @param options - instance of options - * @returns {ComponentRef} - returns ComponentRef - */ - public appendNextToRoot(ComponentClass:Type, - ComponentOptionsClass:any, - options:any):ComponentRef { - let location = this.getRootViewContainerRef(); - let providers = ReflectiveInjector.resolve([ - {provide: ComponentOptionsClass, useValue: options} - ]); - return this.appendNextToLocation(ComponentClass, location, providers); - } -} diff --git a/src/utils/position.ts b/src/utils/position.ts deleted file mode 100644 index fb2dbdc8b8..0000000000 --- a/src/utils/position.ts +++ /dev/null @@ -1,155 +0,0 @@ -/** - * @deprecated - */ -import { KeyAttribute } from './common'; - -export class PositionService { - /** - * Provides read-only equivalent of jQuery's position function: - * http://api.jquery.com/position/ - */ - public position(nativeEl:HTMLElement):{width:number, height:number, top:number, left:number} { - let elBCR = this.offset(nativeEl); - let offsetParentBCR = {top: 0, left: 0}; - let offsetParentEl = this.parentOffsetEl(nativeEl); - if (offsetParentEl !== this.document as any) { - offsetParentBCR = this.offset(offsetParentEl); - offsetParentBCR.top += offsetParentEl.clientTop - offsetParentEl.scrollTop; - offsetParentBCR.left += offsetParentEl.clientLeft - offsetParentEl.scrollLeft; - } - - let boundingClientRect = nativeEl.getBoundingClientRect(); - return { - width: boundingClientRect.width || nativeEl.offsetWidth, - height: boundingClientRect.height || nativeEl.offsetHeight, - top: elBCR.top - offsetParentBCR.top, - left: elBCR.left - offsetParentBCR.left - }; - } - - /** - * Provides read-only equivalent of jQuery's offset function: - * http://api.jquery.com/offset/ - */ - public offset(nativeEl:any):{width:number, height:number, top:number, left:number} { - let boundingClientRect = nativeEl.getBoundingClientRect(); - return { - width: boundingClientRect.width || nativeEl.offsetWidth, - height: boundingClientRect.height || nativeEl.offsetHeight, - top: boundingClientRect.top + (this.window.pageYOffset || this.document.documentElement.scrollTop), - left: boundingClientRect.left + (this.window.pageXOffset || this.document.documentElement.scrollLeft) - }; - } - - /** - * Provides coordinates for the targetEl in relation to hostEl - */ - public positionElements(hostEl:HTMLElement, targetEl:HTMLElement, positionStr:string, appendToBody:boolean):{top:number, left:number} { - let positionStrParts = positionStr.split('-'); - let pos0 = positionStrParts[0]; - let pos1 = positionStrParts[1] || 'center'; - let hostElPos = appendToBody ? - this.offset(hostEl) : - this.position(hostEl); - let targetElWidth = targetEl.offsetWidth; - let targetElHeight = targetEl.offsetHeight; - let shiftWidth:KeyAttribute = { - center():number { - return hostElPos.left + hostElPos.width / 2 - targetElWidth / 2; - }, - left():number { - return hostElPos.left; - }, - right():number { - return hostElPos.left + hostElPos.width; - } - }; - - let shiftHeight:KeyAttribute = { - center():number { - return hostElPos.top + hostElPos.height / 2 - targetElHeight / 2; - }, - top():number { - return hostElPos.top; - }, - bottom():number { - return hostElPos.top + hostElPos.height; - } - }; - - let targetElPos:{top:number, left:number}; - switch (pos0) { - case 'right': - targetElPos = { - top: shiftHeight[pos1](), - left: shiftWidth[pos0]() - }; - break; - case 'left': - targetElPos = { - top: shiftHeight[pos1](), - left: hostElPos.left - targetElWidth - }; - break; - case 'bottom': - targetElPos = { - top: shiftHeight[pos0](), - left: shiftWidth[pos1]() - }; - break; - default: - targetElPos = { - top: hostElPos.top - targetElHeight, - left: shiftWidth[pos1]() - }; - break; - } - - return targetElPos; - } - - protected get window():Window { - return window; - } - - protected get document():Document { - return window.document; - } - - protected getStyle(nativeEl:HTMLElement, cssProp:string):string { - // IE - if ((nativeEl as any).currentStyle) { - return (nativeEl as any).currentStyle[cssProp]; - } - - if (this.window.getComputedStyle) { - return (this.window.getComputedStyle(nativeEl) as KeyAttribute)[cssProp]; - } - // finally try and get inline style - return (nativeEl.style as KeyAttribute)[cssProp]; - } - - /** - * Checks if a given element is statically positioned - * @param nativeEl - raw DOM element - */ - protected isStaticPositioned(nativeEl:HTMLElement):boolean { - return (this.getStyle(nativeEl, 'position') || 'static' ) === 'static'; - } - - /** - * returns the closest, non-statically positioned parentOffset of a given - * element - * @param nativeEl - */ - protected parentOffsetEl(nativeEl:HTMLElement):any { - let offsetParent:any = nativeEl.offsetParent || this.document; - while (offsetParent && offsetParent !== this.document && - this.isStaticPositioned(offsetParent)) { - offsetParent = offsetParent.offsetParent; - } - return offsetParent || this.document; - }; -} - -export const positionService:PositionService = new PositionService();