@starley/ion-directives 1.2.40 → 1.2.42
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/block-input/block-copy-past.directive.d.ts +11 -0
- package/dist/block-input/block-copy-past.directive.js +38 -0
- package/dist/block-input/block-copy-past.directive.js.map +1 -0
- package/dist/directive.module.d.ts +3 -2
- package/dist/directive.module.js +9 -4
- package/dist/directive.module.js.map +1 -1
- package/dist/input-mask/input-mask.directive.d.ts +11 -0
- package/dist/input-mask/input-mask.directive.js +15 -0
- package/dist/input-mask/input-mask.directive.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ElementRef } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export declare class BlockCopyPasteDirective {
|
|
4
|
+
private el;
|
|
5
|
+
constructor(el: ElementRef);
|
|
6
|
+
onPaste(e: ClipboardEvent): void;
|
|
7
|
+
onCut(e: ClipboardEvent): void;
|
|
8
|
+
onCopy(e: ClipboardEvent): void;
|
|
9
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<BlockCopyPasteDirective, never>;
|
|
10
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<BlockCopyPasteDirective, "[appBlockCopyPaste]", never, {}, {}, never, never, false, never>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Directive, HostListener } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
var BlockCopyPasteDirective = /** @class */ (function () {
|
|
4
|
+
function BlockCopyPasteDirective(el) {
|
|
5
|
+
this.el = el;
|
|
6
|
+
}
|
|
7
|
+
BlockCopyPasteDirective.prototype.onPaste = function (e) {
|
|
8
|
+
e.preventDefault();
|
|
9
|
+
};
|
|
10
|
+
BlockCopyPasteDirective.prototype.onCut = function (e) {
|
|
11
|
+
e.preventDefault();
|
|
12
|
+
};
|
|
13
|
+
BlockCopyPasteDirective.prototype.onCopy = function (e) {
|
|
14
|
+
e.preventDefault();
|
|
15
|
+
};
|
|
16
|
+
BlockCopyPasteDirective.ɵfac = function BlockCopyPasteDirective_Factory(t) { return new (t || BlockCopyPasteDirective)(i0.ɵɵdirectiveInject(i0.ElementRef)); };
|
|
17
|
+
BlockCopyPasteDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: BlockCopyPasteDirective, selectors: [["", "appBlockCopyPaste", ""]], hostBindings: function BlockCopyPasteDirective_HostBindings(rf, ctx) { if (rf & 1) {
|
|
18
|
+
i0.ɵɵlistener("paste", function BlockCopyPasteDirective_paste_HostBindingHandler($event) { return ctx.onPaste($event); })("cut", function BlockCopyPasteDirective_cut_HostBindingHandler($event) { return ctx.onCut($event); })("copy", function BlockCopyPasteDirective_copy_HostBindingHandler($event) { return ctx.onCopy($event); });
|
|
19
|
+
} } });
|
|
20
|
+
return BlockCopyPasteDirective;
|
|
21
|
+
}());
|
|
22
|
+
export { BlockCopyPasteDirective };
|
|
23
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BlockCopyPasteDirective, [{
|
|
24
|
+
type: Directive,
|
|
25
|
+
args: [{
|
|
26
|
+
selector: '[appBlockCopyPaste]'
|
|
27
|
+
}]
|
|
28
|
+
}], function () { return [{ type: i0.ElementRef }]; }, { onPaste: [{
|
|
29
|
+
type: HostListener,
|
|
30
|
+
args: ['paste', ['$event']]
|
|
31
|
+
}], onCut: [{
|
|
32
|
+
type: HostListener,
|
|
33
|
+
args: ['cut', ['$event']]
|
|
34
|
+
}], onCopy: [{
|
|
35
|
+
type: HostListener,
|
|
36
|
+
args: ['copy', ['$event']]
|
|
37
|
+
}] }); })();
|
|
38
|
+
//# sourceMappingURL=block-copy-past.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-copy-past.directive.js","sourceRoot":"","sources":["../../src/block-input/block-copy-past.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAc,YAAY,EAAE,MAAM,eAAe,CAAC;;AAEpE;IAII,iCAAoB,EAAc;QAAd,OAAE,GAAF,EAAE,CAAY;IAAI,CAAC;IAGvC,yCAAO,GADP,UACQ,CAAiB;QACrB,CAAC,CAAC,cAAc,EAAE,CAAC;IACvB,CAAC;IAGD,uCAAK,GADL,UACM,CAAiB;QACnB,CAAC,CAAC,cAAc,EAAE,CAAC;IACvB,CAAC;IAGD,wCAAM,GADN,UACO,CAAiB;QACpB,CAAC,CAAC,cAAc,EAAE,CAAC;IACvB,CAAC;kGAhBQ,uBAAuB;8EAAvB,uBAAuB;8GAAvB,mBAAe,qFAAf,iBAAa,uFAAb,kBAAc;;kCAL3B;CAsBC,AApBD,IAoBC;SAjBY,uBAAuB;uFAAvB,uBAAuB;cAHnC,SAAS;eAAC;gBACP,QAAQ,EAAE,qBAAqB;aAClC;6DAKG,OAAO;kBADN,YAAY;mBAAC,OAAO,EAAE,CAAC,QAAQ,CAAC;YAMjC,KAAK;kBADJ,YAAY;mBAAC,KAAK,EAAE,CAAC,QAAQ,CAAC;YAM/B,MAAM;kBADL,YAAY;mBAAC,MAAM,EAAE,CAAC,QAAQ,CAAC","sourcesContent":["import { Directive, ElementRef, HostListener } from '@angular/core';\n\n@Directive({\n selector: '[appBlockCopyPaste]'\n})\nexport class BlockCopyPasteDirective {\n constructor(private el: ElementRef) { }\n\n @HostListener('paste', ['$event'])\n onPaste(e: ClipboardEvent) {\n e.preventDefault();\n }\n\n @HostListener('cut', ['$event'])\n onCut(e: ClipboardEvent) {\n e.preventDefault();\n }\n\n @HostListener('copy', ['$event'])\n onCopy(e: ClipboardEvent) {\n e.preventDefault();\n }\n}\n"]}
|
|
@@ -4,7 +4,8 @@ import * as i1 from "./press-hold/press-hold.directive";
|
|
|
4
4
|
import * as i2 from "./tap/tap.directive";
|
|
5
5
|
import * as i3 from "./input-mask/input-mask.directive";
|
|
6
6
|
import * as i4 from "./input-remove/input-remove.directive";
|
|
7
|
-
import * as i5 from "
|
|
7
|
+
import * as i5 from "./block-input/block-copy-past.directive";
|
|
8
|
+
import * as i6 from "@angular/common";
|
|
8
9
|
/**
|
|
9
10
|
* Gerencia precionamento de enventos
|
|
10
11
|
* @author Starley Cazorla
|
|
@@ -12,6 +13,6 @@ import * as i5 from "@angular/common";
|
|
|
12
13
|
export declare class DirectivesModule {
|
|
13
14
|
static forRoot(): ModuleWithProviders<DirectivesModule>;
|
|
14
15
|
static ɵfac: i0.ɵɵFactoryDeclaration<DirectivesModule, never>;
|
|
15
|
-
static ɵmod: i0.ɵɵNgModuleDeclaration<DirectivesModule, [typeof i1.PressHoldDirective, typeof i2.TapDirective, typeof i3.IonInputMaskDirective, typeof i4.IonInputRemoveDirective], [typeof
|
|
16
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<DirectivesModule, [typeof i1.PressHoldDirective, typeof i2.TapDirective, typeof i3.IonInputMaskDirective, typeof i4.IonInputRemoveDirective, typeof i5.BlockCopyPasteDirective], [typeof i6.CommonModule], [typeof i1.PressHoldDirective, typeof i2.TapDirective, typeof i3.IonInputMaskDirective, typeof i4.IonInputRemoveDirective, typeof i5.BlockCopyPasteDirective]>;
|
|
16
17
|
static ɵinj: i0.ɵɵInjectorDeclaration<DirectivesModule>;
|
|
17
18
|
}
|
package/dist/directive.module.js
CHANGED
|
@@ -4,6 +4,7 @@ import { IonInputMaskDirective } from './input-mask/input-mask.directive';
|
|
|
4
4
|
import { IonInputRemoveDirective } from './input-remove/input-remove.directive';
|
|
5
5
|
import { PressHoldDirective } from './press-hold/press-hold.directive';
|
|
6
6
|
import { TapDirective } from './tap/tap.directive';
|
|
7
|
+
import { BlockCopyPasteDirective } from './block-input/block-copy-past.directive';
|
|
7
8
|
import * as i0 from "@angular/core";
|
|
8
9
|
/**
|
|
9
10
|
* Gerencia precionamento de enventos
|
|
@@ -31,7 +32,8 @@ export { DirectivesModule };
|
|
|
31
32
|
PressHoldDirective,
|
|
32
33
|
TapDirective,
|
|
33
34
|
IonInputMaskDirective,
|
|
34
|
-
IonInputRemoveDirective
|
|
35
|
+
IonInputRemoveDirective,
|
|
36
|
+
BlockCopyPasteDirective
|
|
35
37
|
],
|
|
36
38
|
imports: [
|
|
37
39
|
CommonModule
|
|
@@ -40,7 +42,8 @@ export { DirectivesModule };
|
|
|
40
42
|
PressHoldDirective,
|
|
41
43
|
TapDirective,
|
|
42
44
|
IonInputMaskDirective,
|
|
43
|
-
IonInputRemoveDirective
|
|
45
|
+
IonInputRemoveDirective,
|
|
46
|
+
BlockCopyPasteDirective
|
|
44
47
|
],
|
|
45
48
|
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]
|
|
46
49
|
}]
|
|
@@ -48,8 +51,10 @@ export { DirectivesModule };
|
|
|
48
51
|
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(DirectivesModule, { declarations: [PressHoldDirective,
|
|
49
52
|
TapDirective,
|
|
50
53
|
IonInputMaskDirective,
|
|
51
|
-
IonInputRemoveDirective
|
|
54
|
+
IonInputRemoveDirective,
|
|
55
|
+
BlockCopyPasteDirective], imports: [CommonModule], exports: [PressHoldDirective,
|
|
52
56
|
TapDirective,
|
|
53
57
|
IonInputMaskDirective,
|
|
54
|
-
IonInputRemoveDirective
|
|
58
|
+
IonInputRemoveDirective,
|
|
59
|
+
BlockCopyPasteDirective] }); })();
|
|
55
60
|
//# sourceMappingURL=directive.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directive.module.js","sourceRoot":"","sources":["../src/directive.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAuB,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACxG,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EA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,uBAAuB;QACvB,uBAAuB,aAGvB,YAAY,aAGZ,kBAAkB;QAClB,YAAY;QACZ,qBAAqB;QACrB,uBAAuB;QACvB,uBAAuB","sourcesContent":["import { CommonModule } from '@angular/common';\nimport { CUSTOM_ELEMENTS_SCHEMA, ModuleWithProviders, NgModule, NO_ERRORS_SCHEMA } from '@angular/core';\nimport { IonInputMaskDirective } from './input-mask/input-mask.directive';\nimport { IonInputRemoveDirective } from './input-remove/input-remove.directive';\nimport { PressHoldDirective } from './press-hold/press-hold.directive';\nimport { TapDirective } from './tap/tap.directive';\nimport { BlockCopyPasteDirective } from './block-input/block-copy-past.directive';\n\n/**\n * Gerencia precionamento de enventos\n * @author Starley Cazorla\n */\n\n@NgModule({\n declarations: [\n PressHoldDirective,\n TapDirective,\n IonInputMaskDirective,\n IonInputRemoveDirective,\n BlockCopyPasteDirective\n ],\n imports: [\n CommonModule\n ],\n exports: [\n PressHoldDirective,\n TapDirective,\n IonInputMaskDirective,\n IonInputRemoveDirective,\n BlockCopyPasteDirective\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"]}
|
|
@@ -16,8 +16,19 @@ export declare class IonInputMaskDirective implements OnChanges {
|
|
|
16
16
|
constructor(elementRef: ElementRef, renderer: Renderer2, ngModel: NgModel, cdRef: ChangeDetectorRef);
|
|
17
17
|
ngOnChanges(changes: SimpleChanges): void;
|
|
18
18
|
onInput(value: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Applys mask
|
|
21
|
+
* @author Starley Cazorla
|
|
22
|
+
*/
|
|
19
23
|
private applyMask;
|
|
20
24
|
private extractRawValue;
|
|
25
|
+
/**
|
|
26
|
+
* Masks value
|
|
27
|
+
* @author Starley Cazorla
|
|
28
|
+
* @param rawValue
|
|
29
|
+
* @param mask
|
|
30
|
+
* @returns value
|
|
31
|
+
*/
|
|
21
32
|
private maskValue;
|
|
22
33
|
static ɵfac: i0.ɵɵFactoryDeclaration<IonInputMaskDirective, never>;
|
|
23
34
|
static ɵdir: i0.ɵɵDirectiveDeclaration<IonInputMaskDirective, "[appMask]", never, { "pattern": { "alias": "appMask"; "required": false; }; }, {}, never, never, false, never>;
|
|
@@ -27,6 +27,10 @@ var IonInputMaskDirective = /** @class */ (function () {
|
|
|
27
27
|
this.rawValue = this.extractRawValue(value); // Atualize o valor bruto com o novo valor de entrada
|
|
28
28
|
this.applyMask(); // Reaplique a máscara
|
|
29
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Applys mask
|
|
32
|
+
* @author Starley Cazorla
|
|
33
|
+
*/
|
|
30
34
|
IonInputMaskDirective.prototype.applyMask = function () {
|
|
31
35
|
var _this = this;
|
|
32
36
|
// Aplique a máscara ao valor bruto
|
|
@@ -41,7 +45,18 @@ var IonInputMaskDirective = /** @class */ (function () {
|
|
|
41
45
|
IonInputMaskDirective.prototype.extractRawValue = function (value) {
|
|
42
46
|
return value.replace(/[^a-zA-Z0-9]/g, ''); // Remove todos os caracteres não são letras e digitos
|
|
43
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Masks value
|
|
50
|
+
* @author Starley Cazorla
|
|
51
|
+
* @param rawValue
|
|
52
|
+
* @param mask
|
|
53
|
+
* @returns value
|
|
54
|
+
*/
|
|
44
55
|
IonInputMaskDirective.prototype.maskValue = function (rawValue, mask) {
|
|
56
|
+
// Se a máscara não tiver um padrão, não faca nada
|
|
57
|
+
if (mask === undefined || mask === null || mask === '') {
|
|
58
|
+
return rawValue;
|
|
59
|
+
}
|
|
45
60
|
var maskedValue = '';
|
|
46
61
|
var rawValIndex = 0;
|
|
47
62
|
for (var i = 0; i < mask.length && rawValIndex < rawValue.length; i++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-mask.directive.js","sourceRoot":"","sources":["../../src/input-mask/input-mask.directive.ts"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AAe,GAAvB,UAAwB,KAAa;QACjC,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,CAAC,sDAAsD;IACrG,CAAC;IAED;;;;;;OAMG;IACK,yCAAS,GAAjB,UAAkB,QAAgB,EAAE,IAAY;QAE5C,kDAAkD;QAClD,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,EAAE;YACpD,OAAO,QAAQ,CAAC;SACnB;QAED,IAAI,WAAW,GAAG,EAAE,CAAC;QACrB,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,WAAW,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnE,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;gBACjB,WAAW,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;aAC1C;iBAAM;gBACH,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;aAC1B;SACJ;QACD,OAAO,WAAW,CAAC;IACvB,CAAC;8FAhEQ,qBAAqB;4EAArB,qBAAqB;4GAArB,gCAA4B;2FAF1B,CAAC,OAAO,CAAC;gCAXxB;CA8EC,AArED,IAqEC;SAjEY,qBAAqB;uFAArB,qBAAqB;cAJjC,SAAS;eAAC;gBACP,QAAQ,EAAE,WAAW;gBACrB,SAAS,EAAE,CAAC,OAAO,CAAC;aACvB;2IAGqB,OAAO;kBAAxB,KAAK;mBAAC,SAAS;YAehB,OAAO;kBADN,YAAY;mBAAC,OAAO,EAAE,CAAC,qBAAqB,CAAC","sourcesContent":["import { ChangeDetectorRef, Directive, ElementRef, HostListener, Input, OnChanges, Renderer2, SimpleChanges } from '@angular/core';\nimport { NgModel } from '@angular/forms';\n\n/**\n * Directive input mask\n * @author Starley Cazorla\n * @version 1.0.0\n */\n\n@Directive({\n selector: '[appMask]',\n providers: [NgModel]\n})\nexport class IonInputMaskDirective implements OnChanges {\n\n @Input('appMask') pattern: string;\n private rawValue: string = '';\n\n constructor(private elementRef: ElementRef, private renderer: Renderer2, private ngModel: NgModel, private cdRef: ChangeDetectorRef) { }\n\n ngOnChanges(changes: SimpleChanges) {\n if (changes['pattern'] && !changes['pattern'].firstChange) {\n // Quando a máscara muda, limpe o valor e aplique a nova máscara\n this.rawValue = this.extractRawValue(this.ngModel.value); // Extraia o valor bruto antes de aplicar a nova máscara\n this.applyMask(); // Reaplique a máscara\n this.cdRef.detectChanges();\n }\n }\n\n @HostListener('input', ['$event.target.value'])\n onInput(value: string) {\n this.rawValue = this.extractRawValue(value); // Atualize o valor bruto com o novo valor de entrada\n this.applyMask(); // Reaplique a máscara\n }\n\n /**\n * Applys mask\n * @author Starley Cazorla\n */\n private applyMask() {\n // Aplique a máscara ao valor bruto\n const maskedValue = this.maskValue(this.rawValue, this.pattern);\n Promise.resolve().then(() => {\n // Atualizar o input e o modelo de controle com o valor mascarado\n this.renderer.setProperty(this.elementRef.nativeElement, 'value', maskedValue);\n this.ngModel.control?.setValue(maskedValue, { emitEvent: false });\n });\n }\n\n private extractRawValue(value: string): string {\n return value.replace(/[^a-zA-Z0-9]/g, ''); // Remove todos os caracteres não são letras e digitos\n }\n\n /**\n * Masks value\n * @author Starley Cazorla\n * @param rawValue\n * @param mask\n * @returns value\n */\n private maskValue(rawValue: string, mask: string): string {\n\n // Se a máscara não tiver um padrão, não faca nada\n if (mask === undefined || mask === null || mask === '') {\n return rawValue;\n }\n\n let maskedValue = '';\n let rawValIndex = 0;\n for (let i = 0; i < mask.length && rawValIndex < rawValue.length; i++) {\n if (mask[i] === '*') {\n maskedValue += rawValue[rawValIndex++];\n } else {\n maskedValue += mask[i];\n }\n }\n return maskedValue;\n }\n}\n"]}
|