@starley/ion-directives 1.1.21 → 1.2.0
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/package.json +9 -5
- package/gitignore +0 -3
- package/index.ts +0 -4
- package/lib/directive.module.d.ts +0 -6
- package/lib/directive.module.js +0 -42
- package/lib/input-mask/input-mask.directive.d.ts +0 -19
- package/lib/input-mask/input-mask.directive.js +0 -78
- package/lib/press-hold/press-hold.directive.d.ts +0 -25
- package/lib/press-hold/press-hold.directive.js +0 -77
- package/lib/tap/tap.directive.d.ts +0 -29
- package/lib/tap/tap.directive.js +0 -85
- package/src/directive.module.ts +0 -29
- package/src/input-mask/input-mask.directive.ts +0 -68
- package/src/press-hold/press-hold.directive.ts +0 -66
- package/src/tap/tap.directive.ts +0 -70
- package/tsconfig.json +0 -12
- package/tslint.json +0 -17
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starley/ion-directives",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Directivas internas para ionic",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"typings": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
11
|
+
"ngc": "ngc",
|
|
12
|
+
"build": "rm -rf dist && npm run ngc",
|
|
13
|
+
"publishPackage": "npm run build && npm publish"
|
|
10
14
|
},
|
|
11
15
|
"peerDependencies": {
|
|
12
16
|
"@angular/common": "^15.1.1 || ^11.2.4 || ~10.0.0",
|
package/gitignore
DELETED
package/index.ts
DELETED
package/lib/directive.module.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.DirectivesModule = void 0;
|
|
10
|
-
var core_1 = require("@angular/core");
|
|
11
|
-
var press_hold_directive_1 = require("./press-hold/press-hold.directive");
|
|
12
|
-
var tap_directive_1 = require("./tap/tap.directive");
|
|
13
|
-
var input_mask_directive_1 = require("./input-mask/input-mask.directive");
|
|
14
|
-
var common_1 = require("@angular/common");
|
|
15
|
-
/**
|
|
16
|
-
* Gerencia precionamento de enventos
|
|
17
|
-
* @author Starley Cazorla
|
|
18
|
-
*/
|
|
19
|
-
var DirectivesModule = /** @class */ (function () {
|
|
20
|
-
function DirectivesModule() {
|
|
21
|
-
}
|
|
22
|
-
DirectivesModule = __decorate([
|
|
23
|
-
(0, core_1.NgModule)({
|
|
24
|
-
declarations: [
|
|
25
|
-
press_hold_directive_1.PressHoldDirective,
|
|
26
|
-
tap_directive_1.TapDirective,
|
|
27
|
-
input_mask_directive_1.IonInputMaskDirective
|
|
28
|
-
],
|
|
29
|
-
imports: [
|
|
30
|
-
common_1.CommonModule
|
|
31
|
-
],
|
|
32
|
-
exports: [
|
|
33
|
-
press_hold_directive_1.PressHoldDirective,
|
|
34
|
-
tap_directive_1.TapDirective,
|
|
35
|
-
input_mask_directive_1.IonInputMaskDirective
|
|
36
|
-
],
|
|
37
|
-
schemas: [core_1.CUSTOM_ELEMENTS_SCHEMA, core_1.NO_ERRORS_SCHEMA]
|
|
38
|
-
})
|
|
39
|
-
], DirectivesModule);
|
|
40
|
-
return DirectivesModule;
|
|
41
|
-
}());
|
|
42
|
-
exports.DirectivesModule = DirectivesModule;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { NgModel } from "@angular/forms";
|
|
2
|
-
/**
|
|
3
|
-
* Responsavel pelo mascaramento de inputs
|
|
4
|
-
*/
|
|
5
|
-
export declare class IonInputMaskDirective {
|
|
6
|
-
model: NgModel;
|
|
7
|
-
pattern: string;
|
|
8
|
-
/**
|
|
9
|
-
* Construtor
|
|
10
|
-
* @param {NgModel} model
|
|
11
|
-
* @param {string} pattern
|
|
12
|
-
*/
|
|
13
|
-
constructor(model: NgModel, pattern: string);
|
|
14
|
-
/**
|
|
15
|
-
* Listener para mudança de valor do input
|
|
16
|
-
* @param event
|
|
17
|
-
*/
|
|
18
|
-
onKeyDown(event: any): boolean;
|
|
19
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.IonInputMaskDirective = void 0;
|
|
13
|
-
var core_1 = require("@angular/core");
|
|
14
|
-
var forms_1 = require("@angular/forms");
|
|
15
|
-
/**
|
|
16
|
-
* Responsavel pelo mascaramento de inputs
|
|
17
|
-
*/
|
|
18
|
-
var IonInputMaskDirective = /** @class */ (function () {
|
|
19
|
-
/**
|
|
20
|
-
* Construtor
|
|
21
|
-
* @param {NgModel} model
|
|
22
|
-
* @param {string} pattern
|
|
23
|
-
*/
|
|
24
|
-
function IonInputMaskDirective(model, pattern) {
|
|
25
|
-
this.model = model;
|
|
26
|
-
this.pattern = pattern;
|
|
27
|
-
console.log('Inicou inputMask');
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Listener para mudança de valor do input
|
|
31
|
-
* @param event
|
|
32
|
-
*/
|
|
33
|
-
IonInputMaskDirective.prototype.onKeyDown = function (event) {
|
|
34
|
-
var value = event.target.value, pattern = this.pattern;
|
|
35
|
-
if (event.keyIdentifier === 'U+0008' || event.keyCode === 8 || event.key === 'Backspace') {
|
|
36
|
-
if (value.length) { //prevent fatal exception when backspacing empty value in progressive web app
|
|
37
|
-
//remove all trailing formatting then delete character
|
|
38
|
-
while (pattern[value.length] && pattern[value.length] !== '*') {
|
|
39
|
-
value = value.substring(0, value.length - 1);
|
|
40
|
-
}
|
|
41
|
-
//remove all leading formatting to restore placeholder
|
|
42
|
-
if (pattern.substring(0, value.length).indexOf('*') < 0) {
|
|
43
|
-
value = value.substring(0, value.length - 1);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
var maskIndex = value.length;
|
|
49
|
-
var formatted = '';
|
|
50
|
-
formatted += value;
|
|
51
|
-
if (maskIndex < pattern.length) {
|
|
52
|
-
//apply trailing formatting
|
|
53
|
-
while (pattern[maskIndex] !== '*') {
|
|
54
|
-
formatted += pattern[maskIndex];
|
|
55
|
-
maskIndex++;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
value = formatted;
|
|
59
|
-
}
|
|
60
|
-
event.target.value = value;
|
|
61
|
-
if (this.model) {
|
|
62
|
-
this.model.update.emit(value);
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
};
|
|
66
|
-
IonInputMaskDirective = __decorate([
|
|
67
|
-
(0, core_1.Directive)({
|
|
68
|
-
selector: '[appMask]',
|
|
69
|
-
host: {
|
|
70
|
-
'(keydown)': 'onKeyDown($event)'
|
|
71
|
-
},
|
|
72
|
-
providers: [forms_1.NgModel]
|
|
73
|
-
}),
|
|
74
|
-
__param(1, (0, core_1.Attribute)('appMask'))
|
|
75
|
-
], IonInputMaskDirective);
|
|
76
|
-
return IonInputMaskDirective;
|
|
77
|
-
}());
|
|
78
|
-
exports.IonInputMaskDirective = IonInputMaskDirective;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { EventEmitter, OnInit } from '@angular/core';
|
|
2
|
-
/**
|
|
3
|
-
* Gerencia pressHold
|
|
4
|
-
* @author Starley Cazorla
|
|
5
|
-
*/
|
|
6
|
-
export declare class PressHoldDirective implements OnInit {
|
|
7
|
-
press: EventEmitter<any>;
|
|
8
|
-
pressGesture: {
|
|
9
|
-
name: string;
|
|
10
|
-
enabled: boolean;
|
|
11
|
-
interval: number;
|
|
12
|
-
};
|
|
13
|
-
pressTimeout: any;
|
|
14
|
-
isPressing: boolean;
|
|
15
|
-
lastTap: number;
|
|
16
|
-
tapCount: number;
|
|
17
|
-
tapTimeout: any;
|
|
18
|
-
constructor();
|
|
19
|
-
ngOnInit(): void;
|
|
20
|
-
onPress(event: {
|
|
21
|
-
type: any;
|
|
22
|
-
}): void;
|
|
23
|
-
private handlePressing;
|
|
24
|
-
private resetTaps;
|
|
25
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.PressHoldDirective = void 0;
|
|
10
|
-
var core_1 = require("@angular/core");
|
|
11
|
-
/**
|
|
12
|
-
* Gerencia pressHold
|
|
13
|
-
* @author Starley Cazorla
|
|
14
|
-
*/
|
|
15
|
-
var PressHoldDirective = /** @class */ (function () {
|
|
16
|
-
function PressHoldDirective() {
|
|
17
|
-
this.press = new core_1.EventEmitter();
|
|
18
|
-
this.pressGesture = {
|
|
19
|
-
name: 'press',
|
|
20
|
-
enabled: false,
|
|
21
|
-
interval: 350
|
|
22
|
-
};
|
|
23
|
-
this.pressTimeout = null;
|
|
24
|
-
this.isPressing = false;
|
|
25
|
-
this.lastTap = 0;
|
|
26
|
-
this.tapCount = 0;
|
|
27
|
-
this.tapTimeout = null;
|
|
28
|
-
console.log('Inicou appPressHold');
|
|
29
|
-
}
|
|
30
|
-
PressHoldDirective.prototype.ngOnInit = function () {
|
|
31
|
-
this.pressGesture.enabled = true;
|
|
32
|
-
};
|
|
33
|
-
PressHoldDirective.prototype.onPress = function (event) {
|
|
34
|
-
if (!this.pressGesture.enabled) {
|
|
35
|
-
return;
|
|
36
|
-
} // Press is not enabled, don't do anything.
|
|
37
|
-
this.handlePressing(event.type);
|
|
38
|
-
};
|
|
39
|
-
PressHoldDirective.prototype.handlePressing = function (type) {
|
|
40
|
-
var _this = this;
|
|
41
|
-
if (type == 'touchstart') {
|
|
42
|
-
this.pressTimeout = setTimeout(function () {
|
|
43
|
-
_this.isPressing = true;
|
|
44
|
-
}, this.pressGesture.interval); // Considered a press if it's longer than interval (default: 251).
|
|
45
|
-
}
|
|
46
|
-
else if (type == 'touchend') {
|
|
47
|
-
clearTimeout(this.pressTimeout);
|
|
48
|
-
if (this.isPressing) {
|
|
49
|
-
this.press.emit('end');
|
|
50
|
-
this.resetTaps(); // Just incase this gets passed as a tap event too.
|
|
51
|
-
}
|
|
52
|
-
// Clicks have a natural delay of 300ms, so we have to account for that, before resetting isPressing.
|
|
53
|
-
// Otherwise a tap event is emitted.
|
|
54
|
-
setTimeout(function () { return _this.isPressing = false; }, 50);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
PressHoldDirective.prototype.resetTaps = function () {
|
|
58
|
-
clearTimeout(this.tapTimeout); // clear the old timeout
|
|
59
|
-
this.tapCount = 0;
|
|
60
|
-
this.tapTimeout = null;
|
|
61
|
-
this.lastTap = 0;
|
|
62
|
-
};
|
|
63
|
-
__decorate([
|
|
64
|
-
(0, core_1.Output)()
|
|
65
|
-
], PressHoldDirective.prototype, "press", void 0);
|
|
66
|
-
__decorate([
|
|
67
|
-
(0, core_1.HostListener)('touchstart', ['$event']),
|
|
68
|
-
(0, core_1.HostListener)('touchend', ['$event'])
|
|
69
|
-
], PressHoldDirective.prototype, "onPress", null);
|
|
70
|
-
PressHoldDirective = __decorate([
|
|
71
|
-
(0, core_1.Directive)({
|
|
72
|
-
selector: '[appPressHold]'
|
|
73
|
-
})
|
|
74
|
-
], PressHoldDirective);
|
|
75
|
-
return PressHoldDirective;
|
|
76
|
-
}());
|
|
77
|
-
exports.PressHoldDirective = PressHoldDirective;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { EventEmitter, OnInit } from '@angular/core';
|
|
2
|
-
/**
|
|
3
|
-
* Gerencia tap e doubleTap
|
|
4
|
-
* @author Starley Cazorla
|
|
5
|
-
*/
|
|
6
|
-
export declare class TapDirective implements OnInit {
|
|
7
|
-
tap: EventEmitter<any>;
|
|
8
|
-
doubleTap: EventEmitter<any>;
|
|
9
|
-
lastTap: number;
|
|
10
|
-
tapCount: number;
|
|
11
|
-
tapTimeout: any;
|
|
12
|
-
tapGesture: {
|
|
13
|
-
name: string;
|
|
14
|
-
enabled: boolean;
|
|
15
|
-
interval: number;
|
|
16
|
-
};
|
|
17
|
-
doubleTapGesture: {
|
|
18
|
-
name: string;
|
|
19
|
-
enabled: boolean;
|
|
20
|
-
interval: number;
|
|
21
|
-
};
|
|
22
|
-
constructor();
|
|
23
|
-
ngOnInit(): void;
|
|
24
|
-
handleTaps(e: {
|
|
25
|
-
timeStamp: number;
|
|
26
|
-
}): void;
|
|
27
|
-
private emitTaps;
|
|
28
|
-
private resetTaps;
|
|
29
|
-
}
|
package/lib/tap/tap.directive.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.TapDirective = void 0;
|
|
10
|
-
var core_1 = require("@angular/core");
|
|
11
|
-
/**
|
|
12
|
-
* Gerencia tap e doubleTap
|
|
13
|
-
* @author Starley Cazorla
|
|
14
|
-
*/
|
|
15
|
-
var TapDirective = /** @class */ (function () {
|
|
16
|
-
function TapDirective() {
|
|
17
|
-
this.tap = new core_1.EventEmitter();
|
|
18
|
-
this.doubleTap = new core_1.EventEmitter();
|
|
19
|
-
this.lastTap = 0;
|
|
20
|
-
this.tapCount = 0;
|
|
21
|
-
this.tapTimeout = null;
|
|
22
|
-
this.tapGesture = {
|
|
23
|
-
name: 'tap',
|
|
24
|
-
enabled: false,
|
|
25
|
-
interval: 250,
|
|
26
|
-
};
|
|
27
|
-
this.doubleTapGesture = {
|
|
28
|
-
name: 'doubleTap',
|
|
29
|
-
enabled: false,
|
|
30
|
-
interval: 300,
|
|
31
|
-
};
|
|
32
|
-
console.log('Inicou appTap');
|
|
33
|
-
}
|
|
34
|
-
TapDirective.prototype.ngOnInit = function () {
|
|
35
|
-
this.tapGesture.enabled = true;
|
|
36
|
-
this.doubleTapGesture.enabled = true;
|
|
37
|
-
};
|
|
38
|
-
TapDirective.prototype.handleTaps = function (e) {
|
|
39
|
-
var _this = this;
|
|
40
|
-
var tapTimestamp = Math.floor(e.timeStamp);
|
|
41
|
-
var isDoubleTap = this.lastTap + this.tapGesture.interval > tapTimestamp;
|
|
42
|
-
if (!this.tapGesture.enabled && !this.doubleTapGesture.enabled) {
|
|
43
|
-
return this.resetTaps();
|
|
44
|
-
}
|
|
45
|
-
this.tapCount++;
|
|
46
|
-
if (isDoubleTap && this.doubleTapGesture.enabled) {
|
|
47
|
-
this.emitTaps();
|
|
48
|
-
}
|
|
49
|
-
else if (!isDoubleTap) {
|
|
50
|
-
this.tapTimeout = setTimeout(function () { return _this.emitTaps(); }, this.tapGesture.interval);
|
|
51
|
-
}
|
|
52
|
-
this.lastTap = tapTimestamp;
|
|
53
|
-
};
|
|
54
|
-
TapDirective.prototype.emitTaps = function () {
|
|
55
|
-
if (this.tapCount === 1 && this.tapGesture.enabled) {
|
|
56
|
-
this.tap.emit();
|
|
57
|
-
}
|
|
58
|
-
else if (this.tapCount === 2 && this.doubleTapGesture.enabled) {
|
|
59
|
-
this.doubleTap.emit();
|
|
60
|
-
}
|
|
61
|
-
this.resetTaps();
|
|
62
|
-
};
|
|
63
|
-
TapDirective.prototype.resetTaps = function () {
|
|
64
|
-
clearTimeout(this.tapTimeout); // clear the old timeout
|
|
65
|
-
this.tapCount = 0;
|
|
66
|
-
this.tapTimeout = null;
|
|
67
|
-
this.lastTap = 0;
|
|
68
|
-
};
|
|
69
|
-
__decorate([
|
|
70
|
-
(0, core_1.Output)()
|
|
71
|
-
], TapDirective.prototype, "tap", void 0);
|
|
72
|
-
__decorate([
|
|
73
|
-
(0, core_1.Output)()
|
|
74
|
-
], TapDirective.prototype, "doubleTap", void 0);
|
|
75
|
-
__decorate([
|
|
76
|
-
(0, core_1.HostListener)('click', ['$event'])
|
|
77
|
-
], TapDirective.prototype, "handleTaps", null);
|
|
78
|
-
TapDirective = __decorate([
|
|
79
|
-
(0, core_1.Directive)({
|
|
80
|
-
selector: '[appTap]'
|
|
81
|
-
})
|
|
82
|
-
], TapDirective);
|
|
83
|
-
return TapDirective;
|
|
84
|
-
}());
|
|
85
|
-
exports.TapDirective = TapDirective;
|
package/src/directive.module.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Gerencia precionamento de enventos
|
|
9
|
-
* @author Starley Cazorla
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
@NgModule({
|
|
13
|
-
declarations: [
|
|
14
|
-
PressHoldDirective,
|
|
15
|
-
TapDirective,
|
|
16
|
-
IonInputMaskDirective
|
|
17
|
-
],
|
|
18
|
-
imports: [
|
|
19
|
-
CommonModule
|
|
20
|
-
],
|
|
21
|
-
exports: [
|
|
22
|
-
PressHoldDirective,
|
|
23
|
-
TapDirective,
|
|
24
|
-
IonInputMaskDirective
|
|
25
|
-
],
|
|
26
|
-
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
export class DirectivesModule { }
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Attribute, Directive } from '@angular/core';
|
|
2
|
-
import { NgModel } from "@angular/forms";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Responsavel pelo mascaramento de inputs
|
|
6
|
-
*/
|
|
7
|
-
@Directive({
|
|
8
|
-
selector: '[appMask]',
|
|
9
|
-
host: {
|
|
10
|
-
'(keydown)': 'onKeyDown($event)'
|
|
11
|
-
},
|
|
12
|
-
providers: [NgModel]
|
|
13
|
-
})
|
|
14
|
-
export class IonInputMaskDirective {
|
|
15
|
-
|
|
16
|
-
pattern: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Construtor
|
|
20
|
-
* @param {NgModel} model
|
|
21
|
-
* @param {string} pattern
|
|
22
|
-
*/
|
|
23
|
-
constructor(public model: NgModel,
|
|
24
|
-
@Attribute('appMask') pattern: string) {
|
|
25
|
-
this.pattern = pattern;
|
|
26
|
-
|
|
27
|
-
console.log('Inicou inputMask');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Listener para mudança de valor do input
|
|
32
|
-
* @param event
|
|
33
|
-
*/
|
|
34
|
-
onKeyDown(event: any) {
|
|
35
|
-
let value = event.target.value,
|
|
36
|
-
pattern = this.pattern;
|
|
37
|
-
if (event.keyIdentifier === 'U+0008' || event.keyCode === 8 || event.key === 'Backspace') {
|
|
38
|
-
if (value.length) { //prevent fatal exception when backspacing empty value in progressive web app
|
|
39
|
-
//remove all trailing formatting then delete character
|
|
40
|
-
while (pattern[value.length] && pattern[value.length] !== '*') {
|
|
41
|
-
value = value.substring(0, value.length - 1);
|
|
42
|
-
}
|
|
43
|
-
//remove all leading formatting to restore placeholder
|
|
44
|
-
if (pattern.substring(0, value.length).indexOf('*') < 0) {
|
|
45
|
-
value = value.substring(0, value.length - 1);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
let maskIndex = value.length;
|
|
50
|
-
let formatted = '';
|
|
51
|
-
formatted += value;
|
|
52
|
-
if (maskIndex < pattern.length) {
|
|
53
|
-
//apply trailing formatting
|
|
54
|
-
while (pattern[maskIndex] !== '*') {
|
|
55
|
-
formatted += pattern[maskIndex];
|
|
56
|
-
maskIndex++;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
value = formatted;
|
|
60
|
-
}
|
|
61
|
-
event.target.value = value;
|
|
62
|
-
if (this.model) {
|
|
63
|
-
this.model.update.emit(value);
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Directive, EventEmitter, HostListener, OnInit, Output } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Gerencia pressHold
|
|
5
|
-
* @author Starley Cazorla
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
@Directive({
|
|
9
|
-
selector: '[appPressHold]'
|
|
10
|
-
})
|
|
11
|
-
export class PressHoldDirective implements OnInit {
|
|
12
|
-
|
|
13
|
-
@Output() press = new EventEmitter();
|
|
14
|
-
pressGesture = {
|
|
15
|
-
name: 'press',
|
|
16
|
-
enabled: false,
|
|
17
|
-
interval: 350
|
|
18
|
-
};
|
|
19
|
-
pressTimeout: any = null;
|
|
20
|
-
isPressing: boolean = false;
|
|
21
|
-
lastTap = 0;
|
|
22
|
-
tapCount = 0;
|
|
23
|
-
tapTimeout: any = null;
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
console.log('Inicou appPressHold');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
ngOnInit(): void {
|
|
30
|
-
this.pressGesture.enabled = true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@HostListener('touchstart', ['$event'])
|
|
34
|
-
@HostListener('touchend', ['$event'])
|
|
35
|
-
onPress(event: { type: any; }) {
|
|
36
|
-
if (!this.pressGesture.enabled) {
|
|
37
|
-
return;
|
|
38
|
-
} // Press is not enabled, don't do anything.
|
|
39
|
-
this.handlePressing(event.type);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private handlePressing(type: string) { // touchend or touchstart
|
|
43
|
-
if (type == 'touchstart') {
|
|
44
|
-
this.pressTimeout = setTimeout(() => {
|
|
45
|
-
this.isPressing = true;
|
|
46
|
-
}, this.pressGesture.interval); // Considered a press if it's longer than interval (default: 251).
|
|
47
|
-
} else if (type == 'touchend') {
|
|
48
|
-
clearTimeout(this.pressTimeout);
|
|
49
|
-
if (this.isPressing) {
|
|
50
|
-
this.press.emit('end');
|
|
51
|
-
this.resetTaps(); // Just incase this gets passed as a tap event too.
|
|
52
|
-
}
|
|
53
|
-
// Clicks have a natural delay of 300ms, so we have to account for that, before resetting isPressing.
|
|
54
|
-
// Otherwise a tap event is emitted.
|
|
55
|
-
setTimeout(() => this.isPressing = false, 50);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private resetTaps() {
|
|
60
|
-
clearTimeout(this.tapTimeout); // clear the old timeout
|
|
61
|
-
this.tapCount = 0;
|
|
62
|
-
this.tapTimeout = null;
|
|
63
|
-
this.lastTap = 0;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
package/src/tap/tap.directive.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Directive, EventEmitter, HostListener, OnInit, Output } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Gerencia tap e doubleTap
|
|
5
|
-
* @author Starley Cazorla
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
@Directive({
|
|
9
|
-
selector: '[appTap]'
|
|
10
|
-
})
|
|
11
|
-
export class TapDirective implements OnInit {
|
|
12
|
-
|
|
13
|
-
@Output() tap = new EventEmitter();
|
|
14
|
-
@Output() doubleTap = new EventEmitter();
|
|
15
|
-
lastTap = 0;
|
|
16
|
-
tapCount = 0;
|
|
17
|
-
tapTimeout: any = null;
|
|
18
|
-
tapGesture = {
|
|
19
|
-
name: 'tap',
|
|
20
|
-
enabled: false,
|
|
21
|
-
interval: 250,
|
|
22
|
-
};
|
|
23
|
-
doubleTapGesture = {
|
|
24
|
-
name: 'doubleTap',
|
|
25
|
-
enabled: false,
|
|
26
|
-
interval: 300,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
constructor() {
|
|
30
|
-
console.log('Inicou appTap');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
ngOnInit(): void {
|
|
34
|
-
this.tapGesture.enabled = true;
|
|
35
|
-
this.doubleTapGesture.enabled = true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@HostListener('click', ['$event'])
|
|
39
|
-
handleTaps(e: { timeStamp: number; }) {
|
|
40
|
-
const tapTimestamp = Math.floor(e.timeStamp);
|
|
41
|
-
const isDoubleTap = this.lastTap + this.tapGesture.interval > tapTimestamp;
|
|
42
|
-
if (!this.tapGesture.enabled && !this.doubleTapGesture.enabled) {
|
|
43
|
-
return this.resetTaps();
|
|
44
|
-
}
|
|
45
|
-
this.tapCount++;
|
|
46
|
-
if (isDoubleTap && this.doubleTapGesture.enabled) {
|
|
47
|
-
this.emitTaps();
|
|
48
|
-
} else if (!isDoubleTap) {
|
|
49
|
-
this.tapTimeout = setTimeout(() => this.emitTaps(), this.tapGesture.interval);
|
|
50
|
-
}
|
|
51
|
-
this.lastTap = tapTimestamp;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private emitTaps() {
|
|
55
|
-
if (this.tapCount === 1 && this.tapGesture.enabled) {
|
|
56
|
-
this.tap.emit();
|
|
57
|
-
} else if (this.tapCount === 2 && this.doubleTapGesture.enabled) {
|
|
58
|
-
this.doubleTap.emit();
|
|
59
|
-
}
|
|
60
|
-
this.resetTaps();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private resetTaps() {
|
|
64
|
-
clearTimeout(this.tapTimeout); // clear the old timeout
|
|
65
|
-
this.tapCount = 0;
|
|
66
|
-
this.tapTimeout = null;
|
|
67
|
-
this.lastTap = 0;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
package/tsconfig.json
DELETED
package/tslint.json
DELETED