@starley/ion-directives 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+
2
+ # Ion-directives
3
+
4
+ São directivas para uso em ionic, para mascramento de inputs, pressHold, tap e doubleTap!
5
+
6
+ ![Badge em Desenvolvimento](http://img.shields.io/static/v1?label=STATUS&message=EM%20DESENVOLVIMENTO&color=GREEN&style=for-the-badge)
7
+
8
+
9
+
10
+ ## Authors
11
+
12
+ - [@starleydev](https://www.github.com/starleyDev)
13
+
14
+
15
+ ## Installation
16
+
17
+
18
+ ```bash
19
+ npm i @starley/ion-directives
20
+ ```
21
+
22
+ ## Usage/Examples
23
+
24
+ Importe dentro do modulo que ira utilizar
25
+
26
+ my-component.module.ts
27
+ ```typescript
28
+ import { DirectivesModule } from '@starley/ion-directives';
29
+
30
+
31
+ @NgModule({
32
+ ...
33
+ imports: [
34
+ ...,
35
+ DirectivesModule
36
+ ],
37
+ ...
38
+ })
39
+ export class MyComponent {}
40
+ ```
41
+
42
+ ### Para usar a mascara 'appMask'
43
+
44
+ Adicione dentro do input a chamada passando após o simbolo de '=' a formatação desejada!
45
+
46
+ my-component.html
47
+ ```html
48
+ <ion-content>
49
+ ...
50
+ <ion-item>
51
+ <ion-label>CPF</ion-label>
52
+ <ion-input class="ion-text-right" [(ngModel)]="cpf" maxlength="14" type="number" placeholder="000.000.000-00" appMask="***.***.***-**"></ion-input>
53
+ </ion-item>
54
+ ...
55
+ </ion-content>
56
+ ```
57
+
58
+ Resultado --> 123.456.789-00
59
+
60
+ ### Para usar a pressHold 'appPressHold'
61
+
62
+ O tempo minimo e de 450 milisegundos! **( Adicionarei no futuro a possibilidade de customizar esse tempo! )**
63
+
64
+ Adicione a chamada de 'appPressHold' juntamente com o '(press)' pois ele será o responsavel pela ação!
65
+
66
+ my-component.html
67
+ ```html
68
+ <ion-content>
69
+ ...
70
+ <ion-item appPressHold (press)="doSomething()>
71
+ <ion-label>PressHold</ion-label>
72
+ </ion-item>
73
+ ...
74
+ </ion-content>
75
+ ```
76
+
77
+ ### Para usar 'appTap'
78
+
79
+ Adicione dentro de um elemento qualquer! Ao adicionar você tera duas opções!
80
+
81
+ *O (tap) tera ação de intervalo de 250 milisegundos*
82
+
83
+ *O (doubleTap) terá ação de intervalo de 300 milisegundos*
84
+
85
+ my-component.html
86
+ ```html
87
+ <ion-content>
88
+ ...
89
+ <ion-content>
90
+ ...
91
+ <ion-item appTap (tap)="doSomething()" (doubleTap)="doSomething()">
92
+ <ion-label>tap</ion-label>
93
+ </ion-item>
94
+ ...
95
+ </ion-content>
96
+ ...
97
+ </ion-content>
98
+ ```
99
+
100
+ ## License
101
+
102
+
103
+ [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
104
+
@@ -0,0 +1,16 @@
1
+ import { ModuleWithProviders } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ import * as i1 from "./press-hold/press-hold.directive";
4
+ import * as i2 from "./tap/tap.directive";
5
+ import * as i3 from "./input-mask/input-mask.directive";
6
+ import * as i4 from "@angular/common";
7
+ /**
8
+ * Gerencia precionamento de enventos
9
+ * @author Starley Cazorla
10
+ */
11
+ export declare class DirectivesModule {
12
+ static forRoot(): ModuleWithProviders<DirectivesModule>;
13
+ static ɵfac: i0.ɵɵFactoryDeclaration<DirectivesModule, never>;
14
+ static ɵmod: i0.ɵɵNgModuleDeclaration<DirectivesModule, [typeof i1.PressHoldDirective, typeof i2.TapDirective, typeof i3.IonInputMaskDirective], [typeof i4.CommonModule], [typeof i1.PressHoldDirective, typeof i2.TapDirective, typeof i3.IonInputMaskDirective]>;
15
+ static ɵinj: i0.ɵɵInjectorDeclaration<DirectivesModule>;
16
+ }
@@ -0,0 +1,50 @@
1
+ import { CUSTOM_ELEMENTS_SCHEMA, NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2
+ import { PressHoldDirective } from './press-hold/press-hold.directive';
3
+ import { TapDirective } from './tap/tap.directive';
4
+ import { IonInputMaskDirective } from './input-mask/input-mask.directive';
5
+ import { CommonModule } from '@angular/common';
6
+ import * as i0 from "@angular/core";
7
+ /**
8
+ * Gerencia precionamento de enventos
9
+ * @author Starley Cazorla
10
+ */
11
+ var DirectivesModule = /** @class */ (function () {
12
+ function DirectivesModule() {
13
+ }
14
+ DirectivesModule.forRoot = function () {
15
+ return {
16
+ ngModule: DirectivesModule,
17
+ providers: []
18
+ };
19
+ };
20
+ DirectivesModule.ɵfac = function DirectivesModule_Factory(t) { return new (t || DirectivesModule)(); };
21
+ DirectivesModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: DirectivesModule });
22
+ DirectivesModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule] });
23
+ return DirectivesModule;
24
+ }());
25
+ export { DirectivesModule };
26
+ (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DirectivesModule, [{
27
+ type: NgModule,
28
+ args: [{
29
+ declarations: [
30
+ PressHoldDirective,
31
+ TapDirective,
32
+ IonInputMaskDirective
33
+ ],
34
+ imports: [
35
+ CommonModule
36
+ ],
37
+ exports: [
38
+ PressHoldDirective,
39
+ TapDirective,
40
+ IonInputMaskDirective
41
+ ],
42
+ schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]
43
+ }]
44
+ }], null, null); })();
45
+ (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(DirectivesModule, { declarations: [PressHoldDirective,
46
+ TapDirective,
47
+ IonInputMaskDirective], imports: [CommonModule], exports: [PressHoldDirective,
48
+ TapDirective,
49
+ IonInputMaskDirective] }); })();
50
+ //# sourceMappingURL=directive.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directive.module.js","sourceRoot":"","sources":["../src/directive.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAuB,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;;AAE/C;;;GAGG;AAEH;IAAA;KAwBE;IANS,wBAAO,GAAd;QACI,OAAO;YACH,QAAQ,EAAE,gBAAgB;YAC1B,SAAS,EAAE,EAAE;SAChB,CAAC;IACN,CAAC;oFANQ,gBAAgB;sEAAhB,gBAAgB;0EAVrB,YAAY;2BAlBpB;CAmCE,AAxBF,IAwBE;SAPW,gBAAgB;uFAAhB,gBAAgB;cAjB5B,QAAQ;eAAC;gBACN,YAAY,EAAE;oBACV,kBAAkB;oBAClB,YAAY;oBACZ,qBAAqB;iBACxB;gBACD,OAAO,EAAE;oBACL,YAAY;iBACf;gBACD,OAAO,EAAE;oBACL,kBAAkB;oBAClB,YAAY;oBACZ,qBAAqB;iBACxB;gBACD,OAAO,EAAE,CAAC,sBAAsB,EAAE,gBAAgB,CAAC;aAEtD;;wFACY,gBAAgB,mBAfrB,kBAAkB;QAClB,YAAY;QACZ,qBAAqB,aAGrB,YAAY,aAGZ,kBAAkB;QAClB,YAAY;QACZ,qBAAqB","sourcesContent":["import { CUSTOM_ELEMENTS_SCHEMA, ModuleWithProviders, NgModule, NO_ERRORS_SCHEMA } from '@angular/core';\nimport { PressHoldDirective } from './press-hold/press-hold.directive';\nimport { TapDirective } from './tap/tap.directive';\nimport { IonInputMaskDirective } from './input-mask/input-mask.directive';\nimport { CommonModule } from '@angular/common';\n\n/**\n * Gerencia precionamento de enventos\n * @author Starley Cazorla\n */\n\n@NgModule({\n declarations: [\n PressHoldDirective,\n TapDirective,\n IonInputMaskDirective\n ],\n imports: [\n CommonModule\n ],\n exports: [\n PressHoldDirective,\n TapDirective,\n IonInputMaskDirective\n ],\n schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]\n\n})\nexport class DirectivesModule {\n static forRoot(): ModuleWithProviders<DirectivesModule> {\n return {\n ngModule: DirectivesModule,\n providers: []\n };\n }\n }\n"]}
@@ -0,0 +1,4 @@
1
+ export * from './input-mask/input-mask.directive';
2
+ export * from './press-hold/press-hold.directive';
3
+ export * from './tap/tap.directive';
4
+ export * from './directive.module';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './input-mask/input-mask.directive';
2
+ export * from './press-hold/press-hold.directive';
3
+ export * from './tap/tap.directive';
4
+ export * from './directive.module';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from './input-mask/input-mask.directive'\nexport * from './press-hold/press-hold.directive';\nexport * from './tap/tap.directive'\nexport * from './directive.module';\n"]}
@@ -0,0 +1,24 @@
1
+ import { NgModel } from "@angular/forms";
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Responsavel pelo mascaramento de inputs
5
+ * @author Thiago Przyczynski
6
+ * przyczynski@gmail.com
7
+ */
8
+ export declare class IonInputMaskDirective {
9
+ model: NgModel;
10
+ pattern: string;
11
+ /**
12
+ * Construtor
13
+ * @param {NgModel} model
14
+ * @param {string} pattern
15
+ */
16
+ constructor(model: NgModel, pattern: string);
17
+ /**
18
+ * Listener para mudança de valor do input
19
+ * @param event
20
+ */
21
+ onKeyDown(event: any): boolean;
22
+ static ɵfac: i0.ɵɵFactoryDeclaration<IonInputMaskDirective, [null, { attribute: "appMask"; }]>;
23
+ static ɵdir: i0.ɵɵDirectiveDeclaration<IonInputMaskDirective, "[appMask]", never, {}, {}, never, never, false, never>;
24
+ }
@@ -0,0 +1,77 @@
1
+ import { Attribute, Directive } from '@angular/core';
2
+ import { NgModel } from "@angular/forms";
3
+ import * as i0 from "@angular/core";
4
+ import * as i1 from "@angular/forms";
5
+ /**
6
+ * Responsavel pelo mascaramento de inputs
7
+ * @author Thiago Przyczynski
8
+ * przyczynski@gmail.com
9
+ */
10
+ var IonInputMaskDirective = /** @class */ (function () {
11
+ /**
12
+ * Construtor
13
+ * @param {NgModel} model
14
+ * @param {string} pattern
15
+ */
16
+ function IonInputMaskDirective(model, pattern) {
17
+ this.model = model;
18
+ this.pattern = pattern;
19
+ }
20
+ /**
21
+ * Listener para mudança de valor do input
22
+ * @param event
23
+ */
24
+ IonInputMaskDirective.prototype.onKeyDown = function (event) {
25
+ var value = event.target.value, pattern = this.pattern;
26
+ if (event.keyIdentifier === 'U+0008' || event.keyCode === 8 || event.key === 'Backspace') {
27
+ if (value.length) { //prevent fatal exception when backspacing empty value in progressive web app
28
+ //remove all trailing formatting then delete character
29
+ while (pattern[value.length] && pattern[value.length] !== '*') {
30
+ value = value.substring(0, value.length - 1);
31
+ }
32
+ //remove all leading formatting to restore placeholder
33
+ if (pattern.substring(0, value.length).indexOf('*') < 0) {
34
+ value = value.substring(0, value.length - 1);
35
+ }
36
+ }
37
+ }
38
+ else {
39
+ var maskIndex = value.length;
40
+ var formatted = '';
41
+ formatted += value;
42
+ if (maskIndex < pattern.length) {
43
+ //apply trailing formatting
44
+ while (pattern[maskIndex] !== '*') {
45
+ formatted += pattern[maskIndex];
46
+ maskIndex++;
47
+ }
48
+ }
49
+ value = formatted;
50
+ }
51
+ event.target.value = value;
52
+ if (this.model) {
53
+ this.model.update.emit(value);
54
+ }
55
+ return true;
56
+ };
57
+ IonInputMaskDirective.ɵfac = function IonInputMaskDirective_Factory(t) { return new (t || IonInputMaskDirective)(i0.ɵɵdirectiveInject(i1.NgModel), i0.ɵɵinjectAttribute('appMask')); };
58
+ IonInputMaskDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: IonInputMaskDirective, selectors: [["", "appMask", ""]], hostBindings: function IonInputMaskDirective_HostBindings(rf, ctx) { if (rf & 1) {
59
+ i0.ɵɵlistener("keydown", function IonInputMaskDirective_keydown_HostBindingHandler($event) { return ctx.onKeyDown($event); });
60
+ } }, features: [i0.ɵɵProvidersFeature([NgModel])] });
61
+ return IonInputMaskDirective;
62
+ }());
63
+ export { IonInputMaskDirective };
64
+ (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(IonInputMaskDirective, [{
65
+ type: Directive,
66
+ args: [{
67
+ selector: '[appMask]',
68
+ host: {
69
+ '(keydown)': 'onKeyDown($event)'
70
+ },
71
+ providers: [NgModel]
72
+ }]
73
+ }], function () { return [{ type: i1.NgModel }, { type: undefined, decorators: [{
74
+ type: Attribute,
75
+ args: ['appMask']
76
+ }] }]; }, null); })();
77
+ //# sourceMappingURL=input-mask.directive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-mask.directive.js","sourceRoot":"","sources":["../../src/input-mask/input-mask.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;;;AAEzC;;;;GAIG;AAEH;IAWI;;;;OAIG;IACH,+BAAmB,KAAc,EACP,OAAe;QADtB,UAAK,GAAL,KAAK,CAAS;QAE7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,yCAAS,GAAT,UAAU,KAAU;QAChB,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,EAC1B,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,IAAI,KAAK,CAAC,aAAa,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,WAA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DY,qBAAqB;uFAArB,qBAAqB;cAPjC,SAAS;eAAC;gBACP,QAAQ,EAAE,WAAW;gBACrB,IAAI,EAAE;oBACF,WAAW,EAAE,mBAAmB;iBACnC;gBACD,SAAS,EAAE,CAAC,OAAO,CAAC;aACvB;;sBAWQ,SAAS;uBAAC,SAAS","sourcesContent":["import { Attribute, Directive } from '@angular/core';\nimport { NgModel } from \"@angular/forms\";\n\n/**\n * Responsavel pelo mascaramento de inputs\n * @author Thiago Przyczynski\n * przyczynski@gmail.com\n */\n\n@Directive({\n selector: '[appMask]',\n host: {\n '(keydown)': 'onKeyDown($event)'\n },\n providers: [NgModel]\n})\nexport class IonInputMaskDirective {\n\n pattern: string;\n\n /**\n * Construtor\n * @param {NgModel} model\n * @param {string} pattern\n */\n constructor(public model: NgModel,\n @Attribute('appMask') pattern: string) {\n this.pattern = pattern;\n }\n\n /**\n * Listener para mudança de valor do input\n * @param event\n */\n onKeyDown(event: any) {\n let value = event.target.value,\n pattern = this.pattern;\n if (event.keyIdentifier === 'U+0008' || event.keyCode === 8 || event.key === 'Backspace') {\n if (value.length) { //prevent fatal exception when backspacing empty value in progressive web app\n //remove all trailing formatting then delete character\n while (pattern[value.length] && pattern[value.length] !== '*') {\n value = value.substring(0, value.length - 1);\n }\n //remove all leading formatting to restore placeholder\n if (pattern.substring(0, value.length).indexOf('*') < 0) {\n value = value.substring(0, value.length - 1);\n }\n }\n } else {\n let maskIndex = value.length;\n let formatted = '';\n formatted += value;\n if (maskIndex < pattern.length) {\n //apply trailing formatting\n while (pattern[maskIndex] !== '*') {\n formatted += pattern[maskIndex];\n maskIndex++;\n }\n }\n value = formatted;\n }\n event.target.value = value;\n if (this.model) {\n this.model.update.emit(value);\n }\n return true;\n }\n\n}"]}
@@ -0,0 +1,28 @@
1
+ import { EventEmitter, OnInit } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Gerencia pressHold
5
+ * @author Starley Cazorla
6
+ */
7
+ export declare class PressHoldDirective implements OnInit {
8
+ press: EventEmitter<any>;
9
+ pressGesture: {
10
+ name: string;
11
+ enabled: boolean;
12
+ interval: number;
13
+ };
14
+ pressTimeout: any;
15
+ isPressing: boolean;
16
+ lastTap: number;
17
+ tapCount: number;
18
+ tapTimeout: any;
19
+ constructor();
20
+ ngOnInit(): void;
21
+ onPress(event: {
22
+ type: any;
23
+ }): void;
24
+ private handlePressing;
25
+ private resetTaps;
26
+ static ɵfac: i0.ɵɵFactoryDeclaration<PressHoldDirective, never>;
27
+ static ɵdir: i0.ɵɵDirectiveDeclaration<PressHoldDirective, "[appPressHold]", never, {}, { "press": "press"; }, never, never, false, never>;
28
+ }
@@ -0,0 +1,75 @@
1
+ import { Directive, EventEmitter, HostListener, Output } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Gerencia pressHold
5
+ * @author Starley Cazorla
6
+ */
7
+ var PressHoldDirective = /** @class */ (function () {
8
+ function PressHoldDirective() {
9
+ this.press = new EventEmitter();
10
+ this.pressGesture = {
11
+ name: 'press',
12
+ enabled: false,
13
+ interval: 350
14
+ };
15
+ this.pressTimeout = null;
16
+ this.isPressing = false;
17
+ this.lastTap = 0;
18
+ this.tapCount = 0;
19
+ this.tapTimeout = null;
20
+ }
21
+ PressHoldDirective.prototype.ngOnInit = function () {
22
+ this.pressGesture.enabled = true;
23
+ };
24
+ PressHoldDirective.prototype.onPress = function (event) {
25
+ if (!this.pressGesture.enabled) {
26
+ return;
27
+ } // Press is not enabled, don't do anything.
28
+ this.handlePressing(event.type);
29
+ };
30
+ PressHoldDirective.prototype.handlePressing = function (type) {
31
+ var _this = this;
32
+ if (type == 'touchstart') {
33
+ this.pressTimeout = setTimeout(function () {
34
+ _this.isPressing = true;
35
+ }, this.pressGesture.interval); // Considered a press if it's longer than interval (default: 251).
36
+ }
37
+ else if (type == 'touchend') {
38
+ clearTimeout(this.pressTimeout);
39
+ if (this.isPressing) {
40
+ this.press.emit('end');
41
+ this.resetTaps(); // Just incase this gets passed as a tap event too.
42
+ }
43
+ // Clicks have a natural delay of 300ms, so we have to account for that, before resetting isPressing.
44
+ // Otherwise a tap event is emitted.
45
+ setTimeout(function () { return _this.isPressing = false; }, 50);
46
+ }
47
+ };
48
+ PressHoldDirective.prototype.resetTaps = function () {
49
+ clearTimeout(this.tapTimeout); // clear the old timeout
50
+ this.tapCount = 0;
51
+ this.tapTimeout = null;
52
+ this.lastTap = 0;
53
+ };
54
+ PressHoldDirective.ɵfac = function PressHoldDirective_Factory(t) { return new (t || PressHoldDirective)(); };
55
+ PressHoldDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: PressHoldDirective, selectors: [["", "appPressHold", ""]], hostBindings: function PressHoldDirective_HostBindings(rf, ctx) { if (rf & 1) {
56
+ i0.ɵɵlistener("touchstart", function PressHoldDirective_touchstart_HostBindingHandler($event) { return ctx.onPress($event); })("touchend", function PressHoldDirective_touchend_HostBindingHandler($event) { return ctx.onPress($event); });
57
+ } }, outputs: { press: "press" } });
58
+ return PressHoldDirective;
59
+ }());
60
+ export { PressHoldDirective };
61
+ (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PressHoldDirective, [{
62
+ type: Directive,
63
+ args: [{
64
+ selector: '[appPressHold]'
65
+ }]
66
+ }], function () { return []; }, { press: [{
67
+ type: Output
68
+ }], onPress: [{
69
+ type: HostListener,
70
+ args: ['touchstart', ['$event']]
71
+ }, {
72
+ type: HostListener,
73
+ args: ['touchend', ['$event']]
74
+ }] }); })();
75
+ //# sourceMappingURL=press-hold.directive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"press-hold.directive.js","sourceRoot":"","sources":["../../src/press-hold/press-hold.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAU,MAAM,EAAE,MAAM,eAAe,CAAC;;AAEtF;;;GAGG;AAEH;IAiBI;QAZU,UAAK,GAAG,IAAI,YAAY,EAAE,CAAC;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,UAAU,CAAC,CAAC,CAAC,wBAAwB;QACvD,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACrB,CAAC;wFAnDQ,kBAAkB;yEAAlB,kBAAkB;mHAAlB,mBAAe,0FAAf,mBAAe;;6BAV5B;CA+DC,AAxDD,IAwDC;SArDY,kBAAkB;uFAAlB,kBAAkB;cAH9B,SAAS;eAAC;gBACP,QAAQ,EAAE,gBAAgB;aAC7B;sCAGa,KAAK;kBAAd,MAAM;YAoBP,OAAO;kBAFN,YAAY;mBAAC,YAAY,EAAE,CAAC,QAAQ,CAAC;;kBACrC,YAAY;mBAAC,UAAU,EAAE,CAAC,QAAQ,CAAC","sourcesContent":["import { Directive, EventEmitter, HostListener, OnInit, Output } from '@angular/core';\n\n/**\n * Gerencia pressHold\n * @author Starley Cazorla\n */\n\n@Directive({\n selector: '[appPressHold]'\n})\nexport class PressHoldDirective implements OnInit {\n\n @Output() press = new EventEmitter();\n pressGesture = {\n name: 'press',\n enabled: false,\n interval: 350\n };\n pressTimeout: any = null;\n isPressing: boolean = false;\n lastTap = 0;\n tapCount = 0;\n tapTimeout: any = null;\n\n constructor() { }\n\n ngOnInit(): void {\n this.pressGesture.enabled = true;\n }\n\n @HostListener('touchstart', ['$event'])\n @HostListener('touchend', ['$event'])\n onPress(event: { type: any; }) {\n if (!this.pressGesture.enabled) {\n return;\n } // Press is not enabled, don't do anything.\n this.handlePressing(event.type);\n }\n\n private handlePressing(type: string) { // touchend or touchstart\n if (type == 'touchstart') {\n this.pressTimeout = setTimeout(() => {\n this.isPressing = true;\n }, this.pressGesture.interval); // Considered a press if it's longer than interval (default: 251).\n } else if (type == 'touchend') {\n clearTimeout(this.pressTimeout);\n if (this.isPressing) {\n this.press.emit('end');\n this.resetTaps(); // Just incase this gets passed as a tap event too.\n }\n // Clicks have a natural delay of 300ms, so we have to account for that, before resetting isPressing.\n // Otherwise a tap event is emitted.\n setTimeout(() => this.isPressing = false, 50);\n }\n }\n\n private resetTaps() {\n clearTimeout(this.tapTimeout); // clear the old timeout\n this.tapCount = 0;\n this.tapTimeout = null;\n this.lastTap = 0;\n }\n\n}"]}
@@ -0,0 +1,32 @@
1
+ import { EventEmitter, OnInit } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Gerencia tap e doubleTap
5
+ * @author Starley Cazorla
6
+ */
7
+ export declare class TapDirective implements OnInit {
8
+ tap: EventEmitter<any>;
9
+ doubleTap: EventEmitter<any>;
10
+ lastTap: number;
11
+ tapCount: number;
12
+ tapTimeout: any;
13
+ tapGesture: {
14
+ name: string;
15
+ enabled: boolean;
16
+ interval: number;
17
+ };
18
+ doubleTapGesture: {
19
+ name: string;
20
+ enabled: boolean;
21
+ interval: number;
22
+ };
23
+ constructor();
24
+ ngOnInit(): void;
25
+ handleTaps(e: {
26
+ timeStamp: number;
27
+ }): void;
28
+ private emitTaps;
29
+ private resetTaps;
30
+ static ɵfac: i0.ɵɵFactoryDeclaration<TapDirective, never>;
31
+ static ɵdir: i0.ɵɵDirectiveDeclaration<TapDirective, "[appTap]", never, {}, { "tap": "tap"; "doubleTap": "doubleTap"; }, never, never, false, never>;
32
+ }
@@ -0,0 +1,80 @@
1
+ import { Directive, EventEmitter, HostListener, Output } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Gerencia tap e doubleTap
5
+ * @author Starley Cazorla
6
+ */
7
+ var TapDirective = /** @class */ (function () {
8
+ function TapDirective() {
9
+ this.tap = new EventEmitter();
10
+ this.doubleTap = new EventEmitter();
11
+ this.lastTap = 0;
12
+ this.tapCount = 0;
13
+ this.tapTimeout = null;
14
+ this.tapGesture = {
15
+ name: 'tap',
16
+ enabled: false,
17
+ interval: 250,
18
+ };
19
+ this.doubleTapGesture = {
20
+ name: 'doubleTap',
21
+ enabled: false,
22
+ interval: 300,
23
+ };
24
+ }
25
+ TapDirective.prototype.ngOnInit = function () {
26
+ this.tapGesture.enabled = true;
27
+ this.doubleTapGesture.enabled = true;
28
+ };
29
+ TapDirective.prototype.handleTaps = function (e) {
30
+ var _this = this;
31
+ var tapTimestamp = Math.floor(e.timeStamp);
32
+ var isDoubleTap = this.lastTap + this.tapGesture.interval > tapTimestamp;
33
+ if (!this.tapGesture.enabled && !this.doubleTapGesture.enabled) {
34
+ return this.resetTaps();
35
+ }
36
+ this.tapCount++;
37
+ if (isDoubleTap && this.doubleTapGesture.enabled) {
38
+ this.emitTaps();
39
+ }
40
+ else if (!isDoubleTap) {
41
+ this.tapTimeout = setTimeout(function () { return _this.emitTaps(); }, this.tapGesture.interval);
42
+ }
43
+ this.lastTap = tapTimestamp;
44
+ };
45
+ TapDirective.prototype.emitTaps = function () {
46
+ if (this.tapCount === 1 && this.tapGesture.enabled) {
47
+ this.tap.emit();
48
+ }
49
+ else if (this.tapCount === 2 && this.doubleTapGesture.enabled) {
50
+ this.doubleTap.emit();
51
+ }
52
+ this.resetTaps();
53
+ };
54
+ TapDirective.prototype.resetTaps = function () {
55
+ clearTimeout(this.tapTimeout); // clear the old timeout
56
+ this.tapCount = 0;
57
+ this.tapTimeout = null;
58
+ this.lastTap = 0;
59
+ };
60
+ TapDirective.ɵfac = function TapDirective_Factory(t) { return new (t || TapDirective)(); };
61
+ TapDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: TapDirective, selectors: [["", "appTap", ""]], hostBindings: function TapDirective_HostBindings(rf, ctx) { if (rf & 1) {
62
+ i0.ɵɵlistener("click", function TapDirective_click_HostBindingHandler($event) { return ctx.handleTaps($event); });
63
+ } }, outputs: { tap: "tap", doubleTap: "doubleTap" } });
64
+ return TapDirective;
65
+ }());
66
+ export { TapDirective };
67
+ (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TapDirective, [{
68
+ type: Directive,
69
+ args: [{
70
+ selector: '[appTap]'
71
+ }]
72
+ }], function () { return []; }, { tap: [{
73
+ type: Output
74
+ }], doubleTap: [{
75
+ type: Output
76
+ }], handleTaps: [{
77
+ type: HostListener,
78
+ args: ['click', ['$event']]
79
+ }] }); })();
80
+ //# sourceMappingURL=tap.directive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tap.directive.js","sourceRoot":"","sources":["../../src/tap/tap.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAU,MAAM,EAAE,MAAM,eAAe,CAAC;;AAEtF;;;GAGG;AAEH;IAqBI;QAhBU,QAAG,GAAG,IAAI,YAAY,EAAE,CAAC;QACzB,cAAS,GAAG,IAAI,YAAY,EAAE,CAAC;QACzC,YAAO,GAAG,CAAC,CAAC;QACZ,aAAQ,GAAG,CAAC,CAAC;QACb,eAAU,GAAQ,IAAI,CAAC;QACvB,eAAU,GAAG;YACT,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,GAAG;SAChB,CAAC;QACF,qBAAgB,GAAG;YACf,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,GAAG;SAChB,CAAC;IAEc,CAAC;IAEjB,+BAAQ,GAAR;QACI,IAAI,CAAC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAC/B,IAAI,CAAC,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC;IACzC,CAAC;IAGD,iCAAU,GADV,UACW,CAAyB;QADpC,iBAcC;QAZG,IAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAM,WAAW,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,GAAG,YAAY,CAAC;QAC3E,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE;YAC5D,OAAO,IAAI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AAC,QAAQ,CAAC","sourcesContent":["import { Directive, EventEmitter, HostListener, OnInit, Output } from '@angular/core';\n\n/**\n * Gerencia tap e doubleTap\n * @author Starley Cazorla\n */\n\n@Directive({\n selector: '[appTap]'\n})\nexport class TapDirective implements OnInit {\n\n @Output() tap = new EventEmitter();\n @Output() doubleTap = new EventEmitter();\n lastTap = 0;\n tapCount = 0;\n tapTimeout: any = null;\n tapGesture = {\n name: 'tap',\n enabled: false,\n interval: 250,\n };\n doubleTapGesture = {\n name: 'doubleTap',\n enabled: false,\n interval: 300,\n };\n\n constructor() { }\n\n ngOnInit(): void {\n this.tapGesture.enabled = true;\n this.doubleTapGesture.enabled = true;\n }\n\n @HostListener('click', ['$event'])\n handleTaps(e: { timeStamp: number; }) {\n const tapTimestamp = Math.floor(e.timeStamp);\n const isDoubleTap = this.lastTap + this.tapGesture.interval > tapTimestamp;\n if (!this.tapGesture.enabled && !this.doubleTapGesture.enabled) {\n return this.resetTaps();\n }\n this.tapCount++;\n if (isDoubleTap && this.doubleTapGesture.enabled) {\n this.emitTaps();\n } else if (!isDoubleTap) {\n this.tapTimeout = setTimeout(() => this.emitTaps(), this.tapGesture.interval);\n }\n this.lastTap = tapTimestamp;\n }\n\n private emitTaps() {\n if (this.tapCount === 1 && this.tapGesture.enabled) {\n this.tap.emit();\n } else if (this.tapCount === 2 && this.doubleTapGesture.enabled) {\n this.doubleTap.emit();\n }\n this.resetTaps();\n }\n\n private resetTaps() {\n clearTimeout(this.tapTimeout); // clear the old timeout\n this.tapCount = 0;\n this.tapTimeout = null;\n this.lastTap = 0;\n }\n\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starley/ion-directives",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Directivas internas para ionic",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -37,9 +37,11 @@
37
37
  },
38
38
  "homepage": "https://github.com/StarleyDev/ion-directives#readme",
39
39
  "devDependencies": {
40
- "@angular/common": "^15.1.1",
41
- "@angular/core": "^15.1.1",
42
- "@angular/forms": "^15.1.1",
40
+ "@angular/common": "^15.1.2",
41
+ "@angular/compiler": "^15.1.2",
42
+ "@angular/compiler-cli": "^15.1.2",
43
+ "@angular/core": "^15.1.2",
44
+ "@angular/forms": "^15.1.2",
43
45
  "@types/node": "^18.11.18",
44
46
  "nodemon": "^2.0.20",
45
47
  "ts-node": "^10.9.1",