@sam-senior/virtual-keyboard 1.0.3 → 2.0.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.
@@ -1,274 +1,190 @@
1
- import { Directive, ElementRef, Optional, Input, Output, EventEmitter, NgModule } from '@angular/core';
2
- import { NgControl } from '@angular/forms';
1
+ import * as i0 from '@angular/core';
2
+ import { EventEmitter, Directive, Optional, Input, Output, NgModule } from '@angular/core';
3
+ import * as i1 from '@angular/forms';
3
4
 
4
- /**
5
- * @fileoverview added by tsickle
6
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
7
- */
8
- /**
9
- * ************************************************************
10
- * Método que retonar instancia do elemento jQuery, pois
11
- * o projeto que implementa esta diretiva fica fora da lib.
12
- * Devido ficar fora, o webpack não ficará aqui, portando não
13
- * tem jQuery na lib;
14
- * **************************************************************
15
- * @type {?}
16
- */
17
- const jQueryInstance = (/**
18
- * @param {?} element
19
- * @return {?}
20
- */
21
- (element) => {
22
- /** @type {?} */
23
- const windowInstance = (/** @type {?} */ (window));
24
- return windowInstance.jQuery ? windowInstance.jQuery(element) : null;
25
- });
26
- class VirtualKeyboardDirective {
27
- /**
28
- * @param {?} elementRef
29
- * @param {?} fieldControl
30
- */
31
- constructor(elementRef, fieldControl) {
32
- this.elementRef = elementRef;
33
- this.fieldControl = fieldControl;
34
- this.keyboardPosition = 'bottom';
35
- this.keyboardType = 'email';
36
- this.showOnFocus = true;
37
- this.keyboardValueAccepted = new EventEmitter();
38
- this.showKeyboardChange = new EventEmitter();
39
- this._showKeyboard = false;
40
- this.value = '';
41
- }
42
- /**
43
- * @param {?} activateKeyboard
44
- * @return {?}
45
- */
46
- set activateKeyboard(activateKeyboard) {
47
- if (activateKeyboard) {
48
- this.keyboardElement = (/** @type {?} */ (this.elementRef.nativeElement));
49
- this.keyboardjQueryElement = jQueryInstance(this.keyboardElement);
50
- if (this.keyboardjQueryElement) {
51
- this.keyboardjQueryElement.keyboard(this.createKeyboardOptions());
52
- }
53
- }
54
- }
55
- /**
56
- * @return {?}
57
- */
58
- get showKeyboard() {
59
- return this._showKeyboard;
60
- }
61
- /**
62
- * @param {?} revealKeyboard
63
- * @return {?}
64
- */
65
- set showKeyboard(revealKeyboard) {
66
- this._showKeyboard = revealKeyboard;
67
- this.showKeyboardChange.emit(this._showKeyboard);
68
- }
69
- /**
70
- * @return {?}
71
- */
72
- ngOnChanges() {
73
- if (this.showKeyboard && this.isKeyboardCreated()) {
74
- this.keyboardjQueryElement.getkeyboard().reveal();
75
- }
76
- }
77
- /**
78
- * @return {?}
79
- */
80
- ngOnDestroy() {
81
- if (this.isKeyboardCreated()) {
82
- this.keyboardjQueryElement
83
- .keyboard()
84
- .getkeyboard()
85
- .destroy();
86
- }
87
- }
88
- /**
89
- * @private
90
- * @return {?}
91
- */
92
- isKeyboardCreated() {
93
- return (this.keyboardjQueryElement &&
94
- this.keyboardjQueryElement.keyboard() &&
95
- this.keyboardjQueryElement.keyboard().getkeyboard());
96
- }
97
- /**
98
- * @private
99
- * @return {?}
100
- */
101
- getDefaultKeyboardOptions() {
102
- /** @type {?} */
103
- const keyboardOptions = (/** @type {?} */ ({}));
104
- if (!this.showOnFocus) {
105
- keyboardOptions.openOn = '';
106
- }
107
- keyboardOptions.usePreview = false;
108
- keyboardOptions.accepted = this.onValueAccepted.bind(this);
109
- keyboardOptions.visible = this.onKeyboardVisible.bind(this);
110
- keyboardOptions.beforeClose = this.onBeforeClose.bind(this);
111
- keyboardOptions.change = this.onChange.bind(this);
112
- return keyboardOptions;
113
- }
114
- /**
115
- * @private
116
- * @return {?}
117
- */
118
- getKeyboardDisplayOptions() {
119
- return {
120
- bksp: '\u2190',
121
- normal: 'ABC',
122
- meta1: '%?@',
123
- meta2: '#+=',
124
- accept: 'OK'
125
- };
126
- }
127
- /**
128
- * @private
129
- * @return {?}
130
- */
131
- getKeyboardLayout() {
132
- /** @type {?} */
133
- let customLayout = {};
134
- if (this.keyboardType === 'alphanumeric') {
135
- customLayout = {
136
- normal: [
137
- '1 2 3 4 5 6 7 8 9 0',
138
- 'Q W E R T Y U I O P {bksp}',
139
- 'A S D F G H J K L Ç',
140
- 'Z X C V B N M {accept}'
141
- ]
142
- };
143
- }
144
- else if (this.keyboardType === 'email') {
145
- customLayout = this.getCustomKeyboardForEmail();
146
- }
147
- return customLayout;
148
- }
149
- /**
150
- * @private
151
- * @return {?}
152
- */
153
- getCustomKeyboardForEmail() {
154
- return {
155
- normal: [
156
- '1 2 3 4 5 6 7 8 9 0',
157
- 'q w e r t y u i o p {bksp}',
158
- 'a s d f g h j k l ç',
159
- '{s} z x c v b n m .',
160
- '{meta1} {space} _ - {accept}'
161
- ],
162
- shift: [
163
- '1 2 3 4 5 6 7 8 9 0',
164
- 'Q W E R T Y U I O P {bksp}',
165
- 'A S D F G H J K L Ç',
166
- '{s} Z X C V B N M .',
167
- '{meta1} {space} _ - {accept}'
168
- ],
169
- meta1: [
170
- "` | { } % ^ * / ' {bksp}",
171
- '{meta2} $ & ~ # = + @',
172
- '{normal} {space} ! ? {accept}'
173
- ],
174
- meta2: [
175
- '[ ] { } \u2039 \u203a ^ * " , {bksp}',
176
- '\\ | / < > $ \u00a3 \u00a5 \u2022',
177
- '{meta1} \u20ac & ~ # = + .',
178
- '{normal} {space} ! ? {accept}'
179
- ]
180
- };
181
- }
182
- /**
183
- * @private
184
- * @return {?}
185
- */
186
- createKeyboardOptions() {
187
- /** @type {?} */
188
- const keyboardOptions = this.getDefaultKeyboardOptions();
189
- if (this.keyboardPosition !== 'relative') {
190
- keyboardOptions.position = false;
191
- }
192
- if (this.keyboardPosition === 'bottom') {
193
- this.addBottomKeyboardClass();
194
- }
195
- keyboardOptions.css = {
196
- buttonDefault: 'keyboard-button-override'
197
- };
198
- keyboardOptions.display = this.getKeyboardDisplayOptions();
199
- keyboardOptions.layout = 'custom';
200
- keyboardOptions.customLayout = this.getKeyboardLayout();
201
- return keyboardOptions;
202
- }
203
- /**
204
- * @private
205
- * @return {?}
206
- */
207
- onKeyboardVisible() {
208
- this.addCustomKeyboardFocusClass();
209
- }
210
- /**
211
- * @private
212
- * @return {?}
213
- */
214
- onBeforeClose() {
215
- // O elemente do jQuery limpa tudo o que não passou pelo accept
216
- // Necessário setar o valor quando somente fechado a modal.
217
- /** @type {?} */
218
- const formControl = this.fieldControl.control;
219
- formControl.setValue(this.value);
220
- this.showKeyboard = false;
221
- }
222
- /**
223
- * @private
224
- * @return {?}
225
- */
226
- onValueAccepted() {
227
- /** @type {?} */
228
- const casted = (/** @type {?} */ (this.keyboardElement));
229
- this.keyboardValueAccepted.emit(casted.value);
230
- }
231
- /**
232
- * @private
233
- * @param {?} event
234
- * @return {?}
235
- */
236
- onChange(event) {
237
- /** @type {?} */
238
- const virtualkeyboardevent = new CustomEvent('virtualkeyboardevent', event);
239
- document.dispatchEvent(virtualkeyboardevent);
240
- if (this.keyboardElement instanceof HTMLInputElement) {
241
- /** @type {?} */
242
- const keyboardElement = (/** @type {?} */ (this.keyboardElement));
243
- // Arquivo possui referecia do jQuery que é alterado ao fechar o teclado.
244
- // Necessário clonar a string.
245
- /** @type {?} */
246
- const inputVal = JSON.stringify(keyboardElement.value).replace('"', '').replace('"', '');
247
- if (this.fieldControl) {
248
- /** @type {?} */
249
- const formControl = this.fieldControl.control;
250
- this.value = inputVal;
251
- formControl.setValue(inputVal);
252
- formControl.markAsDirty();
253
- formControl.updateValueAndValidity();
254
- }
255
- // Este setTimeout é necessário para fazer com que o
256
- // cursor do input sempre esteja no final da string digitada
257
- // e o final da string sempre esteja visivel.
258
- setTimeout((/**
259
- * @return {?}
260
- */
261
- () => {
262
- keyboardElement.value = inputVal;
263
- keyboardElement.scrollLeft = keyboardElement.scrollWidth;
264
- }));
265
- }
266
- }
267
- /**
268
- * @private
269
- * @return {?}
270
- */
271
- addBottomKeyboardClass() {
5
+ /***************************************************************
6
+ * Método que retonar instancia do elemento jQuery, pois
7
+ * o projeto que implementa esta diretiva fica fora da lib.
8
+ * Devido ficar fora, o webpack não ficará aqui, portando não
9
+ * tem jQuery na lib;
10
+ ****************************************************************/
11
+ const jQueryInstance = (element) => {
12
+ const windowInstance = window;
13
+ return windowInstance.jQuery ? windowInstance.jQuery(element) : null;
14
+ };
15
+ class VirtualKeyboardDirective {
16
+ elementRef;
17
+ fieldControl;
18
+ keyboardPosition = 'bottom';
19
+ keyboardType = 'email';
20
+ set activateKeyboard(activateKeyboard) {
21
+ if (activateKeyboard) {
22
+ this.keyboardElement = this.elementRef.nativeElement;
23
+ this.keyboardjQueryElement = jQueryInstance(this.keyboardElement);
24
+ if (this.keyboardjQueryElement) {
25
+ this.keyboardjQueryElement.keyboard(this.createKeyboardOptions());
26
+ }
27
+ }
28
+ }
29
+ showOnFocus = true;
30
+ get showKeyboard() {
31
+ return this._showKeyboard;
32
+ }
33
+ set showKeyboard(revealKeyboard) {
34
+ this._showKeyboard = revealKeyboard;
35
+ this.showKeyboardChange.emit(this._showKeyboard);
36
+ }
37
+ keyboardValueAccepted = new EventEmitter();
38
+ showKeyboardChange = new EventEmitter();
39
+ _showKeyboard = false;
40
+ keyboardElement;
41
+ value = '';
42
+ // Any devido a ser referência do jQuery;
43
+ keyboardjQueryElement;
44
+ constructor(elementRef, fieldControl) {
45
+ this.elementRef = elementRef;
46
+ this.fieldControl = fieldControl;
47
+ }
48
+ ngOnChanges() {
49
+ if (this.showKeyboard && this.isKeyboardCreated()) {
50
+ this.keyboardjQueryElement.getkeyboard().reveal();
51
+ }
52
+ }
53
+ ngOnDestroy() {
54
+ if (this.isKeyboardCreated()) {
55
+ this.keyboardjQueryElement
56
+ .keyboard()
57
+ .getkeyboard()
58
+ .destroy();
59
+ }
60
+ }
61
+ isKeyboardCreated() {
62
+ return (this.keyboardjQueryElement &&
63
+ this.keyboardjQueryElement.keyboard() &&
64
+ this.keyboardjQueryElement.keyboard().getkeyboard());
65
+ }
66
+ getDefaultKeyboardOptions() {
67
+ const keyboardOptions = {};
68
+ if (!this.showOnFocus) {
69
+ keyboardOptions.openOn = '';
70
+ }
71
+ keyboardOptions.usePreview = false;
72
+ keyboardOptions.accepted = this.onValueAccepted.bind(this);
73
+ keyboardOptions.visible = this.onKeyboardVisible.bind(this);
74
+ keyboardOptions.beforeClose = this.onBeforeClose.bind(this);
75
+ keyboardOptions.change = this.onChange.bind(this);
76
+ return keyboardOptions;
77
+ }
78
+ getKeyboardDisplayOptions() {
79
+ return {
80
+ bksp: '\u2190',
81
+ normal: 'ABC',
82
+ meta1: '%?@',
83
+ meta2: '#+=',
84
+ accept: 'OK'
85
+ };
86
+ }
87
+ getKeyboardLayout() {
88
+ let customLayout = {};
89
+ if (this.keyboardType === 'alphanumeric') {
90
+ customLayout = {
91
+ normal: [
92
+ '1 2 3 4 5 6 7 8 9 0',
93
+ 'Q W E R T Y U I O P {bksp}',
94
+ 'A S D F G H J K L Ç',
95
+ 'Z X C V B N M {accept}'
96
+ ]
97
+ };
98
+ }
99
+ else if (this.keyboardType === 'email') {
100
+ customLayout = this.getCustomKeyboardForEmail();
101
+ }
102
+ return customLayout;
103
+ }
104
+ getCustomKeyboardForEmail() {
105
+ return {
106
+ normal: [
107
+ '1 2 3 4 5 6 7 8 9 0',
108
+ 'q w e r t y u i o p {bksp}',
109
+ 'a s d f g h j k l ç',
110
+ '{s} z x c v b n m .',
111
+ '{meta1} {space} _ - {accept}'
112
+ ],
113
+ shift: [
114
+ '1 2 3 4 5 6 7 8 9 0',
115
+ 'Q W E R T Y U I O P {bksp}',
116
+ 'A S D F G H J K L Ç',
117
+ '{s} Z X C V B N M .',
118
+ '{meta1} {space} _ - {accept}'
119
+ ],
120
+ meta1: [
121
+ "` | { } % ^ * / ' {bksp}",
122
+ '{meta2} $ & ~ # = + @',
123
+ '{normal} {space} ! ? {accept}'
124
+ ],
125
+ meta2: [
126
+ '[ ] { } \u2039 \u203a ^ * " , {bksp}',
127
+ '\\ | / < > $ \u00a3 \u00a5 \u2022',
128
+ '{meta1} \u20ac & ~ # = + .',
129
+ '{normal} {space} ! ? {accept}'
130
+ ]
131
+ };
132
+ }
133
+ createKeyboardOptions() {
134
+ const keyboardOptions = this.getDefaultKeyboardOptions();
135
+ if (this.keyboardPosition !== 'relative') {
136
+ keyboardOptions.position = false;
137
+ }
138
+ if (this.keyboardPosition === 'bottom') {
139
+ this.addBottomKeyboardClass();
140
+ }
141
+ keyboardOptions.css = {
142
+ buttonDefault: 'keyboard-button-override'
143
+ };
144
+ keyboardOptions.display = this.getKeyboardDisplayOptions();
145
+ keyboardOptions.layout = 'custom';
146
+ keyboardOptions.customLayout = this.getKeyboardLayout();
147
+ return keyboardOptions;
148
+ }
149
+ onKeyboardVisible() {
150
+ this.addCustomKeyboardFocusClass();
151
+ }
152
+ onBeforeClose() {
153
+ // O elemente do jQuery limpa tudo o que não passou pelo accept
154
+ // Necessário setar o valor quando somente fechado a modal.
155
+ const formControl = this.fieldControl.control;
156
+ formControl.setValue(this.value);
157
+ this.showKeyboard = false;
158
+ }
159
+ onValueAccepted() {
160
+ const casted = this.keyboardElement;
161
+ this.keyboardValueAccepted.emit(casted.value);
162
+ }
163
+ onChange(event) {
164
+ const virtualkeyboardevent = new CustomEvent('virtualkeyboardevent', event);
165
+ document.dispatchEvent(virtualkeyboardevent);
166
+ if (this.keyboardElement instanceof HTMLInputElement) {
167
+ const keyboardElement = this.keyboardElement;
168
+ // Arquivo possui referecia do jQuery que é alterado ao fechar o teclado.
169
+ // Necessário clonar a string.
170
+ const inputVal = JSON.stringify(keyboardElement.value).replace('"', '').replace('"', '');
171
+ if (this.fieldControl) {
172
+ const formControl = this.fieldControl.control;
173
+ this.value = inputVal;
174
+ formControl.setValue(inputVal);
175
+ formControl.markAsDirty();
176
+ formControl.updateValueAndValidity();
177
+ }
178
+ // Este setTimeout é necessário para fazer com que o
179
+ // cursor do input sempre esteja no final da string digitada
180
+ // e o final da string sempre esteja visivel.
181
+ setTimeout(() => {
182
+ keyboardElement.value = inputVal;
183
+ keyboardElement.scrollLeft = keyboardElement.scrollWidth;
184
+ });
185
+ }
186
+ }
187
+ addBottomKeyboardClass() {
272
188
  this.injectCssRule(`.ui-keyboard {
273
189
  border-radius: 0;
274
190
  left: 0;
@@ -276,73 +192,65 @@ class VirtualKeyboardDirective {
276
192
  bottom: 0;
277
193
  position: fixed;
278
194
  width: 100%;
279
- }`);
280
- }
281
- /**
282
- * @private
283
- * @return {?}
284
- */
285
- addCustomKeyboardFocusClass() {
195
+ }`);
196
+ }
197
+ addCustomKeyboardFocusClass() {
286
198
  this.injectCssRule(`.ui-keyboard-has-focus {
287
199
  z-index: 900;
288
- }`);
289
- }
290
- /**
291
- * @private
292
- * @param {?} rule
293
- * @return {?}
294
- */
295
- injectCssRule(rule) {
296
- /** @type {?} */
297
- const style = (/** @type {?} */ (document.createElement('style')));
298
- style.appendChild(document.createTextNode(''));
299
- document.head.appendChild(style);
300
- style.sheet.insertRule(rule);
301
- }
302
- }
303
- VirtualKeyboardDirective.decorators = [
304
- { type: Directive, args: [{
305
- selector: '[samVirtualKeyboard]'
306
- },] }
307
- ];
308
- /** @nocollapse */
309
- VirtualKeyboardDirective.ctorParameters = () => [
310
- { type: ElementRef },
311
- { type: NgControl, decorators: [{ type: Optional }] }
312
- ];
313
- VirtualKeyboardDirective.propDecorators = {
314
- keyboardPosition: [{ type: Input }],
315
- keyboardType: [{ type: Input }],
316
- activateKeyboard: [{ type: Input }],
317
- showOnFocus: [{ type: Input }],
318
- showKeyboard: [{ type: Input }],
319
- keyboardValueAccepted: [{ type: Output }],
320
- showKeyboardChange: [{ type: Output }]
321
- };
200
+ }`);
201
+ }
202
+ injectCssRule(rule) {
203
+ const style = document.createElement('style');
204
+ style.appendChild(document.createTextNode(''));
205
+ document.head.appendChild(style);
206
+ style.sheet.insertRule(rule);
207
+ }
208
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: VirtualKeyboardDirective, deps: [{ token: i0.ElementRef }, { token: i1.NgControl, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
209
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: VirtualKeyboardDirective, selector: "[samVirtualKeyboard]", inputs: { keyboardPosition: "keyboardPosition", keyboardType: "keyboardType", activateKeyboard: "activateKeyboard", showOnFocus: "showOnFocus", showKeyboard: "showKeyboard" }, outputs: { keyboardValueAccepted: "keyboardValueAccepted", showKeyboardChange: "showKeyboardChange" }, usesOnChanges: true, ngImport: i0 });
210
+ }
211
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: VirtualKeyboardDirective, decorators: [{
212
+ type: Directive,
213
+ args: [{
214
+ selector: '[samVirtualKeyboard]'
215
+ }]
216
+ }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.NgControl, decorators: [{
217
+ type: Optional
218
+ }] }], propDecorators: { keyboardPosition: [{
219
+ type: Input
220
+ }], keyboardType: [{
221
+ type: Input
222
+ }], activateKeyboard: [{
223
+ type: Input
224
+ }], showOnFocus: [{
225
+ type: Input
226
+ }], showKeyboard: [{
227
+ type: Input
228
+ }], keyboardValueAccepted: [{
229
+ type: Output
230
+ }], showKeyboardChange: [{
231
+ type: Output
232
+ }] } });
322
233
 
