@starley/ion-directives 1.1.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/dist/cjs/directives/directive.module.js +34 -0
- package/dist/cjs/directives/directive.module.js.map +1 -0
- package/dist/cjs/directives/input-mask/input-mask.directive.js +72 -0
- package/dist/cjs/directives/input-mask/input-mask.directive.js.map +1 -0
- package/dist/cjs/directives/press-hold/press-hold.directive.js +71 -0
- package/dist/cjs/directives/press-hold/press-hold.directive.js.map +1 -0
- package/dist/cjs/directives/tap/tap.directive.js +79 -0
- package/dist/cjs/directives/tap/tap.directive.js.map +1 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/directives/directive.module.js +31 -0
- package/dist/directives/directive.module.js.map +1 -0
- package/dist/directives/input-mask/input-mask.directive.js +69 -0
- package/dist/directives/input-mask/input-mask.directive.js.map +1 -0
- package/dist/directives/press-hold/press-hold.directive.js +68 -0
- package/dist/directives/press-hold/press-hold.directive.js.map +1 -0
- package/dist/directives/tap/tap.directive.js +76 -0
- package/dist/directives/tap/tap.directive.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
- package/src/directives/directive.module.ts +28 -0
- package/src/directives/input-mask/input-mask.directive.ts +70 -0
- package/src/directives/press-hold/press-hold.directive.ts +66 -0
- package/src/directives/tap/tap.directive.ts +70 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +30 -0
- package/tslint.json +17 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DirectivesModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@angular/core");
|
|
6
|
+
const common_1 = require("@angular/common");
|
|
7
|
+
const press_hold_directive_1 = require("./press-hold/press-hold.directive");
|
|
8
|
+
const tap_directive_1 = require("./tap/tap.directive");
|
|
9
|
+
const input_mask_directive_1 = require("./input-mask/input-mask.directive");
|
|
10
|
+
/**
|
|
11
|
+
* Gerencia precionamento de enventos
|
|
12
|
+
* @author Starley Cazorla
|
|
13
|
+
*/
|
|
14
|
+
let DirectivesModule = class DirectivesModule {
|
|
15
|
+
};
|
|
16
|
+
DirectivesModule = tslib_1.__decorate([
|
|
17
|
+
(0, core_1.NgModule)({
|
|
18
|
+
declarations: [
|
|
19
|
+
press_hold_directive_1.PressHoldDirective,
|
|
20
|
+
tap_directive_1.TapDirective,
|
|
21
|
+
input_mask_directive_1.IonInputMaskDirective
|
|
22
|
+
],
|
|
23
|
+
imports: [
|
|
24
|
+
common_1.CommonModule
|
|
25
|
+
],
|
|
26
|
+
exports: [
|
|
27
|
+
press_hold_directive_1.PressHoldDirective,
|
|
28
|
+
tap_directive_1.TapDirective,
|
|
29
|
+
input_mask_directive_1.IonInputMaskDirective
|
|
30
|
+
]
|
|
31
|
+
})
|
|
32
|
+
], DirectivesModule);
|
|
33
|
+
exports.DirectivesModule = DirectivesModule;
|
|
34
|
+
//# sourceMappingURL=directive.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directive.module.js","sourceRoot":"","sources":["../../../src/directives/directive.module.ts"],"names":[],"mappings":";;;;AAAA,wCAAyC;AACzC,4CAA+C;AAC/C,4EAAuE;AACvE,uDAAmD;AACnD,4EAA0E;AAE1E;;;GAGG;AAkBI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAI,CAAA;AAApB,gBAAgB;IAhB5B,IAAA,eAAQ,EAAC;QACN,YAAY,EAAE;YACV,yCAAkB;YAClB,4BAAY;YACZ,4CAAqB;SACxB;QACD,OAAO,EAAE;YACL,qBAAY;SACf;QACD,OAAO,EAAE;YACL,yCAAkB;YAClB,4BAAY;YACZ,4CAAqB;SACxB;KAEJ,CAAC;GACW,gBAAgB,CAAI;AAApB,4CAAgB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IonInputMaskDirective = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable @angular-eslint/no-host-metadata-property */
|
|
6
|
+
/* eslint-disable @angular-eslint/directive-selector */
|
|
7
|
+
const core_1 = require("@angular/core");
|
|
8
|
+
const forms_1 = require("@angular/forms");
|
|
9
|
+
/**
|
|
10
|
+
* Responsavel pelo mascaramento de inputs
|
|
11
|
+
*/
|
|
12
|
+
let IonInputMaskDirective = class IonInputMaskDirective {
|
|
13
|
+
/**
|
|
14
|
+
* Construtor
|
|
15
|
+
* @param {NgModel} model
|
|
16
|
+
* @param {string} pattern
|
|
17
|
+
*/
|
|
18
|
+
constructor(model, pattern) {
|
|
19
|
+
this.model = model;
|
|
20
|
+
this.pattern = pattern;
|
|
21
|
+
console.log('Inicou inputMask');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Listener para mudança de valor do input
|
|
25
|
+
* @param event
|
|
26
|
+
*/
|
|
27
|
+
onKeyDown(event) {
|
|
28
|
+
let value = event.target.value, pattern = this.pattern;
|
|
29
|
+
if (event.keyIdentifier === 'U+0008' || event.keyCode === 8 || event.key === 'Backspace') {
|
|
30
|
+
if (value.length) { //prevent fatal exception when backspacing empty value in progressive web app
|
|
31
|
+
//remove all trailing formatting then delete character
|
|
32
|
+
while (pattern[value.length] && pattern[value.length] !== '*') {
|
|
33
|
+
value = value.substring(0, value.length - 1);
|
|
34
|
+
}
|
|
35
|
+
//remove all leading formatting to restore placeholder
|
|
36
|
+
if (pattern.substring(0, value.length).indexOf('*') < 0) {
|
|
37
|
+
value = value.substring(0, value.length - 1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
let maskIndex = value.length;
|
|
43
|
+
let formatted = '';
|
|
44
|
+
formatted += value;
|
|
45
|
+
if (maskIndex < pattern.length) {
|
|
46
|
+
//apply trailing formatting
|
|
47
|
+
while (pattern[maskIndex] !== '*') {
|
|
48
|
+
formatted += pattern[maskIndex];
|
|
49
|
+
maskIndex++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
value = formatted;
|
|
53
|
+
}
|
|
54
|
+
event.target.value = value;
|
|
55
|
+
if (this.model) {
|
|
56
|
+
this.model.update.emit(value);
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
IonInputMaskDirective = tslib_1.__decorate([
|
|
62
|
+
(0, core_1.Directive)({
|
|
63
|
+
selector: '[mask]',
|
|
64
|
+
host: {
|
|
65
|
+
'(keydown)': 'onKeyDown($event)'
|
|
66
|
+
},
|
|
67
|
+
providers: [forms_1.NgModel]
|
|
68
|
+
}),
|
|
69
|
+
tslib_1.__param(1, (0, core_1.Attribute)('mask'))
|
|
70
|
+
], IonInputMaskDirective);
|
|
71
|
+
exports.IonInputMaskDirective = IonInputMaskDirective;
|
|
72
|
+
//# sourceMappingURL=input-mask.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-mask.directive.js","sourceRoot":"","sources":["../../../../src/directives/input-mask/input-mask.directive.ts"],"names":[],"mappings":";;;;AAAA,8DAA8D;AAC9D,uDAAuD;AACvD,wCAAqD;AACrD,0CAAyC;AAEzC;;GAEG;AAQI,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAI9B;;;;OAIG;IACH,YAAmB,KAAc,EACV,OAAe;QADnB,UAAK,GAAL,KAAK,CAAS;QAE7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,KAAU;QAChB,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,EAC1B,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,IA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tDY,qBAAqB;IAPjC,IAAA,gBAAS,EAAC;QACP,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE;YACF,WAAW,EAAE,mBAAmB;SACnC;QACD,SAAS,EAAE,CAAC,eAAO,CAAC;KACvB,CAAC;IAWO,mBAAA,IAAA,gBAAS,EAAC,MAAM,CAAC,CAAA;GAVb,qBAAqB,CAsDjC;AAtDY,sDAAqB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PressHoldDirective = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@angular/core");
|
|
6
|
+
/**
|
|
7
|
+
* Gerencia pressHold
|
|
8
|
+
* @author Starley Cazorla
|
|
9
|
+
*/
|
|
10
|
+
let PressHoldDirective = class PressHoldDirective {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.press = new core_1.EventEmitter();
|
|
13
|
+
this.pressGesture = {
|
|
14
|
+
name: 'press',
|
|
15
|
+
enabled: false,
|
|
16
|
+
interval: 350
|
|
17
|
+
};
|
|
18
|
+
this.pressTimeout = null;
|
|
19
|
+
this.isPressing = false;
|
|
20
|
+
this.lastTap = 0;
|
|
21
|
+
this.tapCount = 0;
|
|
22
|
+
this.tapTimeout = null;
|
|
23
|
+
console.log('Inicou appPressHold');
|
|
24
|
+
}
|
|
25
|
+
ngOnInit() {
|
|
26
|
+
this.pressGesture.enabled = true;
|
|
27
|
+
}
|
|
28
|
+
onPress(event) {
|
|
29
|
+
if (!this.pressGesture.enabled) {
|
|
30
|
+
return;
|
|
31
|
+
} // Press is not enabled, don't do anything.
|
|
32
|
+
this.handlePressing(event.type);
|
|
33
|
+
}
|
|
34
|
+
handlePressing(type) {
|
|
35
|
+
if (type == 'touchstart') {
|
|
36
|
+
this.pressTimeout = setTimeout(() => {
|
|
37
|
+
this.isPressing = true;
|
|
38
|
+
}, this.pressGesture.interval); // Considered a press if it's longer than interval (default: 251).
|
|
39
|
+
}
|
|
40
|
+
else if (type == 'touchend') {
|
|
41
|
+
clearTimeout(this.pressTimeout);
|
|
42
|
+
if (this.isPressing) {
|
|
43
|
+
this.press.emit('end');
|
|
44
|
+
this.resetTaps(); // Just incase this gets passed as a tap event too.
|
|
45
|
+
}
|
|
46
|
+
// Clicks have a natural delay of 300ms, so we have to account for that, before resetting isPressing.
|
|
47
|
+
// Otherwise a tap event is emitted.
|
|
48
|
+
setTimeout(() => this.isPressing = false, 50);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
resetTaps() {
|
|
52
|
+
clearTimeout(this.tapTimeout); // clear the old timeout
|
|
53
|
+
this.tapCount = 0;
|
|
54
|
+
this.tapTimeout = null;
|
|
55
|
+
this.lastTap = 0;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
tslib_1.__decorate([
|
|
59
|
+
(0, core_1.Output)()
|
|
60
|
+
], PressHoldDirective.prototype, "press", void 0);
|
|
61
|
+
tslib_1.__decorate([
|
|
62
|
+
(0, core_1.HostListener)('touchstart', ['$event']),
|
|
63
|
+
(0, core_1.HostListener)('touchend', ['$event'])
|
|
64
|
+
], PressHoldDirective.prototype, "onPress", null);
|
|
65
|
+
PressHoldDirective = tslib_1.__decorate([
|
|
66
|
+
(0, core_1.Directive)({
|
|
67
|
+
selector: '[appPressHold]'
|
|
68
|
+
})
|
|
69
|
+
], PressHoldDirective);
|
|
70
|
+
exports.PressHoldDirective = PressHoldDirective;
|
|
71
|
+
//# sourceMappingURL=press-hold.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"press-hold.directive.js","sourceRoot":"","sources":["../../../../src/directives/press-hold/press-hold.directive.ts"],"names":[],"mappings":";;;;AAAA,wCAAsF;AAEtF;;;GAGG;AAKI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAc3B;QAZU,UAAK,GAAG,IAAI,mBAAY,EAAE,CAAC;QACrC,iBAAY,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,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;CAEJ,CAAA;AArDa;IAAT,IAAA,aAAM,GAAE;iDAA4B;AAsBrC;IAFC,IAAA,mBAAY,EAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAA,mBAAY,EAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,CAAC;iDAMpC;AA7BQ,kBAAkB;IAH9B,IAAA,gBAAS,EAAC;QACP,QAAQ,EAAE,gBAAgB;KAC7B,CAAC;GACW,kBAAkB,CAuD9B;AAvDY,gDAAkB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TapDirective = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@angular/core");
|
|
6
|
+
/**
|
|
7
|
+
* Gerencia tap e doubleTap
|
|
8
|
+
* @author Starley Cazorla
|
|
9
|
+
*/
|
|
10
|
+
let TapDirective = class TapDirective {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.tap = new core_1.EventEmitter();
|
|
13
|
+
this.doubleTap = new core_1.EventEmitter();
|
|
14
|
+
this.lastTap = 0;
|
|
15
|
+
this.tapCount = 0;
|
|
16
|
+
this.tapTimeout = null;
|
|
17
|
+
this.tapGesture = {
|
|
18
|
+
name: 'tap',
|
|
19
|
+
enabled: false,
|
|
20
|
+
interval: 250,
|
|
21
|
+
};
|
|
22
|
+
this.doubleTapGesture = {
|
|
23
|
+
name: 'doubleTap',
|
|
24
|
+
enabled: false,
|
|
25
|
+
interval: 300,
|
|
26
|
+
};
|
|
27
|
+
console.log('Inicou appTap');
|
|
28
|
+
}
|
|
29
|
+
ngOnInit() {
|
|
30
|
+
this.tapGesture.enabled = true;
|
|
31
|
+
this.doubleTapGesture.enabled = true;
|
|
32
|
+
}
|
|
33
|
+
handleTaps(e) {
|
|
34
|
+
const tapTimestamp = Math.floor(e.timeStamp);
|
|
35
|
+
const isDoubleTap = this.lastTap + this.tapGesture.interval > tapTimestamp;
|
|
36
|
+
if (!this.tapGesture.enabled && !this.doubleTapGesture.enabled) {
|
|
37
|
+
return this.resetTaps();
|
|
38
|
+
}
|
|
39
|
+
this.tapCount++;
|
|
40
|
+
if (isDoubleTap && this.doubleTapGesture.enabled) {
|
|
41
|
+
this.emitTaps();
|
|
42
|
+
}
|
|
43
|
+
else if (!isDoubleTap) {
|
|
44
|
+
this.tapTimeout = setTimeout(() => this.emitTaps(), this.tapGesture.interval);
|
|
45
|
+
}
|
|
46
|
+
this.lastTap = tapTimestamp;
|
|
47
|
+
}
|
|
48
|
+
emitTaps() {
|
|
49
|
+
if (this.tapCount === 1 && this.tapGesture.enabled) {
|
|
50
|
+
this.tap.emit();
|
|
51
|
+
}
|
|
52
|
+
else if (this.tapCount === 2 && this.doubleTapGesture.enabled) {
|
|
53
|
+
this.doubleTap.emit();
|
|
54
|
+
}
|
|
55
|
+
this.resetTaps();
|
|
56
|
+
}
|
|
57
|
+
resetTaps() {
|
|
58
|
+
clearTimeout(this.tapTimeout); // clear the old timeout
|
|
59
|
+
this.tapCount = 0;
|
|
60
|
+
this.tapTimeout = null;
|
|
61
|
+
this.lastTap = 0;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
tslib_1.__decorate([
|
|
65
|
+
(0, core_1.Output)()
|
|
66
|
+
], TapDirective.prototype, "tap", void 0);
|
|
67
|
+
tslib_1.__decorate([
|
|
68
|
+
(0, core_1.Output)()
|
|
69
|
+
], TapDirective.prototype, "doubleTap", void 0);
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, core_1.HostListener)('click', ['$event'])
|
|
72
|
+
], TapDirective.prototype, "handleTaps", null);
|
|
73
|
+
TapDirective = tslib_1.__decorate([
|
|
74
|
+
(0, core_1.Directive)({
|
|
75
|
+
selector: '[appTap]'
|
|
76
|
+
})
|
|
77
|
+
], TapDirective);
|
|
78
|
+
exports.TapDirective = TapDirective;
|
|
79
|
+
//# sourceMappingURL=tap.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tap.directive.js","sourceRoot":"","sources":["../../../../src/directives/tap/tap.directive.ts"],"names":[],"mappings":";;;;AAAA,wCAAsF;AAEtF;;;GAGG;AAKI,IAAM,YAAY,GAAlB,MAAM,YAAY;IAkBrB;QAhBU,QAAG,GAAG,IAAI,mBAAY,EAAE,CAAC;QACzB,cAAS,GAAG,IAAI,mBAAY,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;QAGE,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACjC,CAAC;IAED,QAAQ;QACJ,IAAI,CAAC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAC/B,IAAI,CAAC,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC;IACzC,CAAC;IAGD,UAAU,CAAC,CAAyB;QAChC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,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,O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ACW,YAAY,CA2DxB;AA3DY,oCAAY"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,wEAA8C"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { NgModule } from '@angular/core';
|
|
3
|
+
import { CommonModule } from '@angular/common';
|
|
4
|
+
import { PressHoldDirective } from './press-hold/press-hold.directive';
|
|
5
|
+
import { TapDirective } from './tap/tap.directive';
|
|
6
|
+
import { IonInputMaskDirective } from './input-mask/input-mask.directive';
|
|
7
|
+
/**
|
|
8
|
+
* Gerencia precionamento de enventos
|
|
9
|
+
* @author Starley Cazorla
|
|
10
|
+
*/
|
|
11
|
+
let DirectivesModule = class DirectivesModule {
|
|
12
|
+
};
|
|
13
|
+
DirectivesModule = __decorate([
|
|
14
|
+
NgModule({
|
|
15
|
+
declarations: [
|
|
16
|
+
PressHoldDirective,
|
|
17
|
+
TapDirective,
|
|
18
|
+
IonInputMaskDirective
|
|
19
|
+
],
|
|
20
|
+
imports: [
|
|
21
|
+
CommonModule
|
|
22
|
+
],
|
|
23
|
+
exports: [
|
|
24
|
+
PressHoldDirective,
|
|
25
|
+
TapDirective,
|
|
26
|
+
IonInputMaskDirective
|
|
27
|
+
]
|
|
28
|
+
})
|
|
29
|
+
], DirectivesModule);
|
|
30
|
+
export { DirectivesModule };
|
|
31
|
+
//# sourceMappingURL=directive.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directive.module.js","sourceRoot":"","sources":["../../src/directives/directive.module.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E;;;GAGG;AAkBI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAI,CAAA;AAApB,gBAAgB;IAhB5B,QAAQ,CAAC;QACN,YAAY,EAAE;YACV,kBAAkB;YAClB,YAAY;YACZ,qBAAqB;SACxB;QACD,OAAO,EAAE;YACL,YAAY;SACf;QACD,OAAO,EAAE;YACL,kBAAkB;YAClB,YAAY;YACZ,qBAAqB;SACxB;KAEJ,CAAC;GACW,gBAAgB,CAAI;SAApB,gBAAgB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { __decorate, __param } from "tslib";
|
|
2
|
+
/* eslint-disable @angular-eslint/no-host-metadata-property */
|
|
3
|
+
/* eslint-disable @angular-eslint/directive-selector */
|
|
4
|
+
import { Attribute, Directive } from '@angular/core';
|
|
5
|
+
import { NgModel } from "@angular/forms";
|
|
6
|
+
/**
|
|
7
|
+
* Responsavel pelo mascaramento de inputs
|
|
8
|
+
*/
|
|
9
|
+
let IonInputMaskDirective = class IonInputMaskDirective {
|
|
10
|
+
/**
|
|
11
|
+
* Construtor
|
|
12
|
+
* @param {NgModel} model
|
|
13
|
+
* @param {string} pattern
|
|
14
|
+
*/
|
|
15
|
+
constructor(model, pattern) {
|
|
16
|
+
this.model = model;
|
|
17
|
+
this.pattern = pattern;
|
|
18
|
+
console.log('Inicou inputMask');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Listener para mudança de valor do input
|
|
22
|
+
* @param event
|
|
23
|
+
*/
|
|
24
|
+
onKeyDown(event) {
|
|
25
|
+
let 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
|
+
let maskIndex = value.length;
|
|
40
|
+
let 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
|
+
};
|
|
58
|
+
IonInputMaskDirective = __decorate([
|
|
59
|
+
Directive({
|
|
60
|
+
selector: '[mask]',
|
|
61
|
+
host: {
|
|
62
|
+
'(keydown)': 'onKeyDown($event)'
|
|
63
|
+
},
|
|
64
|
+
providers: [NgModel]
|
|
65
|
+
}),
|
|
66
|
+
__param(1, Attribute('mask'))
|
|
67
|
+
], IonInputMaskDirective);
|
|
68
|
+
export { IonInputMaskDirective };
|
|
69
|
+
//# sourceMappingURL=input-mask.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-mask.directive.js","sourceRoot":"","sources":["../../../src/directives/input-mask/input-mask.directive.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,uDAAuD;AACvD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC;;GAEG;AAQI,IAAM,qBA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AAG,EAAE;oBAC/B,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;oBAChC,SAAS,EAAE,CAAC;iBACf;aACJ;YACD,KAAK,GAAG,SAAS,CAAC;SACrB;QACD,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QAC3B,IAAI,IAAI,CAAC,KAAK,EAAE;YACZ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CAEJ,CAAA;AAtDY,qBAAqB;IAPjC,SAAS,CAAC;QACP,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE;YACF,WAAW,EAAE,mBAAmB;SACnC;QACD,SAAS,EAAE,CAAC,OAAO,CAAC;KACvB,CAAC;IAWO,WAAA,SAAS,CAAC,MAAM,CAAC,CAAA;GAVb,qBAAqB,CAsDjC;SAtDY,qBAAqB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Directive, EventEmitter, HostListener, Output } from '@angular/core';
|
|
3
|
+
/**
|
|
4
|
+
* Gerencia pressHold
|
|
5
|
+
* @author Starley Cazorla
|
|
6
|
+
*/
|
|
7
|
+
let PressHoldDirective = class PressHoldDirective {
|
|
8
|
+
constructor() {
|
|
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
|
+
console.log('Inicou appPressHold');
|
|
21
|
+
}
|
|
22
|
+
ngOnInit() {
|
|
23
|
+
this.pressGesture.enabled = true;
|
|
24
|
+
}
|
|
25
|
+
onPress(event) {
|
|
26
|
+
if (!this.pressGesture.enabled) {
|
|
27
|
+
return;
|
|
28
|
+
} // Press is not enabled, don't do anything.
|
|
29
|
+
this.handlePressing(event.type);
|
|
30
|
+
}
|
|
31
|
+
handlePressing(type) {
|
|
32
|
+
if (type == 'touchstart') {
|
|
33
|
+
this.pressTimeout = setTimeout(() => {
|
|
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(() => this.isPressing = false, 50);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
resetTaps() {
|
|
49
|
+
clearTimeout(this.tapTimeout); // clear the old timeout
|
|
50
|
+
this.tapCount = 0;
|
|
51
|
+
this.tapTimeout = null;
|
|
52
|
+
this.lastTap = 0;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
__decorate([
|
|
56
|
+
Output()
|
|
57
|
+
], PressHoldDirective.prototype, "press", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
HostListener('touchstart', ['$event']),
|
|
60
|
+
HostListener('touchend', ['$event'])
|
|
61
|
+
], PressHoldDirective.prototype, "onPress", null);
|
|
62
|
+
PressHoldDirective = __decorate([
|
|
63
|
+
Directive({
|
|
64
|
+
selector: '[appPressHold]'
|
|
65
|
+
})
|
|
66
|
+
], PressHoldDirective);
|
|
67
|
+
export { PressHoldDirective };
|
|
68
|
+
//# sourceMappingURL=press-hold.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"press-hold.directive.js","sourceRoot":"","sources":["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AC,CAAC;gBACvB,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,mDAAmD;aACxE;YACD,qGAAqG;YACrG,oCAAoC;YACpC,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,EAAE,EAAE,CAAC,CAAC;SACjD;IACL,CAAC;IAEO,SAAS;QACb,YAAY,CAAC,IAAI,CAAC,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;CAEJ,CAAA;AArDa;IAAT,MAAM,EAAE;iDAA4B;AAsBrC;IAFC,YAAY,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,CAAC;IACtC,YAAY,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,CAAC;iDAMpC;AA7BQ,kBAAkB;IAH9B,SAAS,CAAC;QACP,QAAQ,EAAE,gBAAgB;KAC7B,CAAC;GACW,kBAAkB,CAuD9B;SAvDY,kBAAkB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Directive, EventEmitter, HostListener, Output } from '@angular/core';
|
|
3
|
+
/**
|
|
4
|
+
* Gerencia tap e doubleTap
|
|
5
|
+
* @author Starley Cazorla
|
|
6
|
+
*/
|
|
7
|
+
let TapDirective = class TapDirective {
|
|
8
|
+
constructor() {
|
|
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
|
+
console.log('Inicou appTap');
|
|
25
|
+
}
|
|
26
|
+
ngOnInit() {
|
|
27
|
+
this.tapGesture.enabled = true;
|
|
28
|
+
this.doubleTapGesture.enabled = true;
|
|
29
|
+
}
|
|
30
|
+
handleTaps(e) {
|
|
31
|
+
const tapTimestamp = Math.floor(e.timeStamp);
|
|
32
|
+
const 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(() => this.emitTaps(), this.tapGesture.interval);
|
|
42
|
+
}
|
|
43
|
+
this.lastTap = tapTimestamp;
|
|
44
|
+
}
|
|
45
|
+
emitTaps() {
|
|
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
|
+
resetTaps() {
|
|
55
|
+
clearTimeout(this.tapTimeout); // clear the old timeout
|
|
56
|
+
this.tapCount = 0;
|
|
57
|
+
this.tapTimeout = null;
|
|
58
|
+
this.lastTap = 0;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
__decorate([
|
|
62
|
+
Output()
|
|
63
|
+
], TapDirective.prototype, "tap", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
Output()
|
|
66
|
+
], TapDirective.prototype, "doubleTap", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
HostListener('click', ['$event'])
|
|
69
|
+
], TapDirective.prototype, "handleTaps", null);
|
|
70
|
+
TapDirective = __decorate([
|
|
71
|
+
Directive({
|
|
72
|
+
selector: '[appTap]'
|
|
73
|
+
})
|
|
74
|
+
], TapDirective);
|
|
75
|
+
export { TapDirective };
|
|
76
|
+
//# sourceMappingURL=tap.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tap.directive.js","sourceRoot":"","sources":["../../../src/directives/tap/tap.directive.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAU,MAAM,EAAE,MAAM,eAAe,CAAC;AAEtF;;;GAGG;AAKI,IAAM,YAAY,GAAlB,MAAM,YAAY;IAkBrB;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;QAGE,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACjC,CAAC;IAED,QAAQ;QACJ,IAAI,CAAC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAC/B,IAAI,CAAC,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC;IACzC,CAAC;IAGD,UAAU,CAAC,CAAyB;QAChC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,U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QAAQ,CAAC,CAAC;8CAcjC;AAzCQ,YAAY;IAHxB,SAAS,CAAC;QACP,QAAQ,EAAE,UAAU;KACvB,CAAC;GACW,YAAY,CA2DxB;SA3DY,YAAY"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@starley/ion-directives",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Directivas internas para ionic",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "rm -rf dist/ && npm run build:esm && npm run build:cjs",
|
|
9
|
+
"build:esm": "tsc",
|
|
10
|
+
"build:cjs": "tsc --module CommonJS --outDir dist/cjs"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@angular/common": "^15.1.1 || ^11.2.4 || ~10.0.0",
|
|
14
|
+
"@angular/core": "^15.1.1 || ^11.2.4 || ~10.0.0",
|
|
15
|
+
"@angular/forms": "^15.1.1 || ^11.2.4 || ~10.0.0"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/StarleyDev/ion-directives.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"ionic",
|
|
23
|
+
"mask",
|
|
24
|
+
"mascara",
|
|
25
|
+
"input",
|
|
26
|
+
"presshold",
|
|
27
|
+
"tap",
|
|
28
|
+
"doubletap"
|
|
29
|
+
],
|
|
30
|
+
"author": "Starley Cazorla",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/StarleyDev/ion-directives/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/StarleyDev/ion-directives#readme",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@angular/common": "^15.1.1",
|
|
38
|
+
"@angular/core": "^15.1.1",
|
|
39
|
+
"@angular/forms": "^15.1.1",
|
|
40
|
+
"@types/node": "^18.11.18",
|
|
41
|
+
"nodemon": "^2.0.20",
|
|
42
|
+
"ts-node": "^10.9.1",
|
|
43
|
+
"typescript": "^4.9.4"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"tslib": "^2.4.1"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { PressHoldDirective } from './press-hold/press-hold.directive';
|
|
4
|
+
import { TapDirective } from './tap/tap.directive';
|
|
5
|
+
import { IonInputMaskDirective } from './input-mask/input-mask.directive';
|
|
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
|
+
|
|
27
|
+
})
|
|
28
|
+
export class DirectivesModule { }
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* eslint-disable @angular-eslint/no-host-metadata-property */
|
|
2
|
+
/* eslint-disable @angular-eslint/directive-selector */
|
|
3
|
+
import { Attribute, Directive } from '@angular/core';
|
|
4
|
+
import { NgModel } from "@angular/forms";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Responsavel pelo mascaramento de inputs
|
|
8
|
+
*/
|
|
9
|
+
@Directive({
|
|
10
|
+
selector: '[mask]',
|
|
11
|
+
host: {
|
|
12
|
+
'(keydown)': 'onKeyDown($event)'
|
|
13
|
+
},
|
|
14
|
+
providers: [NgModel]
|
|
15
|
+
})
|
|
16
|
+
export class IonInputMaskDirective {
|
|
17
|
+
|
|
18
|
+
pattern: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Construtor
|
|
22
|
+
* @param {NgModel} model
|
|
23
|
+
* @param {string} pattern
|
|
24
|
+
*/
|
|
25
|
+
constructor(public model: NgModel,
|
|
26
|
+
@Attribute('mask') pattern: string) {
|
|
27
|
+
this.pattern = pattern;
|
|
28
|
+
|
|
29
|
+
console.log('Inicou inputMask');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Listener para mudança de valor do input
|
|
34
|
+
* @param event
|
|
35
|
+
*/
|
|
36
|
+
onKeyDown(event: any) {
|
|
37
|
+
let value = event.target.value,
|
|
38
|
+
pattern = this.pattern;
|
|
39
|
+
if (event.keyIdentifier === 'U+0008' || event.keyCode === 8 || event.key === 'Backspace') {
|
|
40
|
+
if (value.length) { //prevent fatal exception when backspacing empty value in progressive web app
|
|
41
|
+
//remove all trailing formatting then delete character
|
|
42
|
+
while (pattern[value.length] && pattern[value.length] !== '*') {
|
|
43
|
+
value = value.substring(0, value.length - 1);
|
|
44
|
+
}
|
|
45
|
+
//remove all leading formatting to restore placeholder
|
|
46
|
+
if (pattern.substring(0, value.length).indexOf('*') < 0) {
|
|
47
|
+
value = value.substring(0, value.length - 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
let maskIndex = value.length;
|
|
52
|
+
let formatted = '';
|
|
53
|
+
formatted += value;
|
|
54
|
+
if (maskIndex < pattern.length) {
|
|
55
|
+
//apply trailing formatting
|
|
56
|
+
while (pattern[maskIndex] !== '*') {
|
|
57
|
+
formatted += pattern[maskIndex];
|
|
58
|
+
maskIndex++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
value = formatted;
|
|
62
|
+
}
|
|
63
|
+
event.target.value = value;
|
|
64
|
+
if (this.model) {
|
|
65
|
+
this.model.update.emit(value);
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './directives/directive.module';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"compileOnSave": false,
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"baseUrl": "./",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noImplicitOverride": true,
|
|
11
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noFallthroughCasesInSwitch": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"declaration": false,
|
|
16
|
+
"downlevelIteration": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"moduleResolution": "node",
|
|
19
|
+
"importHelpers": true,
|
|
20
|
+
"target": "es2015",
|
|
21
|
+
"module": "es2020",
|
|
22
|
+
"lib": [
|
|
23
|
+
"es2018",
|
|
24
|
+
"dom"
|
|
25
|
+
],
|
|
26
|
+
"useDefineForClassFields": false
|
|
27
|
+
},
|
|
28
|
+
"include": ["src/**/*"],
|
|
29
|
+
"exclude": ["node_modules", "**/*.test.ts"]
|
|
30
|
+
}
|