@starley/ion-directives 1.1.6 → 1.1.10

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 CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@starley/ion-directives",
3
- "version": "1.1.6",
3
+ "version": "1.1.10",
4
4
  "description": "Directivas internas para ionic",
5
5
  "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
6
+ "module": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
7
10
  "scripts": {
8
11
  "build": "tsc --declaration",
9
12
  "dev": "nodemon --watch \"scr//\" --exec \"ts-node dist/index.js\" -e ts"
@@ -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('mask') 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,10 +0,0 @@
1
- import { NgModule } from '@angular/core';
2
- import { IonInputMaskDirective } from './input-mask.directive';
3
-
4
- @NgModule({
5
- declarations: [IonInputMaskDirective],
6
- imports: [
7
- ],
8
- exports: [IonInputMaskDirective]
9
- })
10
- export class IonInputMaskDirectiveModule { }
@@ -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
- }
@@ -1,10 +0,0 @@
1
- import { NgModule } from '@angular/core';
2
- import { PressHoldDirective } from './press-hold.directive';
3
-
4
- @NgModule({
5
- declarations: [PressHoldDirective],
6
- imports: [
7
- ],
8
- exports: [PressHoldDirective]
9
- })
10
- export class PressHoldDirectiveModule { }
@@ -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
- }
@@ -1,10 +0,0 @@
1
- import { NgModule } from '@angular/core';
2
- import { TapDirective } from './tap.directive';
3
-
4
- @NgModule({
5
- declarations: [TapDirective],
6
- imports: [
7
- ],
8
- exports: [TapDirective]
9
- })
10
- export class TapDirectiveModule { }
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './directives/input-mask/input-mask.directive';
2
- export * from './directives/press-hold/press-hold.directive';
3
- export * from './directives/tap/tap.directive';
4
- /** Modules */
5
- export * from './directives/input-mask/input-mask.module';
6
- export * from './directives/press-hold/press-hold.module';
7
- export * from './directives/tap/tap.module';
package/tsconfig.json DELETED
@@ -1,29 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "compileOnSave": false,
4
- "compilerOptions": {
5
- "outDir": "./dist",
6
- "forceConsistentCasingInFileNames": true,
7
- "allowSyntheticDefaultImports": true,
8
- "strict": true,
9
- "noImplicitOverride": true,
10
- "noPropertyAccessFromIndexSignature": true,
11
- "noImplicitReturns": true,
12
- "noFallthroughCasesInSwitch": true,
13
- "sourceMap": true,
14
- "declaration": false,
15
- "downlevelIteration": true,
16
- "experimentalDecorators": true,
17
- "moduleResolution": "node",
18
- "importHelpers": true,
19
- "target": "es2015",
20
- "module": "es2020",
21
- "lib": [
22
- "es2018",
23
- "dom"
24
- ],
25
- "useDefineForClassFields": false
26
- },
27
- "include": ["src/**/*"],
28
- "exclude": ["node_modules", "**/*.test.ts"]
29
- }
package/tslint.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "../../../tslint.json",
3
- "rules": {
4
- "directive-selector": [
5
- true,
6
- "attribute",
7
- "lib",
8
- "camelCase"
9
- ],
10
- "component-selector": [
11
- true,
12
- "element",
13
- "lib",
14
- "kebab-case"
15
- ]
16
- }
17
- }