323
- /**
324
- * @fileoverview added by tsickle
325
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
326
- */
327
- class VirtualKeyboardModule {
328
- }
329
- VirtualKeyboardModule.decorators = [
330
- { type: NgModule, args: [{
331
- declarations: [VirtualKeyboardDirective],
332
- exports: [VirtualKeyboardDirective]
333
- },] }
334
- ];
234
+ class VirtualKeyboardModule {
235
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: VirtualKeyboardModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
236
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: VirtualKeyboardModule, declarations: [VirtualKeyboardDirective], exports: [VirtualKeyboardDirective] });
237
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: VirtualKeyboardModule });
238
+ }
239
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: VirtualKeyboardModule, decorators: [{
240
+ type: NgModule,
241
+ args: [{
242
+ declarations: [VirtualKeyboardDirective],
243
+ exports: [VirtualKeyboardDirective]
244
+ }]
245
+ }] });
335
246
 
336
- /**
337
- * @fileoverview added by tsickle
338
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
247
+ /*
248
+ * Public API Surface of virtual-keyboard
339
249
  */
340
250
 
341
- /**
342
- * @fileoverview added by tsickle
343
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
251
+ /**
252
+ * Generated bundle index. Do not edit.
344
253
  */
345
254
 
346
- export { VirtualKeyboardModule, VirtualKeyboardDirective as ɵa };
347
-
348
- //# sourceMappingURL=sam-senior-virtual-keyboard.js.map
255
+ export { VirtualKeyboardDirective, VirtualKeyboardModule };
256
+ //# sourceMappingURL=sam-senior-virtual-keyboard.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sam-senior-virtual-keyboard.mjs","sources":["../../../projects/sam-virtual-keyboard/src/lib/virtual-keyboard.directive.ts","../../../projects/sam-virtual-keyboard/src/lib/virtual-keyboard.module.ts","../../../projects/sam-virtual-keyboard/src/public_api.ts","../../../projects/sam-virtual-keyboard/src/sam-senior-virtual-keyboard.ts"],"sourcesContent":["import { Directive, OnDestroy, OnChanges, ElementRef, Optional, Input, Output, EventEmitter } from '@angular/core';\r\nimport { NgControl } from '@angular/forms';\r\n\r\nimport { KeyboardOptions } from 'virtual-keyboard';\r\n\r\n/***************************************************************\r\n* Método que retonar instancia do elemento jQuery, pois\r\n* o projeto que implementa esta diretiva fica fora da lib.\r\n* Devido ficar fora, o webpack não ficará aqui, portando não\r\n* tem jQuery na lib;\r\n****************************************************************/\r\nconst jQueryInstance = (element) => {\r\n const windowInstance = window as any;\r\n return windowInstance.jQuery ? windowInstance.jQuery(element) : null;\r\n};\r\n\r\n@Directive({\r\n selector: '[samVirtualKeyboard]'\r\n})\r\nexport class VirtualKeyboardDirective\r\n implements OnDestroy, OnChanges {\r\n\r\n @Input() private keyboardPosition: 'relative' | 'bottom' = 'bottom';\r\n @Input() private keyboardType: 'email' | 'alphanumeric' = 'email';\r\n @Input() public set activateKeyboard(activateKeyboard: boolean) {\r\n if (activateKeyboard) {\r\n this.keyboardElement = this.elementRef.nativeElement as HTMLElement;\r\n this.keyboardjQueryElement = jQueryInstance(this.keyboardElement);\r\n if (this.keyboardjQueryElement) {\r\n this.keyboardjQueryElement.keyboard(this.createKeyboardOptions());\r\n }\r\n }\r\n }\r\n @Input() private showOnFocus = true;\r\n @Input()\r\n public get showKeyboard(): boolean {\r\n return this._showKeyboard;\r\n }\r\n public set showKeyboard(revealKeyboard: boolean) {\r\n this._showKeyboard = revealKeyboard;\r\n this.showKeyboardChange.emit(this._showKeyboard);\r\n }\r\n\r\n @Output() private keyboardValueAccepted = new EventEmitter();\r\n @Output() public showKeyboardChange = new EventEmitter<boolean>();\r\n\r\n public _showKeyboard = false;\r\n private keyboardElement: HTMLElement;\r\n private value = '';\r\n\r\n // Any devido a ser referência do jQuery;\r\n private keyboardjQueryElement: any;\r\n\r\n constructor(\r\n public elementRef: ElementRef,\r\n @Optional() public fieldControl: NgControl\r\n ) { }\r\n\r\n ngOnChanges() {\r\n if (this.showKeyboard && this.isKeyboardCreated()) {\r\n this.keyboardjQueryElement.getkeyboard().reveal();\r\n }\r\n }\r\n\r\n ngOnDestroy() {\r\n if (this.isKeyboardCreated()) {\r\n this.keyboardjQueryElement\r\n .keyboard()\r\n .getkeyboard()\r\n .destroy();\r\n }\r\n }\r\n\r\n private isKeyboardCreated(): boolean {\r\n return (\r\n this.keyboardjQueryElement &&\r\n this.keyboardjQueryElement.keyboard() &&\r\n this.keyboardjQueryElement.keyboard().getkeyboard()\r\n );\r\n }\r\n\r\n private getDefaultKeyboardOptions() {\r\n const keyboardOptions = {} as KeyboardOptions;\r\n if (!this.showOnFocus) {\r\n keyboardOptions.openOn = '';\r\n }\r\n keyboardOptions.usePreview = false;\r\n keyboardOptions.accepted = this.onValueAccepted.bind(this);\r\n keyboardOptions.visible = this.onKeyboardVisible.bind(this);\r\n keyboardOptions.beforeClose = this.onBeforeClose.bind(this);\r\n keyboardOptions.change = this.onChange.bind(this);\r\n return keyboardOptions;\r\n }\r\n\r\n private getKeyboardDisplayOptions() {\r\n return {\r\n bksp: '\\u2190',\r\n normal: 'ABC',\r\n meta1: '%?@',\r\n meta2: '#+=',\r\n accept: 'OK'\r\n };\r\n }\r\n\r\n private getKeyboardLayout() {\r\n let customLayout = {};\r\n if (this.keyboardType === 'alphanumeric') {\r\n customLayout = {\r\n normal: [\r\n '1 2 3 4 5 6 7 8 9 0',\r\n 'Q W E R T Y U I O P {bksp}',\r\n 'A S D F G H J K L Ç',\r\n 'Z X C V B N M {accept}'\r\n ]\r\n };\r\n } else if (this.keyboardType === 'email') {\r\n customLayout = this.getCustomKeyboardForEmail();\r\n }\r\n return customLayout;\r\n }\r\n\r\n private getCustomKeyboardForEmail() {\r\n return {\r\n normal: [\r\n '1 2 3 4 5 6 7 8 9 0',\r\n 'q w e r t y u i o p {bksp}',\r\n 'a s d f g h j k l ç',\r\n '{s} z x c v b n m .',\r\n '{meta1} {space} _ - {accept}'\r\n ],\r\n shift: [\r\n '1 2 3 4 5 6 7 8 9 0',\r\n 'Q W E R T Y U I O P {bksp}',\r\n 'A S D F G H J K L Ç',\r\n '{s} Z X C V B N M .',\r\n '{meta1} {space} _ - {accept}'\r\n ],\r\n meta1: [\r\n \"` | { } % ^ * / ' {bksp}\",\r\n '{meta2} $ & ~ # = + @',\r\n '{normal} {space} ! ? {accept}'\r\n ],\r\n meta2: [\r\n '[ ] { } \\u2039 \\u203a ^ * \" , {bksp}',\r\n '\\\\ | / < > $ \\u00a3 \\u00a5 \\u2022',\r\n '{meta1} \\u20ac & ~ # = + .',\r\n '{normal} {space} ! ? {accept}'\r\n ]\r\n };\r\n }\r\n\r\n private createKeyboardOptions(): KeyboardOptions {\r\n const keyboardOptions = this.getDefaultKeyboardOptions();\r\n if (this.keyboardPosition !== 'relative') {\r\n keyboardOptions.position = false;\r\n }\r\n if (this.keyboardPosition === 'bottom') {\r\n this.addBottomKeyboardClass();\r\n }\r\n keyboardOptions.css = {\r\n buttonDefault: 'keyboard-button-override'\r\n };\r\n\r\n keyboardOptions.display = this.getKeyboardDisplayOptions();\r\n keyboardOptions.layout = 'custom';\r\n keyboardOptions.customLayout = this.getKeyboardLayout();\r\n\r\n return keyboardOptions;\r\n }\r\n\r\n private onKeyboardVisible() {\r\n this.addCustomKeyboardFocusClass();\r\n }\r\n\r\n private onBeforeClose() {\r\n // O elemente do jQuery limpa tudo o que não passou pelo accept\r\n // Necessário setar o valor quando somente fechado a modal.\r\n const formControl = this.fieldControl.control;\r\n formControl.setValue(this.value);\r\n this.showKeyboard = false;\r\n }\r\n\r\n private onValueAccepted() {\r\n const casted = this.keyboardElement as any;\r\n this.keyboardValueAccepted.emit(casted.value);\r\n }\r\n\r\n private onChange(event) {\r\n const virtualkeyboardevent = new CustomEvent('virtualkeyboardevent', event);\r\n document.dispatchEvent(virtualkeyboardevent);\r\n if (this.keyboardElement instanceof HTMLInputElement) {\r\n const keyboardElement = this.keyboardElement as HTMLInputElement;\r\n // Arquivo possui referecia do jQuery que é alterado ao fechar o teclado.\r\n // Necessário clonar a string.\r\n const inputVal = JSON.stringify(keyboardElement.value).replace('\"', '').replace('\"', '');\r\n if (this.fieldControl) {\r\n const formControl = this.fieldControl.control;\r\n this.value = inputVal;\r\n formControl.setValue(inputVal);\r\n formControl.markAsDirty();\r\n formControl.updateValueAndValidity();\r\n }\r\n // Este setTimeout é necessário para fazer com que o\r\n // cursor do input sempre esteja no final da string digitada\r\n // e o final da string sempre esteja visivel.\r\n setTimeout(() => {\r\n keyboardElement.value = inputVal;\r\n keyboardElement.scrollLeft = keyboardElement.scrollWidth;\r\n });\r\n }\r\n }\r\n\r\n private addBottomKeyboardClass() {\r\n this.injectCssRule(\r\n `.ui-keyboard {\r\n border-radius: 0;\r\n left: 0;\r\n top: auto;\r\n bottom: 0;\r\n position: fixed;\r\n width: 100%;\r\n }`\r\n );\r\n }\r\n\r\n private addCustomKeyboardFocusClass() {\r\n this.injectCssRule(\r\n `.ui-keyboard-has-focus {\r\n z-index: 900;\r\n }`\r\n );\r\n }\r\n\r\n private injectCssRule(rule) {\r\n const style = document.createElement('style') as any;\r\n style.appendChild(document.createTextNode(''));\r\n document.head.appendChild(style);\r\n style.sheet.insertRule(rule);\r\n }\r\n}\r\n\r\n","import { NgModule } from '@angular/core';\r\nimport { VirtualKeyboardDirective } from './virtual-keyboard.directive';\r\n\r\n@NgModule({\r\n declarations: [VirtualKeyboardDirective],\r\n exports: [VirtualKeyboardDirective]\r\n})\r\nexport class VirtualKeyboardModule { }\r\n","/*\r\n * Public API Surface of virtual-keyboard\r\n */\r\nexport * from './lib/virtual-keyboard.directive';\r\nexport * from './lib/virtual-keyboard.module';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;AAKA;;;;;AAKiE;AACjE,MAAM,cAAc,GAAG,CAAC,OAAO,KAAI;IACjC,MAAM,cAAc,GAAG,MAAa,CAAC;AACrC,IAAA,OAAO,cAAc,CAAC,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;AACvE,CAAC,CAAC;MAKW,wBAAwB,CAAA;AAmC1B,IAAA,UAAA,CAAA;AACY,IAAA,YAAA,CAAA;IAjCJ,gBAAgB,GAA0B,QAAQ,CAAC;IACnD,YAAY,GAA6B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