Skip to content

Commit f507b24

Browse files
author
taulantdisha
committed
feat: Changed implementation of ng-image-editor
1 parent 29dd6a8 commit f507b24

8 files changed

+42
-47
lines changed

ng-package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
3+
"lib": {
4+
"entryFile": "public_api.ts",
5+
"externals": {
6+
"@angular/flex-layout": "ng.flex-layout"
7+
}
8+
}
9+
}

ngx-image-editor.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

ngx-image-editor.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "1.0.0-semantically-released",
44
"description": "Angular 5 Image Editor",
55
"scripts": {
6-
"clean": "rm -rf lib ",
7-
"build": "ngc -p ./tsconfig-ngc.json",
8-
"semantic-release": "npm run clean && semantic-release pre && npm run build && npm publish && semantic-release post"
6+
"clean": "rm -rf dist ",
7+
"build": "ng-packagr -p ng-package.json",
8+
"semantic-release": "npm run clean && semantic-release pre && npm run build && npm publish dist/ && semantic-release post"
99
},
1010
"main": "./bundles/ng.umd.js",
1111
"module": "./ngx-image-editor.es5.js",

public_api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./src/ngx-image-editor.module";

src/ngx-image-editor.component.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import {AfterViewInit, Component, Inject, OnDestroy, ViewEncapsulation, Optional, ViewChild} from '@angular/core';
2-
import {MD_DIALOG_DATA, MdDialogRef} from '@angular/material';
1+
import {
2+
AfterViewInit, Component, OnDestroy, ViewEncapsulation, ViewChild,
3+
OnInit, Input, Output, EventEmitter
4+
} from '@angular/core';
35
declare const Cropper: any;
46

57
@Component({
@@ -22,7 +24,7 @@ declare const Cropper: any;
2224
<button md-icon-button mdTooltip="Fullscreen">
2325
<md-icon>fullscreen</md-icon>
2426
</button>
25-
<button md-icon-button mdTooltip="Close" (click)="dialogRef.close()">
27+
<button md-icon-button mdTooltip="Close" (click)="close.emit()">
2628
<md-icon>clear</md-icon>
2729
</button>
2830
</div>
@@ -314,7 +316,7 @@ declare const Cropper: any;
314316
encapsulation: ViewEncapsulation.None
315317
})
316318

317-
export class NgxImageEditorComponent implements AfterViewInit, OnDestroy {
319+
export class NgxImageEditorComponent implements AfterViewInit, OnInit, OnDestroy {
318320

319321
public state: EditorOptions;
320322
public cropper: any;
@@ -339,15 +341,26 @@ export class NgxImageEditorComponent implements AfterViewInit, OnDestroy {
339341
@ViewChild('croppedImg')
340342
public croppedImg: any;
341343

342-
public constructor(public dialogRef: MdDialogRef<any>,
343-
@Optional() @Inject(MD_DIALOG_DATA)
344-
private data: EditorOptions) {
344+
@Input()
345+
public set configOption(options: EditorOptions) {
346+
this.state = options;
347+
}
348+
349+
@Output()
350+
public close: EventEmitter<void> = new EventEmitter<void>();
351+
352+
@Output()
353+
public file: EventEmitter<File> = new EventEmitter<File>();
354+
355+
public constructor() {
345356
this.zoomIn = 0;
346357
this.sliderValue = 0;
347358
this.loading = true;
348-
this.state = data;
349359
this.canvasFillColor = '#fff';
360+
this.state = new EditorOptions();
361+
}
350362

363+
public ngOnInit() {
351364
this.handleStateConfig();
352365
}
353366

@@ -437,7 +450,7 @@ export class NgxImageEditorComponent implements AfterViewInit, OnDestroy {
437450
}
438451

439452
public saveImage() {
440-
this.dialogRef.close(new File([this.blob], this.state.ImageName, {type: this.state.ImageType}));
453+
this.file.emit(new File([this.blob], this.state.ImageName, {type: this.state.ImageType}));
441454
}
442455

443456
private initializeCropper() {
@@ -573,7 +586,7 @@ export class NgxImageEditorComponent implements AfterViewInit, OnDestroy {
573586
}
574587

575588

576-
export interface EditorOptions {
589+
export class EditorOptions {
577590
ImageName: string;
578591
ImageUrl?: string;
579592
ImageType?: string;

src/ngx-image-editor.module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ export * from './ngx-image-editor.component';
3535
declarations: [
3636
NgxImageEditorComponent
3737
],
38-
exports: [NgxImageEditorComponent],
39-
entryComponents: [NgxImageEditorComponent]
38+
exports: [NgxImageEditorComponent]
4039
})
4140

4241

4342
export class NgxImageEditorModule {
43+
static forRoot(): ModuleWithProviders {
44+
return {
45+
ngModule: NgxImageEditorModule,
46+
};
47+
}
4448
}

tsconfig-ngc.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)