ngx-touch-keyboard 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.
- package/README.md +86 -0
- package/karma.conf.js +44 -0
- package/ng-package.json +7 -0
- package/package.json +35 -0
- package/src/lib/layouts/index.ts +132 -0
- package/src/lib/layouts/layouts.type.ts +7 -0
- package/src/lib/ngx-touch-keyboard.component.html +26 -0
- package/src/lib/ngx-touch-keyboard.component.scss +103 -0
- package/src/lib/ngx-touch-keyboard.component.spec.ts +22 -0
- package/src/lib/ngx-touch-keyboard.component.ts +723 -0
- package/src/lib/ngx-touch-keyboard.directive.ts +164 -0
- package/src/lib/ngx-touch-keyboard.module.ts +14 -0
- package/src/public-api.ts +7 -0
- package/src/test.ts +27 -0
- package/tsconfig.lib.json +15 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComponentRef,
|
|
3
|
+
Directive,
|
|
4
|
+
ElementRef,
|
|
5
|
+
Inject,
|
|
6
|
+
OnDestroy,
|
|
7
|
+
} from '@angular/core';
|
|
8
|
+
import { DOCUMENT } from '@angular/common';
|
|
9
|
+
import { ComponentPortal } from '@angular/cdk/portal';
|
|
10
|
+
import { Overlay, OverlayRef, OverlaySizeConfig } from '@angular/cdk/overlay';
|
|
11
|
+
import { NgxTouchKeyboardComponent } from './ngx-touch-keyboard.component';
|
|
12
|
+
|
|
13
|
+
@Directive({
|
|
14
|
+
selector: 'input[ngxTouchKeyboard], textarea[ngxTouchKeyboard]',
|
|
15
|
+
exportAs: 'ngxTouchKeyboard',
|
|
16
|
+
})
|
|
17
|
+
export class NgxTouchKeyboardDirective implements OnDestroy {
|
|
18
|
+
isOpen = false;
|
|
19
|
+
|
|
20
|
+
private _overlayRef!: OverlayRef;
|
|
21
|
+
private _panelRef!: ComponentRef<NgxTouchKeyboardComponent>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Constructor
|
|
25
|
+
*/
|
|
26
|
+
constructor(
|
|
27
|
+
private _overlay: Overlay,
|
|
28
|
+
private _elementRef: ElementRef<HTMLInputElement>,
|
|
29
|
+
@Inject(DOCUMENT) private _document: any
|
|
30
|
+
) {}
|
|
31
|
+
|
|
32
|
+
// -----------------------------------------------------------------------------------------------------
|
|
33
|
+
// @ Lifecycle hooks
|
|
34
|
+
// -----------------------------------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* On destroy
|
|
38
|
+
*/
|
|
39
|
+
ngOnDestroy(): void {
|
|
40
|
+
// Dispose the overlay
|
|
41
|
+
if (this._overlayRef) {
|
|
42
|
+
this._overlayRef.dispose();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// -----------------------------------------------------------------------------------------------------
|
|
47
|
+
// @ Public methods
|
|
48
|
+
// -----------------------------------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Open keyboard panel
|
|
52
|
+
*/
|
|
53
|
+
openPanel(): void {
|
|
54
|
+
// return if panel is attached
|
|
55
|
+
if (this._overlayRef?.hasAttached()) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Create the overlay if it doesn't exist
|
|
60
|
+
if (!this._overlayRef) {
|
|
61
|
+
this._createOverlay();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Update direction and size the overlay
|
|
65
|
+
this._overlayRef.setDirection(this._document.body.getAttribute('dir'));
|
|
66
|
+
this._overlayRef.updateSize({
|
|
67
|
+
width: this._inputOrigin().getBoundingClientRect().width,
|
|
68
|
+
maxWidth: this._inputOrigin().getBoundingClientRect().width,
|
|
69
|
+
minWidth: '260px',
|
|
70
|
+
} as OverlaySizeConfig);
|
|
71
|
+
|
|
72
|
+
// Attach the portal to the overlay
|
|
73
|
+
this._panelRef = this._overlayRef.attach(
|
|
74
|
+
new ComponentPortal(NgxTouchKeyboardComponent)
|
|
75
|
+
);
|
|
76
|
+
this._panelRef.instance.setActiveInput(this._elementRef.nativeElement);
|
|
77
|
+
this.isOpen = true;
|
|
78
|
+
|
|
79
|
+
// Reference the input element
|
|
80
|
+
this._panelRef.instance.closePanel.subscribe(() => this.closePanel());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Close keyboard panel
|
|
85
|
+
*/
|
|
86
|
+
closePanel(): void {
|
|
87
|
+
this._overlayRef.detach();
|
|
88
|
+
this.isOpen = false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Toggle keyboard panel
|
|
93
|
+
*/
|
|
94
|
+
togglePanel(): void {
|
|
95
|
+
if (this.isOpen) {
|
|
96
|
+
this.closePanel();
|
|
97
|
+
} else {
|
|
98
|
+
this.openPanel();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// -----------------------------------------------------------------------------------------------------
|
|
103
|
+
// @ Private methods
|
|
104
|
+
// -----------------------------------------------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Create the overlay
|
|
108
|
+
*/
|
|
109
|
+
private _createOverlay(): void {
|
|
110
|
+
// Create the overlay
|
|
111
|
+
this._overlayRef = this._overlay.create({
|
|
112
|
+
hasBackdrop: false,
|
|
113
|
+
scrollStrategy: this._overlay.scrollStrategies.noop(),
|
|
114
|
+
positionStrategy: this._overlay
|
|
115
|
+
.position()
|
|
116
|
+
.flexibleConnectedTo(this._inputOrigin())
|
|
117
|
+
.withLockedPosition(true)
|
|
118
|
+
.withPush(true)
|
|
119
|
+
.withPositions([
|
|
120
|
+
{
|
|
121
|
+
originX: 'start',
|
|
122
|
+
originY: 'bottom',
|
|
123
|
+
overlayX: 'start',
|
|
124
|
+
overlayY: 'top',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
originX: 'start',
|
|
128
|
+
originY: 'top',
|
|
129
|
+
overlayX: 'start',
|
|
130
|
+
overlayY: 'bottom',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
originX: 'end',
|
|
134
|
+
originY: 'bottom',
|
|
135
|
+
overlayX: 'end',
|
|
136
|
+
overlayY: 'top',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
originX: 'end',
|
|
140
|
+
originY: 'top',
|
|
141
|
+
overlayX: 'end',
|
|
142
|
+
overlayY: 'bottom',
|
|
143
|
+
},
|
|
144
|
+
]),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get input origin
|
|
150
|
+
*
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
private _inputOrigin(): any {
|
|
154
|
+
const element = this._elementRef.nativeElement;
|
|
155
|
+
// Material form field - Check input in mat-form-field
|
|
156
|
+
if (element.classList.contains('mat-input-element')) {
|
|
157
|
+
// Return [mat-form-field-flex] element
|
|
158
|
+
return element.parentNode?.parentNode;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Return input
|
|
162
|
+
return element;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { OverlayModule } from '@angular/cdk/overlay';
|
|
4
|
+
import { PortalModule } from '@angular/cdk/portal';
|
|
5
|
+
|
|
6
|
+
import { NgxTouchKeyboardDirective } from './ngx-touch-keyboard.directive';
|
|
7
|
+
import { NgxTouchKeyboardComponent } from './ngx-touch-keyboard.component';
|
|
8
|
+
|
|
9
|
+
@NgModule({
|
|
10
|
+
declarations: [NgxTouchKeyboardDirective, NgxTouchKeyboardComponent],
|
|
11
|
+
imports: [CommonModule, OverlayModule, PortalModule],
|
|
12
|
+
exports: [NgxTouchKeyboardDirective, NgxTouchKeyboardComponent],
|
|
13
|
+
})
|
|
14
|
+
export class NgxTouchKeyboardModule {}
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
+
|
|
3
|
+
import 'zone.js';
|
|
4
|
+
import 'zone.js/testing';
|
|
5
|
+
import { getTestBed } from '@angular/core/testing';
|
|
6
|
+
import {
|
|
7
|
+
BrowserDynamicTestingModule,
|
|
8
|
+
platformBrowserDynamicTesting
|
|
9
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
10
|
+
|
|
11
|
+
declare const require: {
|
|
12
|
+
context(path: string, deep?: boolean, filter?: RegExp): {
|
|
13
|
+
<T>(id: string): T;
|
|
14
|
+
keys(): string[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// First, initialize the Angular testing environment.
|
|
19
|
+
getTestBed().initTestEnvironment(
|
|
20
|
+
BrowserDynamicTestingModule,
|
|
21
|
+
platformBrowserDynamicTesting(),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Then we find all the tests.
|
|
25
|
+
const context = require.context('./', true, /\.spec\.ts$/);
|
|
26
|
+
// And load the modules.
|
|
27
|
+
context.keys().forEach(context);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/lib",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"inlineSources": true,
|
|
9
|
+
"types": []
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"src/test.ts",
|
|
13
|
+
"**/*.spec.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/spec",
|
|
6
|
+
"types": [
|
|
7
|
+
"jasmine"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src/test.ts"
|
|
12
|
+
],
|
|
13
|
+
"include": [
|
|
14
|
+
"**/*.spec.ts",
|
|
15
|
+
"**/*.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|