Skip to content

Commit

Permalink
feat(vex): support Angular RC5
Browse files Browse the repository at this point in the history
feat(js-native): support Angular RC5
  • Loading branch information
Shlomi Assaf (shlassaf) committed Aug 10, 2016
1 parent e4bbcc4 commit 2783d51
Show file tree
Hide file tree
Showing 32 changed files with 525 additions and 396 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
"zone.js": "^0.6.12"
},
"devDependencies": {
"@angular/core": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
"@angular/core": "2.0.0-rc.5",
"@angular/forms": "^0.3.0",
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
Expand Down
1 change: 0 additions & 1 deletion src/components/angular2-modal/angular2-modal.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { DOMOutsideEventPlugin } from './providers/outside-event-plugin';
import { ModalRenderer, DOMModalRenderer } from '../angular2-modal';

@NgModule({

})
export class ModalModule {
static forRoot(): ModuleWithProviders {
Expand Down
2 changes: 2 additions & 0 deletions src/components/angular2-modal/angular2-modal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Modal } from './providers/modal';

export * from './framework/fluent-assign';
export { createComponent } from './framework/createComponent';

export { DialogRef } from './models/dialog-ref';

export {
Expand Down
27 changes: 27 additions & 0 deletions src/components/angular2-modal/framework/createComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
ComponentRef,
ComponentFactoryResolver,
ViewContainerRef,
ReflectiveInjector,
ResolvedReflectiveProvider
} from '@angular/core';

export function createComponent(cfr: ComponentFactoryResolver,
type: any,
vcr: ViewContainerRef,
bindings: ResolvedReflectiveProvider[]): ComponentRef<any> {
return vcr.createComponent(
cfr.resolveComponentFactory(type),
vcr.length,
getInjector(vcr, bindings)
);
}

function getInjector(viewContainer: ViewContainerRef, bindings: ResolvedReflectiveProvider[]) {
const ctxInjector = viewContainer.parentInjector;
return Array.isArray(bindings) && bindings.length > 0 ?
ReflectiveInjector.fromResolvedProviders(bindings, ctxInjector) : ctxInjector;

}

export default createComponent;
28 changes: 18 additions & 10 deletions src/components/angular2-modal/plugins/bootstrap/bootstrap.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@ import {
ModalDropInFactory
} from '../../angular2-modal';

@NgModule({
imports: [ CommonModule ],
declarations: [
BSModalBackdrop,
BSMessageModal,
BSModalContainer,
BSModalFooter
],
providers: [
function getProviders(): any[] {
return [
{ provide: BaseModal, useClass: Modal },
{ provide: Modal, useClass: Modal },
{ provide: ModalBackdropComponent, useValue: BSModalBackdrop },
Expand All @@ -34,11 +27,26 @@ import {
prompt: modal => new OneButtonPresetBuilder(modal, <any>{isBlocking: true, keyboard: null}),
confirm: modal => new TwoButtonPresetBuilder(modal, <any>{isBlocking: true, keyboard: null})
}}
];
}

@NgModule({
imports: [ CommonModule ],
declarations: [
BSModalBackdrop,
BSMessageModal,
BSModalContainer,
BSModalFooter
],
providers: getProviders(),
entryComponents: [
BSModalBackdrop,
BSMessageModal
]
})
export class BootstrapModalModule {}
export class BootstrapModalModule {
static getProviders(): any[] {
return getProviders();
}
}

20 changes: 8 additions & 12 deletions src/components/angular2-modal/plugins/bootstrap/modal-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Component,
ComponentFactoryResolver,
ViewContainerRef,
ReflectiveInjector,
ViewChild,
ViewEncapsulation,
AfterViewInit,
Expand All @@ -15,7 +14,7 @@ import {
transition
} from '@angular/core';

import { DialogRef, ModalCompileConfig } from '../../angular2-modal';
import { createComponent, DialogRef, ModalCompileConfig } from '../../angular2-modal';

import { Modal } from './modal';
import { supportsKey } from '../../framework/utils';
Expand Down Expand Up @@ -92,13 +91,6 @@ export class BSModalContainer implements AfterViewInit {
}

ngAfterViewInit() {
const cmpFactory = this._cr.resolveComponentFactory(this._compileConfig.component as any),
vcr = this._viewContainer,
bindings = this._compileConfig.bindings,
ctxInjector = vcr.parentInjector,
childInjector = Array.isArray(bindings) && bindings.length > 0 ?
ReflectiveInjector.fromResolvedProviders(bindings, ctxInjector) : ctxInjector;

if (this.el.nativeElement) {
this.el.nativeElement.focus();
}
Expand All @@ -109,9 +101,13 @@ export class BSModalContainer implements AfterViewInit {
a CD exception. setTimeout is a workaround that mimics the async behavior.
Find out the error and remove setTimeout.
*/
setTimeout(
() => this.dialog.contentRef = vcr.createComponent(cmpFactory, vcr.length, childInjector)
);
setTimeout( () => {
this.dialog.contentRef = createComponent(
this._cr,
this._compileConfig.component,
this._viewContainer,
this._compileConfig.bindings);
});
}

onClickOutside() {
Expand Down
27 changes: 1 addition & 26 deletions src/components/angular2-modal/plugins/js-native/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
import { Provider } from '@angular/core';

import { Modal } from './modal';
import { JSNativeModalRenderer } from './js-native-modal-renderer';
import { JSNativePresetBuilder } from './presets/js-native-preset';

import {
Modal as BaseModal,
MODAL_PROVIDERS,
ModalBackdropComponent,
ModalDropInFactory,
ModalRenderer,
DROP_IN_TYPE
} from '../../angular2-modal';

export { Modal, JSNativeModal } from './modal';
export {
Expand All @@ -21,16 +8,4 @@ export {
export { JSNativeModalRenderer } from './js-native-modal-renderer';
export { JSNativePresetBuilder } from './presets/js-native-preset';


export const JS_NATIVE_MODAL_PROVIDERS: any[] = [
...MODAL_PROVIDERS,
new Provider(BaseModal, { useClass: Modal }),
new Provider(Modal, { useClass: Modal }),
new Provider(ModalRenderer, { useClass: JSNativeModalRenderer }),
new Provider(ModalBackdropComponent, { useValue: {} }),
new Provider(ModalDropInFactory, { useValue: {
alert: modal => new JSNativePresetBuilder(modal, DROP_IN_TYPE.alert),
prompt: modal => new JSNativePresetBuilder(modal, DROP_IN_TYPE.prompt),
confirm: modal => new JSNativePresetBuilder(modal, DROP_IN_TYPE.confirm)
} })
];
export { JSNativeModalModule } from './js-native.module';
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class JSNativeModalRenderer implements ModalRenderer {
render(type: Type,
viewContainer: ViewContainerRef,
bindings: ResolvedReflectiveProvider[],
dialog: DialogRef<JSNativeModalContext>): Promise<DialogRef<any>> {
dialog: DialogRef<JSNativeModalContext>): DialogRef<any> {

let result: string | boolean;
switch (dialog.context.dialogType) {
Expand All @@ -39,7 +39,7 @@ export class JSNativeModalRenderer implements ModalRenderer {
dialog.close(result);
}

return Promise.resolve(dialog);
return dialog;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NgModule } from '@angular/core';

import { Modal } from './modal';
import { JSNativeModalRenderer } from './js-native-modal-renderer';
import { JSNativePresetBuilder } from './presets/js-native-preset';

import {
Modal as BaseModal,
ModalBackdropComponent,
ModalDropInFactory,
ModalRenderer,
DROP_IN_TYPE
} from '../../angular2-modal';

function getProviders(): any[] {
return [
{ provide: BaseModal, useClass: Modal },
{ provide: Modal, useClass: Modal },
{ provide: ModalRenderer, useClass: JSNativeModalRenderer },
{ provide: ModalBackdropComponent, useValue: {} },
{ provide: ModalDropInFactory, useValue: {
alert: modal => new JSNativePresetBuilder(modal, DROP_IN_TYPE.alert),
prompt: modal => new JSNativePresetBuilder(modal, DROP_IN_TYPE.prompt),
confirm: modal => new JSNativePresetBuilder(modal, DROP_IN_TYPE.confirm)
}}
];
}

@NgModule({
providers: getProviders()
})
export class JSNativeModalModule {

static getProviders(): any[] {
return getProviders();
}

}
Loading

0 comments on commit 2783d51

Please sign in to comment.