diff --git a/.gitignore b/.gitignore index 57ff5a5..986fd2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea/ node_modules/ npm-debug.log - +js/ diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..e69de29 diff --git a/index.ts b/index.ts deleted file mode 100644 index 6f098fd..0000000 --- a/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import {Autosize} from './src/autosize.directive'; - -export * from './src/autosize.directive'; - -export default { - directives: [Autosize] -} diff --git a/package.json b/package.json index a07b2a0..998f36d 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,15 @@ { "name": "ionic2-autosize", - "version": "1.0.2", + "version": "1.1.0", "description": "Directive that automatically adjusts textarea height to fit content", "repository": { "type": "git", "url": "git+https://github.com/flivni/ionic2-autosize.git" }, + "main": "js/index.js", + "typings": "js/index", "scripts": { + "prepublish": "cd src && tsc" }, "keywords": [ "ng2", @@ -22,7 +25,6 @@ "Zeb Burke-Conte (http://zebburkeconte.com)", "Felix Livni " ], - "main": "ionic2-autosize.ts", "license": "MIT", "devDependencies": { "@angular/common": "2.0.0-rc.4", @@ -34,6 +36,6 @@ "@angular/platform-browser-dynamic": "2.0.0-rc.4", "rxjs": "5.0.0-beta.6", "zone.js": "0.6.12", - "typescript": "^1.7.3" + "typescript": "^2.2.0" } } diff --git a/src/autosize.directive.d.ts b/src/autosize.directive.d.ts new file mode 100644 index 0000000..9bd5480 --- /dev/null +++ b/src/autosize.directive.d.ts @@ -0,0 +1,8 @@ +import { ElementRef, OnInit } from '@angular/core'; +export declare class Autosize implements OnInit { + element: ElementRef; + onInput(textArea: HTMLTextAreaElement): void; + constructor(element: ElementRef); + ngOnInit(): void; + adjust(): void; +} diff --git a/src/autosize.directive.js b/src/autosize.directive.js new file mode 100644 index 0000000..fb7505f --- /dev/null +++ b/src/autosize.directive.js @@ -0,0 +1,46 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var core_1 = require('@angular/core'); +var Autosize = (function () { + function Autosize(element) { + this.element = element; + } + Autosize.prototype.onInput = function (textArea) { + this.adjust(); + }; + Autosize.prototype.ngOnInit = function () { + var _this = this; + setTimeout(function () { return _this.adjust(); }, 0); + }; + Autosize.prototype.adjust = function () { + var textArea = this.element.nativeElement.getElementsByTagName('textarea')[0]; + textArea.style.overflow = 'hidden'; + textArea.style.height = 'auto'; + textArea.style.height = textArea.scrollHeight + "px"; + }; + Object.defineProperty(Autosize.prototype, "onInput", + __decorate([ + core_1.HostListener('input', ['$event.target']), + __metadata('design:type', Function), + __metadata('design:paramtypes', [HTMLTextAreaElement]), + __metadata('design:returntype', void 0) + ], Autosize.prototype, "onInput", Object.getOwnPropertyDescriptor(Autosize.prototype, "onInput"))); + Autosize = __decorate([ + core_1.Directive({ + selector: 'ion-textarea[autosize]' + }), + __metadata('design:paramtypes', [(typeof ElementRef !== 'undefined' && ElementRef) || Object]) + ], Autosize); + return Autosize; +})(); +exports.Autosize = Autosize; +//# sourceMappingURL=autosize.directive.js.map \ No newline at end of file diff --git a/src/autosize.directive.js.map b/src/autosize.directive.js.map new file mode 100644 index 0000000..37bd388 --- /dev/null +++ b/src/autosize.directive.js.map @@ -0,0 +1 @@ +{"version":3,"file":"autosize.directive.js","sourceRoot":"","sources":["autosize.directive.ts"],"names":["Autosize","Autosize.constructor","Autosize.onInput","Autosize.ngOnInit","Autosize.adjust"],"mappings":";;;;;;;;;;;AAAA,qBAA0D,eAAe,CAAC,CAAA;AAE1E;IASEA,kBAAmBA,OAAkBA;QAAlBC,YAAOA,GAAPA,OAAOA,CAAWA;IACrCA,CAACA;IALDD,0BAAOA,GADPA,UACQA,QAA4BA;QAClCE,IAAIA,CAACA,MAAMA,EAAEA,CAACA;IAChBA,CAACA;IAKDF,2BAAQA,GAARA;QAAAG,iBAECA;QADCA,UAAUA,CAACA,cAAMA,OAAAA,KAAIA,CAACA,MAAMA,EAAEA,EAAbA,CAAaA,EAAEA,CAACA,CAACA,CAACA;IACrCA,CAACA;IAEDH,yBAAMA,GAANA;QACEI,IAAIA,QAAQA,GAAGA,IAAIA,CAACA,OAAOA,CAACA,aAAaA,CAACA,oBAAoBA,CAACA,UAAUA,CAACA,CAACA,CAACA,CAACA,CAACA;QAC9EA,QAAQA,CAACA,KAAKA,CAACA,QAAQA,GAAGA,QAAQA,CAACA;QACnCA,QAAQA,CAACA,KAAKA,CAACA,MAAMA,GAAGA,MAAMA,CAACA;QAC/BA,QAAQA,CAACA,KAAKA,CAACA,MAAMA,GAAGA,QAAQA,CAACA,YAAYA,GAAGA,IAAIA,CAACA;IACvDA,CAACA;IAjBDJ,sBACAA,6BAAOA;;YADNA,mBAAYA,CAACA,OAAOA,EAAEA,CAACA,eAAeA,CAACA,CAACA;;;;WACzCA,6BAAOA,kCAAPA,6BAAOA,IAENA;IAPHA;QAACA,gBAASA,CAACA;YACTA,QAAQA,EAAEA,wBAAwBA;SACnCA,CAACA;;iBAoBDA;IAADA,eAACA;AAADA,CAACA,AAtBD,IAsBC;AAnBY,gBAAQ,WAmBpB,CAAA"} \ No newline at end of file diff --git a/src/autosize.directive.ts b/src/autosize.directive.ts index 54d0174..c5afc06 100644 --- a/src/autosize.directive.ts +++ b/src/autosize.directive.ts @@ -3,7 +3,6 @@ import {ElementRef, HostListener, Directive, OnInit} from '@angular/core'; @Directive({ selector: 'ion-textarea[autosize]' }) - export class Autosize implements OnInit { @HostListener('input', ['$event.target']) onInput(textArea:HTMLTextAreaElement):void { diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..7c0153b --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,6 @@ +import { Autosize } from './autosize.directive'; +export * from './autosize.directive'; +declare var _default: { + directives: typeof Autosize[]; +}; +export default _default; diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..89f281d --- /dev/null +++ b/src/index.js @@ -0,0 +1,9 @@ +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +var autosize_directive_1 = require('./autosize.directive'); +__export(require('./autosize.directive')); +exports.default = { + directives: [autosize_directive_1.Autosize] +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/src/index.js.map b/src/index.js.map new file mode 100644 index 0000000..078be6c --- /dev/null +++ b/src/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,mCAAuB,sBAAsB,CAAC,CAAA;AAE9C,iBAAc,sBAAsB,CAAC,EAAA;AAErC,kBAAe;IACb,UAAU,EAAE,CAAC,6BAAQ,CAAC;CACvB,CAAA"} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..d8443c9 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,7 @@ +import {Autosize} from './autosize.directive'; + +export * from './autosize.directive'; + +export default { + directives: [Autosize] +} diff --git a/tsconfig.json b/src/tsconfig.json similarity index 56% rename from tsconfig.json rename to src/tsconfig.json index d5e4e90..81da8e8 100644 --- a/tsconfig.json +++ b/src/tsconfig.json @@ -2,11 +2,15 @@ "compilerOptions": { "noImplicitAny": false, "module": "commonjs", - "target": "ES5", + "target": "ES6", "emitDecoratorMetadata": true, "experimentalDecorators": true, "sourceMap": true, - "declaration": true + "declaration": true, + "outDir": "../js" }, - "exclude": ["node_modules"] + "filesGlob": [ + "./**/*.ts", + "!./node_modules/**/*.ts" + ] }