cmat 0.0.111 → 0.0.113

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.
Files changed (256) hide show
  1. package/fesm2022/cmat-components-adapter.mjs +531 -536
  2. package/fesm2022/cmat-components-adapter.mjs.map +1 -1
  3. package/fesm2022/cmat-components-breadcrumb.mjs +521 -356
  4. package/fesm2022/cmat-components-breadcrumb.mjs.map +1 -1
  5. package/fesm2022/cmat-components-card.mjs +150 -42
  6. package/fesm2022/cmat-components-card.mjs.map +1 -1
  7. package/fesm2022/cmat-components-carousel.mjs +1120 -629
  8. package/fesm2022/cmat-components-carousel.mjs.map +1 -1
  9. package/fesm2022/cmat-components-cascade.mjs +861 -441
  10. package/fesm2022/cmat-components-cascade.mjs.map +1 -1
  11. package/fesm2022/cmat-components-chip-input.mjs +580 -335
  12. package/fesm2022/cmat-components-chip-input.mjs.map +1 -1
  13. package/fesm2022/cmat-components-code-editor.mjs +197 -105
  14. package/fesm2022/cmat-components-code-editor.mjs.map +1 -1
  15. package/fesm2022/cmat-components-color-picker.mjs +1762 -825
  16. package/fesm2022/cmat-components-color-picker.mjs.map +1 -1
  17. package/fesm2022/cmat-components-custom-formly.mjs +5196 -2531
  18. package/fesm2022/cmat-components-custom-formly.mjs.map +1 -1
  19. package/fesm2022/cmat-components-data-picker.mjs +1901 -1073
  20. package/fesm2022/cmat-components-data-picker.mjs.map +1 -1
  21. package/fesm2022/cmat-components-date-range.mjs +701 -456
  22. package/fesm2022/cmat-components-date-range.mjs.map +1 -1
  23. package/fesm2022/cmat-components-date-time-display.mjs +137 -30
  24. package/fesm2022/cmat-components-date-time-display.mjs.map +1 -1
  25. package/fesm2022/cmat-components-drawer.mjs +410 -258
  26. package/fesm2022/cmat-components-drawer.mjs.map +1 -1
  27. package/fesm2022/cmat-components-empty-state.mjs +201 -41
  28. package/fesm2022/cmat-components-empty-state.mjs.map +1 -1
  29. package/fesm2022/cmat-components-file-preview.mjs +198 -35
  30. package/fesm2022/cmat-components-file-preview.mjs.map +1 -1
  31. package/fesm2022/cmat-components-filter-toolbar.mjs +320 -72
  32. package/fesm2022/cmat-components-filter-toolbar.mjs.map +1 -1
  33. package/fesm2022/cmat-components-form-actions.mjs +102 -26
  34. package/fesm2022/cmat-components-form-actions.mjs.map +1 -1
  35. package/fesm2022/cmat-components-fullscreen.mjs +167 -47
  36. package/fesm2022/cmat-components-fullscreen.mjs.map +1 -1
  37. package/fesm2022/cmat-components-highlight.mjs +203 -112
  38. package/fesm2022/cmat-components-highlight.mjs.map +1 -1
  39. package/fesm2022/cmat-components-image-viewer.mjs +489 -215
  40. package/fesm2022/cmat-components-image-viewer.mjs.map +1 -1
  41. package/fesm2022/cmat-components-inline-loading.mjs +117 -27
  42. package/fesm2022/cmat-components-inline-loading.mjs.map +1 -1
  43. package/fesm2022/cmat-components-json-editor.mjs +276 -230
  44. package/fesm2022/cmat-components-json-editor.mjs.map +1 -1
  45. package/fesm2022/cmat-components-knob-input.mjs +615 -420
  46. package/fesm2022/cmat-components-knob-input.mjs.map +1 -1
  47. package/fesm2022/cmat-components-loading-overlay.mjs +53 -25
  48. package/fesm2022/cmat-components-loading-overlay.mjs.map +1 -1
  49. package/fesm2022/cmat-components-masonry.mjs +120 -40
  50. package/fesm2022/cmat-components-masonry.mjs.map +1 -1
  51. package/fesm2022/cmat-components-material-color-picker.mjs +332 -155
  52. package/fesm2022/cmat-components-material-color-picker.mjs.map +1 -1
  53. package/fesm2022/cmat-components-material-datetimepicker.mjs +4283 -2504
  54. package/fesm2022/cmat-components-material-datetimepicker.mjs.map +1 -1
  55. package/fesm2022/cmat-components-navigation.mjs +3080 -1404
  56. package/fesm2022/cmat-components-navigation.mjs.map +1 -1
  57. package/fesm2022/cmat-components-opt-input.mjs +540 -466
  58. package/fesm2022/cmat-components-opt-input.mjs.map +1 -1
  59. package/fesm2022/cmat-components-org-chart.mjs +528 -125
  60. package/fesm2022/cmat-components-org-chart.mjs.map +1 -1
  61. package/fesm2022/cmat-components-page-header.mjs +141 -32
  62. package/fesm2022/cmat-components-page-header.mjs.map +1 -1
  63. package/fesm2022/cmat-components-pagination.mjs +866 -534
  64. package/fesm2022/cmat-components-pagination.mjs.map +1 -1
  65. package/fesm2022/cmat-components-password-strength.mjs +873 -434
  66. package/fesm2022/cmat-components-password-strength.mjs.map +1 -1
  67. package/fesm2022/cmat-components-popover.mjs +1012 -731
  68. package/fesm2022/cmat-components-popover.mjs.map +1 -1
  69. package/fesm2022/cmat-components-progress-bar.mjs +98 -35
  70. package/fesm2022/cmat-components-progress-bar.mjs.map +1 -1
  71. package/fesm2022/cmat-components-qrcode.mjs +463 -287
  72. package/fesm2022/cmat-components-qrcode.mjs.map +1 -1
  73. package/fesm2022/cmat-components-rating.mjs +377 -203
  74. package/fesm2022/cmat-components-rating.mjs.map +1 -1
  75. package/fesm2022/cmat-components-rich-text-editor.mjs +153 -39
  76. package/fesm2022/cmat-components-rich-text-editor.mjs.map +1 -1
  77. package/fesm2022/cmat-components-select-search.mjs +926 -496
  78. package/fesm2022/cmat-components-select-search.mjs.map +1 -1
  79. package/fesm2022/cmat-components-select-table.mjs +1280 -842
  80. package/fesm2022/cmat-components-select-table.mjs.map +1 -1
  81. package/fesm2022/cmat-components-select-tree.mjs +998 -690
  82. package/fesm2022/cmat-components-select-tree.mjs.map +1 -1
  83. package/fesm2022/cmat-components-skeleton.mjs +143 -57
  84. package/fesm2022/cmat-components-skeleton.mjs.map +1 -1
  85. package/fesm2022/cmat-components-speed-dial.mjs +457 -303
  86. package/fesm2022/cmat-components-speed-dial.mjs.map +1 -1
  87. package/fesm2022/cmat-components-status-tag.mjs +136 -44
  88. package/fesm2022/cmat-components-status-tag.mjs.map +1 -1
  89. package/fesm2022/cmat-components-table-toolbar.mjs +120 -28
  90. package/fesm2022/cmat-components-table-toolbar.mjs.map +1 -1
  91. package/fesm2022/cmat-components-timeline.mjs +464 -168
  92. package/fesm2022/cmat-components-timeline.mjs.map +1 -1
  93. package/fesm2022/cmat-components-toast.mjs +346 -262
  94. package/fesm2022/cmat-components-toast.mjs.map +1 -1
  95. package/fesm2022/cmat-components-transfer-picker.mjs +1427 -593
  96. package/fesm2022/cmat-components-transfer-picker.mjs.map +1 -1
  97. package/fesm2022/cmat-components-treetable.mjs +372 -112
  98. package/fesm2022/cmat-components-treetable.mjs.map +1 -1
  99. package/fesm2022/cmat-components-upload.mjs +904 -410
  100. package/fesm2022/cmat-components-upload.mjs.map +1 -1
  101. package/fesm2022/cmat-components-x6-angular-shape.mjs +153 -170
  102. package/fesm2022/cmat-components-x6-angular-shape.mjs.map +1 -1
  103. package/fesm2022/cmat-directives-animate-on-scroll.mjs +220 -138
  104. package/fesm2022/cmat-directives-animate-on-scroll.mjs.map +1 -1
  105. package/fesm2022/cmat-directives-arrow-cursor.mjs +246 -193
  106. package/fesm2022/cmat-directives-arrow-cursor.mjs.map +1 -1
  107. package/fesm2022/cmat-directives-autofocus.mjs +43 -25
  108. package/fesm2022/cmat-directives-autofocus.mjs.map +1 -1
  109. package/fesm2022/cmat-directives-data-exporter.mjs +537 -338
  110. package/fesm2022/cmat-directives-data-exporter.mjs.map +1 -1
  111. package/fesm2022/cmat-directives-debounce.mjs +162 -76
  112. package/fesm2022/cmat-directives-debounce.mjs.map +1 -1
  113. package/fesm2022/cmat-directives-digit-only.mjs +457 -356
  114. package/fesm2022/cmat-directives-digit-only.mjs.map +1 -1
  115. package/fesm2022/cmat-directives-equal-validator.mjs +70 -53
  116. package/fesm2022/cmat-directives-equal-validator.mjs.map +1 -1
  117. package/fesm2022/cmat-directives-seamless-auto-scroll.mjs +180 -132
  118. package/fesm2022/cmat-directives-seamless-auto-scroll.mjs.map +1 -1
  119. package/fesm2022/cmat-lib-mock-api.mjs +207 -195
  120. package/fesm2022/cmat-lib-mock-api.mjs.map +1 -1
  121. package/fesm2022/cmat-pipes-bytes.mjs +50 -30
  122. package/fesm2022/cmat-pipes-bytes.mjs.map +1 -1
  123. package/fesm2022/cmat-pipes-date-format.mjs +41 -25
  124. package/fesm2022/cmat-pipes-date-format.mjs.map +1 -1
  125. package/fesm2022/cmat-pipes-find-by-key.mjs +44 -26
  126. package/fesm2022/cmat-pipes-find-by-key.mjs.map +1 -1
  127. package/fesm2022/cmat-pipes-group-by.mjs +50 -38
  128. package/fesm2022/cmat-pipes-group-by.mjs.map +1 -1
  129. package/fesm2022/cmat-pipes-keys.mjs +44 -31
  130. package/fesm2022/cmat-pipes-keys.mjs.map +1 -1
  131. package/fesm2022/cmat-pipes-secure.mjs +60 -49
  132. package/fesm2022/cmat-pipes-secure.mjs.map +1 -1
  133. package/fesm2022/cmat-pipes-uppercase.mjs +39 -22
  134. package/fesm2022/cmat-pipes-uppercase.mjs.map +1 -1
  135. package/fesm2022/cmat-reports.mjs +2761 -0
  136. package/fesm2022/cmat-reports.mjs.map +1 -0
  137. package/fesm2022/cmat-services-alert.mjs +249 -277
  138. package/fesm2022/cmat-services-alert.mjs.map +1 -1
  139. package/fesm2022/cmat-services-config.mjs +110 -81
  140. package/fesm2022/cmat-services-config.mjs.map +1 -1
  141. package/fesm2022/cmat-services-confirmation.mjs +184 -73
  142. package/fesm2022/cmat-services-confirmation.mjs.map +1 -1
  143. package/fesm2022/cmat-services-data.mjs +136 -125
  144. package/fesm2022/cmat-services-data.mjs.map +1 -1
  145. package/fesm2022/cmat-services-export-as.mjs +165 -183
  146. package/fesm2022/cmat-services-export-as.mjs.map +1 -1
  147. package/fesm2022/cmat-services-loading.mjs +116 -95
  148. package/fesm2022/cmat-services-loading.mjs.map +1 -1
  149. package/fesm2022/cmat-services-local-storage.mjs +75 -66
  150. package/fesm2022/cmat-services-local-storage.mjs.map +1 -1
  151. package/fesm2022/cmat-services-media-watcher.mjs +69 -64
  152. package/fesm2022/cmat-services-media-watcher.mjs.map +1 -1
  153. package/fesm2022/cmat-services-platform.mjs +48 -45
  154. package/fesm2022/cmat-services-platform.mjs.map +1 -1
  155. package/fesm2022/cmat-services-print.mjs +984 -1109
  156. package/fesm2022/cmat-services-print.mjs.map +1 -1
  157. package/fesm2022/cmat-services-splash-screen.mjs +53 -38
  158. package/fesm2022/cmat-services-splash-screen.mjs.map +1 -1
  159. package/fesm2022/cmat-services-title.mjs +57 -47
  160. package/fesm2022/cmat-services-title.mjs.map +1 -1
  161. package/fesm2022/cmat-services-translation.mjs +79 -68
  162. package/fesm2022/cmat-services-translation.mjs.map +1 -1
  163. package/fesm2022/cmat-services-utils.mjs +424 -517
  164. package/fesm2022/cmat-services-utils.mjs.map +1 -1
  165. package/fesm2022/cmat-validators.mjs +23 -33
  166. package/fesm2022/cmat-validators.mjs.map +1 -1
  167. package/fesm2022/cmat-version.mjs +12 -16
  168. package/fesm2022/cmat-version.mjs.map +1 -1
  169. package/fesm2022/cmat.mjs +39805 -22511
  170. package/fesm2022/cmat.mjs.map +1 -1
  171. package/package.json +5 -1
  172. package/types/cmat-components-adapter.d.ts +145 -156
  173. package/types/cmat-components-breadcrumb.d.ts +108 -86
  174. package/types/cmat-components-card.d.ts +34 -18
  175. package/types/cmat-components-carousel.d.ts +251 -134
  176. package/types/cmat-components-cascade.d.ts +158 -117
  177. package/types/cmat-components-chip-input.d.ts +105 -71
  178. package/types/cmat-components-code-editor.d.ts +59 -34
  179. package/types/cmat-components-color-picker.d.ts +378 -236
  180. package/types/cmat-components-custom-formly.d.ts +776 -814
  181. package/types/cmat-components-data-picker.d.ts +502 -360
  182. package/types/cmat-components-date-range.d.ts +106 -77
  183. package/types/cmat-components-date-time-display.d.ts +36 -13
  184. package/types/cmat-components-drawer.d.ts +91 -61
  185. package/types/cmat-components-empty-state.d.ts +47 -17
  186. package/types/cmat-components-file-preview.d.ts +42 -14
  187. package/types/cmat-components-filter-toolbar.d.ts +57 -25
  188. package/types/cmat-components-form-actions.d.ts +18 -10
  189. package/types/cmat-components-fullscreen.d.ts +21 -13
  190. package/types/cmat-components-highlight.d.ts +33 -26
  191. package/types/cmat-components-image-viewer.d.ts +119 -58
  192. package/types/cmat-components-inline-loading.d.ts +24 -11
  193. package/types/cmat-components-json-editor.d.ts +39 -28
  194. package/types/cmat-components-knob-input.d.ts +172 -101
  195. package/types/cmat-components-loading-overlay.d.ts +8 -11
  196. package/types/cmat-components-masonry.d.ts +27 -14
  197. package/types/cmat-components-material-color-picker.d.ts +56 -42
  198. package/types/cmat-components-material-datetimepicker.d.ts +817 -454
  199. package/types/cmat-components-navigation.d.ts +295 -221
  200. package/types/cmat-components-opt-input.d.ts +111 -90
  201. package/types/cmat-components-org-chart.d.ts +53 -35
  202. package/types/cmat-components-page-header.d.ts +37 -14
  203. package/types/cmat-components-pagination.d.ts +144 -107
  204. package/types/cmat-components-password-strength.d.ts +197 -86
  205. package/types/cmat-components-popover.d.ts +264 -166
  206. package/types/cmat-components-progress-bar.d.ts +17 -14
  207. package/types/cmat-components-qrcode.d.ts +111 -42
  208. package/types/cmat-components-rating.d.ts +105 -59
  209. package/types/cmat-components-rich-text-editor.d.ts +39 -16
  210. package/types/cmat-components-select-search.d.ts +195 -99
  211. package/types/cmat-components-select-table.d.ts +241 -142
  212. package/types/cmat-components-select-tree.d.ts +185 -118
  213. package/types/cmat-components-skeleton.d.ts +55 -32
  214. package/types/cmat-components-speed-dial.d.ts +86 -61
  215. package/types/cmat-components-status-tag.d.ts +42 -24
  216. package/types/cmat-components-table-toolbar.d.ts +30 -12
  217. package/types/cmat-components-timeline.d.ts +83 -51
  218. package/types/cmat-components-toast.d.ts +84 -85
  219. package/types/cmat-components-transfer-picker.d.ts +228 -181
  220. package/types/cmat-components-treetable.d.ts +63 -39
  221. package/types/cmat-components-upload.d.ts +205 -106
  222. package/types/cmat-components-x6-angular-shape.d.ts +29 -37
  223. package/types/cmat-directives-animate-on-scroll.d.ts +48 -30
  224. package/types/cmat-directives-arrow-cursor.d.ts +55 -35
  225. package/types/cmat-directives-autofocus.d.ts +8 -11
  226. package/types/cmat-directives-data-exporter.d.ts +71 -40
  227. package/types/cmat-directives-debounce.d.ts +31 -28
  228. package/types/cmat-directives-digit-only.d.ts +90 -53
  229. package/types/cmat-directives-equal-validator.d.ts +11 -14
  230. package/types/cmat-directives-seamless-auto-scroll.d.ts +42 -29
  231. package/types/cmat-lib-mock-api.d.ts +46 -55
  232. package/types/cmat-pipes-bytes.d.ts +7 -10
  233. package/types/cmat-pipes-date-format.d.ts +7 -10
  234. package/types/cmat-pipes-find-by-key.d.ts +8 -12
  235. package/types/cmat-pipes-group-by.d.ts +11 -15
  236. package/types/cmat-pipes-keys.d.ts +10 -13
  237. package/types/cmat-pipes-secure.d.ts +14 -17
  238. package/types/cmat-pipes-uppercase.d.ts +7 -10
  239. package/types/cmat-reports.d.ts +1138 -0
  240. package/types/cmat-services-alert.d.ts +80 -87
  241. package/types/cmat-services-config.d.ts +37 -43
  242. package/types/cmat-services-confirmation.d.ts +31 -37
  243. package/types/cmat-services-data.d.ts +18 -21
  244. package/types/cmat-services-export-as.d.ts +28 -33
  245. package/types/cmat-services-loading.d.ts +27 -31
  246. package/types/cmat-services-local-storage.d.ts +17 -21
  247. package/types/cmat-services-media-watcher.d.ts +14 -18
  248. package/types/cmat-services-platform.d.ts +8 -11
  249. package/types/cmat-services-print.d.ts +97 -102
  250. package/types/cmat-services-splash-screen.d.ts +11 -14
  251. package/types/cmat-services-title.d.ts +9 -12
  252. package/types/cmat-services-translation.d.ts +19 -22
  253. package/types/cmat-services-utils.d.ts +76 -80
  254. package/types/cmat-validators.d.ts +5 -8
  255. package/types/cmat-version.d.ts +8 -10
  256. package/types/cmat.d.ts +7551 -5204
@@ -1,468 +1,542 @@
1
- import { coerceBooleanProperty } from '@angular/cdk/coercion';
2
- import * as i1 from '@angular/common';
3
- import { CommonModule } from '@angular/common';
4
- import * as i0 from '@angular/core';
5
- import { input, output, signal, computed, inject, DOCUMENT, DestroyRef, Input, ChangeDetectionStrategy, ViewEncapsulation, Component } from '@angular/core';
6
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
7
- import * as i2 from '@angular/forms';
8
- import { NgControl, FormBuilder, FormControl, ReactiveFormsModule } from '@angular/forms';
9
- import { MatFormFieldControl } from '@angular/material/form-field';
10
- import { Subject } from 'rxjs';
11
-
12
- class KeyboardUtil {
13
- static ifTab(event) {
14
- return this.ifKey(event, 'Tab');
15
- }
16
- static ifDelete(event) {
17
- return this.ifKey(event, 'Delete;Del');
18
- }
19
- static ifBackspace(event) {
20
- return this.ifKey(event, 'Backspace');
21
- }
22
- static ifRightArrow(event) {
23
- return this.ifKey(event, 'ArrowRight;Right');
24
- }
25
- static ifLeftArrow(event) {
26
- return this.ifKey(event, 'ArrowLeft;Left');
27
- }
28
- static ifSpacebar(event) {
29
- return this.ifKey(event, 'Spacebar; '); //don't remove the space after ; as this will check for space key
30
- }
31
- static ifKey(event, keys) {
32
- let keysToCheck = keys.split(';');
33
- return keysToCheck.some(k => k === event.key);
34
- }
35
- }
36
-
37
- /* eslint-disable @typescript-eslint/member-ordering */
1
+ import { coerceBooleanProperty } from "@angular/cdk/coercion";
2
+ import * as i1 from "@angular/common";
3
+ import { CommonModule } from "@angular/common";
4
+ import * as i0 from "@angular/core";
5
+ import { ChangeDetectionStrategy, Component, DOCUMENT, DestroyRef, Input, ViewEncapsulation, computed, inject, input, output, signal } from "@angular/core";
6
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
7
+ import * as i2 from "@angular/forms";
8
+ import { FormBuilder, FormControl, NgControl, ReactiveFormsModule } from "@angular/forms";
9
+ import { MatFormFieldControl } from "@angular/material/form-field";
10
+ import { Subject } from "rxjs";
11
+ var KeyboardUtil = class {
12
+ static ifTab(event) {
13
+ return this.ifKey(event, "Tab");
14
+ }
15
+ static ifDelete(event) {
16
+ return this.ifKey(event, "Delete;Del");
17
+ }
18
+ static ifBackspace(event) {
19
+ return this.ifKey(event, "Backspace");
20
+ }
21
+ static ifRightArrow(event) {
22
+ return this.ifKey(event, "ArrowRight;Right");
23
+ }
24
+ static ifLeftArrow(event) {
25
+ return this.ifKey(event, "ArrowLeft;Left");
26
+ }
27
+ static ifSpacebar(event) {
28
+ return this.ifKey(event, "Spacebar; ");
29
+ }
30
+ static ifKey(event, keys) {
31
+ return keys.split(";").some((k) => k === event.key);
32
+ }
33
+ };
38
34
  let NEXT_ID = 1;
39
- class CmatOtpInputComponent {
40
- get errorState() {
41
- if (this.ngControl == null)
42
- return false;
43
- return (this.ngControl.invalid && ((this.ngControl.dirty ?? false) || this.ngControl.touched)) ?? false;
44
- }
45
- constructor() {
46
- this.config = input({ length: 4 }, /* @ts-ignore */
47
- ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
48
- this.onBlur = output();
49
- this.onInputChange = output();
50
- this.id = `cmat-otp-input-${NEXT_ID}`;
51
- this.stateChanges = new Subject();
52
- this._placeholderSignal = signal('', /* @ts-ignore */
53
- ...(ngDevMode ? [{ debugName: "_placeholderSignal" }] : /* istanbul ignore next */ []));
54
- this._requiredSignal = signal(false, /* @ts-ignore */
55
- ...(ngDevMode ? [{ debugName: "_requiredSignal" }] : /* istanbul ignore next */ []));
56
- this._disabledSignal = signal(false, /* @ts-ignore */
57
- ...(ngDevMode ? [{ debugName: "_disabledSignal" }] : /* istanbul ignore next */ []));
58
- this._valueSignal = signal(null, /* @ts-ignore */
59
- ...(ngDevMode ? [{ debugName: "_valueSignal" }] : /* istanbul ignore next */ []));
60
- this._currentValSignal = signal(null, /* @ts-ignore */
61
- ...(ngDevMode ? [{ debugName: "_currentValSignal" }] : /* istanbul ignore next */ []));
62
- this._focused = false;
63
- this._activeFocusCount = 0;
64
- this.controlKeys = computed(() => Object.keys(this.otpForm?.controls ?? {}), /* @ts-ignore */
65
- ...(ngDevMode ? [{ debugName: "controlKeys" }] : /* istanbul ignore next */ []));
66
- this.inputType = computed(() => {
67
- const cfg = this.config();
68
- return cfg?.isPasswordInput
69
- ? 'password'
70
- : cfg?.allowNumbersOnly
71
- ? 'tel'
72
- : 'text';
73
- }, /* @ts-ignore */
74
- ...(ngDevMode ? [{ debugName: "inputType" }] : /* istanbul ignore next */ []));
75
- this.componentKey = (NEXT_ID++).toString(36);
76
- this.ngControl = inject(NgControl, { optional: true, self: true });
77
- this._document = inject(DOCUMENT);
78
- this._formBuilder = inject(FormBuilder);
79
- this._destroyRef = inject(DestroyRef);
80
- this._valueChangesSub = null;
81
- this._pendingTimeouts = [];
82
- this._onModelChange = () => { };
83
- this._onTouchedChange = () => { };
84
- this.otpForm = this._formBuilder.group({});
85
- if (this.ngControl != null) {
86
- this.ngControl.valueAccessor = this;
87
- }
88
- this._rebuildForm();
89
- }
90
- get placeholder() {
91
- return this._placeholderSignal();
92
- }
93
- set placeholder(value) {
94
- this._placeholderSignal.set(value);
95
- this.stateChanges.next();
96
- }
97
- get required() {
98
- return this._requiredSignal();
99
- }
100
- set required(value) {
101
- this._requiredSignal.set(coerceBooleanProperty(value));
102
- this.stateChanges.next();
103
- }
104
- get disabled() {
105
- if (!this.ngControl.disabled && this.ngControl.disabled !== null) {
106
- return this.ngControl.disabled;
107
- }
108
- return this._disabledSignal();
109
- }
110
- set disabled(value) {
111
- const isDisabled = coerceBooleanProperty(value);
112
- this._disabledSignal.set(isDisabled);
113
- this.setDisabledState(isDisabled);
114
- if (isDisabled && this._focused) {
115
- this._focused = false;
116
- this.stateChanges.next();
117
- }
118
- }
119
- get focused() {
120
- return this._focused;
121
- }
122
- get value() {
123
- return this._valueSignal();
124
- }
125
- set value(val) {
126
- const current = this._valueSignal();
127
- if (val !== current) {
128
- this._valueSignal.set(val);
129
- this.stateChanges.next();
130
- this._onModelChange(val);
131
- }
132
- }
133
- get empty() {
134
- return !this._valueSignal();
135
- }
136
- get shouldLabelFloat() {
137
- return this._focused || !this.empty;
138
- }
139
- setDisabledState(isDisabled) {
140
- if (this.otpForm) {
141
- if (isDisabled) {
142
- this.otpForm.disable({ emitEvent: false });
143
- }
144
- else {
145
- this.otpForm.enable({ emitEvent: false });
146
- }
147
- }
148
- this.stateChanges.next();
149
- }
150
- writeValue(value) {
151
- this._currentValSignal.set(value || null);
152
- if (this.otpForm && this._currentValSignal()) {
153
- this.setValue(this._currentValSignal());
154
- }
155
- }
156
- registerOnChange(fn) {
157
- this._onModelChange = fn;
158
- }
159
- registerOnTouched(fn) {
160
- this._onTouchedChange = fn;
161
- }
162
- onFocusIn() {
163
- this._onTouchedChange();
164
- this._activeFocusCount++;
165
- if (!this._focused) {
166
- this._focused = true;
167
- this.stateChanges.next();
168
- }
169
- }
170
- onFocusOut() {
171
- const timeoutId = setTimeout(() => {
172
- this._removePendingTimeout(timeoutId);
173
- this._activeFocusCount--;
174
- if (this._activeFocusCount === 0) {
175
- this._focused = false;
176
- this._onTouchedChange();
177
- this.onBlur.emit();
178
- this.stateChanges.next();
179
- }
180
- }, 0);
181
- this._pendingTimeouts.push(timeoutId);
182
- }
183
- ngAfterViewInit() {
184
- if (!this.config().disableAutoFocus) {
185
- const containerItem = this._document.getElementById(`c_${this.componentKey}`);
186
- if (containerItem) {
187
- const ele = containerItem.getElementsByClassName('cmat-otp-input')[0];
188
- if (ele?.focus) {
189
- ele.focus();
190
- }
191
- }
192
- }
193
- }
194
- ngOnDestroy() {
195
- this._pendingTimeouts.forEach(id => clearTimeout(id));
196
- this._pendingTimeouts = [];
197
- this._valueChangesSub?.unsubscribe();
198
- this._valueChangesSub = null;
199
- this.stateChanges.complete();
200
- this.otpForm.reset();
201
- }
202
- setDescribedByIds(ids) {
203
- this.userAriaDescribedBy = ids.length ? ids.join(' ') : undefined;
204
- const containerItem = this._document.getElementById(`c_${this.componentKey}`);
205
- if (containerItem) {
206
- if (ids.length) {
207
- containerItem.setAttribute('aria-describedby', ids.join(' '));
208
- }
209
- else {
210
- containerItem.removeAttribute('aria-describedby');
211
- }
212
- }
213
- this.stateChanges.next();
214
- }
215
- onContainerClick() {
216
- if (!this._focused) {
217
- const containerItem = this._document.getElementById(`c_${this.componentKey}`);
218
- if (containerItem) {
219
- containerItem.focus();
220
- }
221
- }
222
- }
223
- onKeyDown($event, inputIdx) {
224
- const inputTarget = $event.target;
225
- const prevInputId = this.getBoxId(inputIdx - 1);
226
- const currentInputId = this.getBoxId(inputIdx);
227
- const nextInputId = this.getBoxId(inputIdx + 1);
228
- if (KeyboardUtil.ifSpacebar($event)) {
229
- $event.preventDefault();
230
- return;
231
- }
232
- if (KeyboardUtil.ifBackspace($event)) {
233
- if (!inputTarget.value) {
234
- this._clearInput(prevInputId, inputIdx - 1);
235
- this._setSelected(prevInputId);
236
- }
237
- else {
238
- this._clearInput(currentInputId, inputIdx);
239
- }
240
- this._rebuildValue();
241
- return;
242
- }
243
- if (KeyboardUtil.ifDelete($event)) {
244
- if (!inputTarget.value) {
245
- this._clearInput(prevInputId, inputIdx - 1);
246
- this._setSelected(prevInputId);
247
- }
248
- else {
249
- this._clearInput(currentInputId, inputIdx);
250
- }
251
- this._rebuildValue();
252
- return;
253
- }
254
- if (this.ifValidKeyCode($event)) {
255
- inputTarget.value = $event.key;
256
- const ctrlName = this._getControlName(inputIdx);
257
- this.otpForm.controls[ctrlName]?.setValue($event.key);
258
- $event.preventDefault();
259
- this._setSelected(nextInputId);
260
- this._rebuildValue();
261
- }
262
- }
263
- onInput($event, inputIdx) {
264
- const inputTarget = $event.target;
265
- const currentVal = this._currentValSignal();
266
- const newVal = currentVal ? `${currentVal}${inputTarget.value}` : inputTarget.value;
267
- if (this.config().allowNumbersOnly && !this.validateNumber(newVal)) {
268
- inputTarget.value = '';
269
- $event.stopPropagation();
270
- this._clearInput(null, inputIdx);
271
- this._rebuildValue();
272
- }
273
- }
274
- onKeyUp($event, inputIdx) {
275
- if (KeyboardUtil.ifTab($event)) {
276
- inputIdx -= 1;
277
- }
278
- const nextInputId = this.getBoxId(inputIdx + 1);
279
- const prevInputId = this.getBoxId(inputIdx - 1);
280
- if (KeyboardUtil.ifRightArrow($event)) {
281
- $event.preventDefault();
282
- this._setSelected(nextInputId);
283
- return;
284
- }
285
- if (KeyboardUtil.ifLeftArrow($event)) {
286
- $event.preventDefault();
287
- this._setSelected(prevInputId);
288
- return;
289
- }
290
- if (!$event.target?.value) {
291
- return;
292
- }
293
- }
294
- validateNumber(val) {
295
- return !!val && /^[0-9]+$/.test(val);
296
- }
297
- getBoxId(idx) {
298
- return `otp_${idx}_${this.componentKey}`;
299
- }
300
- focusTo(eleId) {
301
- const ele = this._document.getElementById(eleId);
302
- if (ele) {
303
- ele.focus();
304
- }
305
- }
306
- setValue(value) {
307
- const cfg = this.config();
308
- if (cfg.allowNumbersOnly && isNaN(value)) {
309
- return;
310
- }
311
- this.otpForm.reset();
312
- if (!value) {
313
- this._rebuildValue();
314
- return;
315
- }
316
- value = value.toString().replace(/\s/g, '');
317
- Array.from(value).forEach((c, idx) => {
318
- if (this.otpForm.get(this._getControlName(idx))) {
319
- this.otpForm.get(this._getControlName(idx)).setValue(c);
320
- }
321
- });
322
- if (!cfg.disableAutoFocus) {
323
- const outerTimeoutId = setTimeout(() => {
324
- this._removePendingTimeout(outerTimeoutId);
325
- const containerItem = this._document.getElementById(`c_${this.componentKey}`);
326
- if (!containerItem)
327
- return;
328
- const indexOfElementToFocus = value.length < cfg.length ? value.length : (cfg.length - 1);
329
- const ele = containerItem.getElementsByClassName('cmat-otp-input')[indexOfElementToFocus];
330
- if (ele) {
331
- const innerTimeoutId = setTimeout(() => {
332
- this._removePendingTimeout(innerTimeoutId);
333
- ele.focus();
334
- }, 1);
335
- this._pendingTimeouts.push(innerTimeoutId);
336
- }
337
- }, 0);
338
- this._pendingTimeouts.push(outerTimeoutId);
339
- }
340
- this._rebuildValue();
341
- }
342
- handlePaste(e) {
343
- const clipboardData = e.clipboardData ?? window.clipboardData;
344
- let pastedData = '';
345
- if (clipboardData) {
346
- pastedData = clipboardData.getData('Text');
347
- }
348
- e.stopPropagation();
349
- e.preventDefault();
350
- if (!pastedData || (this.config().allowNumbersOnly && !this.validateNumber(pastedData))) {
351
- return;
352
- }
353
- this.setValue(pastedData);
354
- }
355
- getFormControl(key) {
356
- return this.otpForm.controls[key];
357
- }
358
- _removePendingTimeout(timeoutId) {
359
- const idx = this._pendingTimeouts.indexOf(timeoutId);
360
- if (idx !== -1) {
361
- this._pendingTimeouts.splice(idx, 1);
362
- }
363
- }
364
- _getControlName(idx) {
365
- return `ctrl_${idx}`;
366
- }
367
- _clearInput(eleId, inputIdx) {
368
- const ctrlName = this._getControlName(inputIdx);
369
- this.otpForm.controls[ctrlName]?.setValue(null);
370
- if (eleId) {
371
- const ele = this._document.getElementById(eleId);
372
- if (ele && ele instanceof HTMLInputElement) {
373
- ele.value = '';
374
- }
375
- }
376
- }
377
- _setSelected(eleId) {
378
- this.focusTo(eleId);
379
- const ele = this._document.getElementById(eleId);
380
- if (ele instanceof HTMLInputElement) {
381
- const timeoutId = setTimeout(() => {
382
- this._removePendingTimeout(timeoutId);
383
- ele.setSelectionRange(0, 1);
384
- }, 0);
385
- this._pendingTimeouts.push(timeoutId);
386
- }
387
- }
388
- ifValidKeyCode(event) {
389
- const inp = event.key;
390
- if (this.config()?.allowNumbersOnly) {
391
- return this.validateNumber(inp);
392
- }
393
- const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
394
- return isMobile || (/^[a-zA-Z0-9%*_\-@#$!]$/.test(inp) && inp.length === 1);
395
- }
396
- _rebuildValue() {
397
- let val = null;
398
- const cfg = this.config();
399
- Object.keys(this.otpForm.controls).forEach((k) => {
400
- let ctrlVal = this.otpForm.controls[k].value;
401
- if (typeof ctrlVal === 'string' && ctrlVal) {
402
- const isLengthExceed = ctrlVal.length > 1;
403
- ctrlVal = ctrlVal[0];
404
- const letterCase = cfg.letterCase?.toLocaleLowerCase();
405
- const isCaseTransformEnabled = !cfg.allowNumbersOnly && (letterCase === 'upper' || letterCase === 'lower');
406
- if (isCaseTransformEnabled) {
407
- ctrlVal = letterCase === 'upper' ? ctrlVal.toUpperCase() : ctrlVal.toLowerCase();
408
- this.otpForm.controls[k].setValue(ctrlVal);
409
- }
410
- else if (isLengthExceed) {
411
- this.otpForm.controls[k].setValue(ctrlVal);
412
- }
413
- val = val === null ? ctrlVal : val + ctrlVal;
414
- }
415
- });
416
- const currentVal = this._currentValSignal();
417
- if (currentVal != val) {
418
- this._currentValSignal.set(val);
419
- this._onModelChange(val);
420
- this.onInputChange.emit(val);
421
- }
422
- }
423
- _rebuildForm() {
424
- this._valueChangesSub?.unsubscribe();
425
- this._valueChangesSub = null;
426
- this.otpForm = this._formBuilder.group({});
427
- for (let index = 0; index < this.config().length; index++) {
428
- this.otpForm.addControl(this._getControlName(index), new FormControl());
429
- }
430
- this._valueChangesSub = this.otpForm.valueChanges.pipe(takeUntilDestroyed(this._destroyRef)).subscribe(() => {
431
- Object.keys(this.otpForm.controls).forEach((k) => {
432
- const val = this.otpForm.controls[k].value;
433
- if (typeof val === 'string' && val.length > 1) {
434
- if (val.length >= this.config().length) {
435
- this.setValue(val);
436
- }
437
- else {
438
- this._rebuildValue();
439
- }
440
- }
441
- });
442
- });
443
- }
444
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatOtpInputComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
445
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: CmatOtpInputComponent, isStandalone: true, selector: "cmat-otp-input", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: false, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: false, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: false, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: false, isRequired: false, transformFunction: null } }, outputs: { onBlur: "onBlur", onInputChange: "onInputChange" }, host: { properties: { "attr.id": "id" } }, providers: [{ provide: MatFormFieldControl, useExisting: CmatOtpInputComponent }], exportAs: ["cmatOtpInput"], ngImport: i0, template: "@if(otpForm.controls){\r\n<div class=\"cmat-otp-input-wrapper wrapper {{config().containerClass}}\" id=\"c_{{componentKey}}\"\r\n [attr.tabindex]=\"disabled ? -1 : 0\" [ngStyle]=\"config().containerStyles\" (focusin)=\"onFocusIn()\" (focusout)=\"onFocusOut()\">\r\n <div class=\"n-o-c\">\r\n @for (item of controlKeys(); track item) {\r\n <input #inp class=\"cmat-otp-input {{config().inputClass}}\" autocomplete=\"one-time-code\" [pattern]=\"config().allowNumbersOnly ? '\\\\d*' : ''\"\r\n [type]=\"inputType()\" [placeholder]=\"config().placeholder || ''\"\r\n [ngStyle]=\"config().inputStyles\" [id]=\"getBoxId($index)\"\r\n [ngClass]=\"{'error-input': (config().showError && errorState)}\"\r\n [formControl]=\"getFormControl(item)\" (paste)=\"handlePaste($event)\" (keyup)=\"onKeyUp($event,$index)\"\r\n (input)=\"onInput($event,$index)\" (keydown)=\"onKeyDown($event,$index)\">\r\n @if(config().separator && !$last){\r\n {{config().separator}}\r\n }\r\n }\r\n </div>\r\n</div>\r\n}", styles: [".cmat-otp-input{width:50px;height:50px;border-radius:4px;border:solid 1px;border-color:rgba(var(--cmat-text-hint-rgb),.5);text-align:center;font-size:32px}.cmat-otp-input:focus{background-color:var(--cmat-divider);border:solid 2px var(--cmat-primary)}.cmat-otp-input-wrapper .cmat-otp-input{margin:0 .51rem}.cmat-otp-input-wrapper .cmat-otp-input:first-child{margin-left:0}.cmat-otp-input-wrapper .cmat-otp-input:last-child{margin-right:0}.n-o-c{display:flex;align-items:center}.error-input{border-color:var(--cmat-warn)}@media screen and (max-width:767px){.cmat-otp-input{width:40px;font-size:24px;height:40px}}@media screen and (max-width:420px){.cmat-otp-input{width:30px;font-size:18px;height:30px}}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.PatternValidator, selector: "[pattern][formControlName],[pattern][formControl],[pattern][ngModel]", inputs: ["pattern"] }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
446
- }
447
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatOtpInputComponent, decorators: [{
448
- type: Component,
449
- args: [{ selector: 'cmat-otp-input', exportAs: 'cmatOtpInput', imports: [CommonModule, ReactiveFormsModule], providers: [{ provide: MatFormFieldControl, useExisting: CmatOtpInputComponent }], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, host: {
450
- // eslint-disable-next-line @typescript-eslint/naming-convention
451
- '[attr.id]': 'id',
452
- }, template: "@if(otpForm.controls){\r\n<div class=\"cmat-otp-input-wrapper wrapper {{config().containerClass}}\" id=\"c_{{componentKey}}\"\r\n [attr.tabindex]=\"disabled ? -1 : 0\" [ngStyle]=\"config().containerStyles\" (focusin)=\"onFocusIn()\" (focusout)=\"onFocusOut()\">\r\n <div class=\"n-o-c\">\r\n @for (item of controlKeys(); track item) {\r\n <input #inp class=\"cmat-otp-input {{config().inputClass}}\" autocomplete=\"one-time-code\" [pattern]=\"config().allowNumbersOnly ? '\\\\d*' : ''\"\r\n [type]=\"inputType()\" [placeholder]=\"config().placeholder || ''\"\r\n [ngStyle]=\"config().inputStyles\" [id]=\"getBoxId($index)\"\r\n [ngClass]=\"{'error-input': (config().showError && errorState)}\"\r\n [formControl]=\"getFormControl(item)\" (paste)=\"handlePaste($event)\" (keyup)=\"onKeyUp($event,$index)\"\r\n (input)=\"onInput($event,$index)\" (keydown)=\"onKeyDown($event,$index)\">\r\n @if(config().separator && !$last){\r\n {{config().separator}}\r\n }\r\n }\r\n </div>\r\n</div>\r\n}", styles: [".cmat-otp-input{width:50px;height:50px;border-radius:4px;border:solid 1px;border-color:rgba(var(--cmat-text-hint-rgb),.5);text-align:center;font-size:32px}.cmat-otp-input:focus{background-color:var(--cmat-divider);border:solid 2px var(--cmat-primary)}.cmat-otp-input-wrapper .cmat-otp-input{margin:0 .51rem}.cmat-otp-input-wrapper .cmat-otp-input:first-child{margin-left:0}.cmat-otp-input-wrapper .cmat-otp-input:last-child{margin-right:0}.n-o-c{display:flex;align-items:center}.error-input{border-color:var(--cmat-warn)}@media screen and (max-width:767px){.cmat-otp-input{width:40px;font-size:24px;height:40px}}@media screen and (max-width:420px){.cmat-otp-input{width:30px;font-size:18px;height:30px}}\n"] }]
453
- }], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: false }] }], onBlur: [{ type: i0.Output, args: ["onBlur"] }], onInputChange: [{ type: i0.Output, args: ["onInputChange"] }], placeholder: [{
454
- type: Input
455
- }], required: [{
456
- type: Input
457
- }], disabled: [{
458
- type: Input
459
- }], value: [{
460
- type: Input
461
- }] } });
462
-
463
- /**
464
- * Generated bundle index. Do not edit.
465
- */
466
-
35
+ var CmatOtpInputComponent = class CmatOtpInputComponent {
36
+ get errorState() {
37
+ if (this.ngControl == null) return false;
38
+ return (this.ngControl.invalid && ((this.ngControl.dirty ?? false) || this.ngControl.touched)) ?? false;
39
+ }
40
+ constructor() {
41
+ this.config = input({ length: 4 }, ...ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []);
42
+ this.onBlur = output();
43
+ this.onInputChange = output();
44
+ this.id = `cmat-otp-input-${NEXT_ID}`;
45
+ this.stateChanges = new Subject();
46
+ this._placeholderSignal = signal("", ...ngDevMode ? [{ debugName: "_placeholderSignal" }] : /* istanbul ignore next */ []);
47
+ this._requiredSignal = signal(false, ...ngDevMode ? [{ debugName: "_requiredSignal" }] : /* istanbul ignore next */ []);
48
+ this._disabledSignal = signal(false, ...ngDevMode ? [{ debugName: "_disabledSignal" }] : /* istanbul ignore next */ []);
49
+ this._valueSignal = signal(null, ...ngDevMode ? [{ debugName: "_valueSignal" }] : /* istanbul ignore next */ []);
50
+ this._currentValSignal = signal(null, ...ngDevMode ? [{ debugName: "_currentValSignal" }] : /* istanbul ignore next */ []);
51
+ this._focused = false;
52
+ this._activeFocusCount = 0;
53
+ this.controlKeys = computed(() => Object.keys(this.otpForm?.controls ?? {}), ...ngDevMode ? [{ debugName: "controlKeys" }] : /* istanbul ignore next */ []);
54
+ this.inputType = computed(() => {
55
+ const cfg = this.config();
56
+ return cfg?.isPasswordInput ? "password" : cfg?.allowNumbersOnly ? "tel" : "text";
57
+ }, ...ngDevMode ? [{ debugName: "inputType" }] : /* istanbul ignore next */ []);
58
+ this.componentKey = (NEXT_ID++).toString(36);
59
+ this.ngControl = inject(NgControl, {
60
+ optional: true,
61
+ self: true
62
+ });
63
+ this._document = inject(DOCUMENT);
64
+ this._formBuilder = inject(FormBuilder);
65
+ this._destroyRef = inject(DestroyRef);
66
+ this._valueChangesSub = null;
67
+ this._pendingTimeouts = [];
68
+ this._onModelChange = () => {};
69
+ this._onTouchedChange = () => {};
70
+ this.otpForm = this._formBuilder.group({});
71
+ if (this.ngControl != null) this.ngControl.valueAccessor = this;
72
+ this._rebuildForm();
73
+ }
74
+ get placeholder() {
75
+ return this._placeholderSignal();
76
+ }
77
+ set placeholder(value) {
78
+ this._placeholderSignal.set(value);
79
+ this.stateChanges.next();
80
+ }
81
+ get required() {
82
+ return this._requiredSignal();
83
+ }
84
+ set required(value) {
85
+ this._requiredSignal.set(coerceBooleanProperty(value));
86
+ this.stateChanges.next();
87
+ }
88
+ get disabled() {
89
+ if (!this.ngControl.disabled && this.ngControl.disabled !== null) return this.ngControl.disabled;
90
+ return this._disabledSignal();
91
+ }
92
+ set disabled(value) {
93
+ const isDisabled = coerceBooleanProperty(value);
94
+ this._disabledSignal.set(isDisabled);
95
+ this.setDisabledState(isDisabled);
96
+ if (isDisabled && this._focused) {
97
+ this._focused = false;
98
+ this.stateChanges.next();
99
+ }
100
+ }
101
+ get focused() {
102
+ return this._focused;
103
+ }
104
+ get value() {
105
+ return this._valueSignal();
106
+ }
107
+ set value(val) {
108
+ if (val !== this._valueSignal()) {
109
+ this._valueSignal.set(val);
110
+ this.stateChanges.next();
111
+ this._onModelChange(val);
112
+ }
113
+ }
114
+ get empty() {
115
+ return !this._valueSignal();
116
+ }
117
+ get shouldLabelFloat() {
118
+ return this._focused || !this.empty;
119
+ }
120
+ setDisabledState(isDisabled) {
121
+ if (this.otpForm) {
122
+ if (isDisabled) this.otpForm.disable({ emitEvent: false });
123
+ else this.otpForm.enable({ emitEvent: false });
124
+ }
125
+ this.stateChanges.next();
126
+ }
127
+ writeValue(value) {
128
+ this._currentValSignal.set(value || null);
129
+ if (this.otpForm && this._currentValSignal()) this.setValue(this._currentValSignal());
130
+ }
131
+ registerOnChange(fn) {
132
+ this._onModelChange = fn;
133
+ }
134
+ registerOnTouched(fn) {
135
+ this._onTouchedChange = fn;
136
+ }
137
+ onFocusIn() {
138
+ this._onTouchedChange();
139
+ this._activeFocusCount++;
140
+ if (!this._focused) {
141
+ this._focused = true;
142
+ this.stateChanges.next();
143
+ }
144
+ }
145
+ onFocusOut() {
146
+ const timeoutId = setTimeout(() => {
147
+ this._removePendingTimeout(timeoutId);
148
+ this._activeFocusCount--;
149
+ if (this._activeFocusCount === 0) {
150
+ this._focused = false;
151
+ this._onTouchedChange();
152
+ this.onBlur.emit();
153
+ this.stateChanges.next();
154
+ }
155
+ }, 0);
156
+ this._pendingTimeouts.push(timeoutId);
157
+ }
158
+ ngAfterViewInit() {
159
+ if (!this.config().disableAutoFocus) {
160
+ const containerItem = this._document.getElementById(`c_${this.componentKey}`);
161
+ if (containerItem) {
162
+ const ele = containerItem.getElementsByClassName("cmat-otp-input")[0];
163
+ if (ele?.focus) ele.focus();
164
+ }
165
+ }
166
+ }
167
+ ngOnDestroy() {
168
+ this._pendingTimeouts.forEach((id) => clearTimeout(id));
169
+ this._pendingTimeouts = [];
170
+ this._valueChangesSub?.unsubscribe();
171
+ this._valueChangesSub = null;
172
+ this.stateChanges.complete();
173
+ this.otpForm.reset();
174
+ }
175
+ setDescribedByIds(ids) {
176
+ this.userAriaDescribedBy = ids.length ? ids.join(" ") : void 0;
177
+ const containerItem = this._document.getElementById(`c_${this.componentKey}`);
178
+ if (containerItem) {
179
+ if (ids.length) containerItem.setAttribute("aria-describedby", ids.join(" "));
180
+ else containerItem.removeAttribute("aria-describedby");
181
+ }
182
+ this.stateChanges.next();
183
+ }
184
+ onContainerClick() {
185
+ if (!this._focused) {
186
+ const containerItem = this._document.getElementById(`c_${this.componentKey}`);
187
+ if (containerItem) containerItem.focus();
188
+ }
189
+ }
190
+ onKeyDown($event, inputIdx) {
191
+ const inputTarget = $event.target;
192
+ const prevInputId = this.getBoxId(inputIdx - 1);
193
+ const currentInputId = this.getBoxId(inputIdx);
194
+ const nextInputId = this.getBoxId(inputIdx + 1);
195
+ if (KeyboardUtil.ifSpacebar($event)) {
196
+ $event.preventDefault();
197
+ return;
198
+ }
199
+ if (KeyboardUtil.ifBackspace($event)) {
200
+ if (!inputTarget.value) {
201
+ this._clearInput(prevInputId, inputIdx - 1);
202
+ this._setSelected(prevInputId);
203
+ } else this._clearInput(currentInputId, inputIdx);
204
+ this._rebuildValue();
205
+ return;
206
+ }
207
+ if (KeyboardUtil.ifDelete($event)) {
208
+ if (!inputTarget.value) {
209
+ this._clearInput(prevInputId, inputIdx - 1);
210
+ this._setSelected(prevInputId);
211
+ } else this._clearInput(currentInputId, inputIdx);
212
+ this._rebuildValue();
213
+ return;
214
+ }
215
+ if (this.ifValidKeyCode($event)) {
216
+ inputTarget.value = $event.key;
217
+ const ctrlName = this._getControlName(inputIdx);
218
+ this.otpForm.controls[ctrlName]?.setValue($event.key);
219
+ $event.preventDefault();
220
+ this._setSelected(nextInputId);
221
+ this._rebuildValue();
222
+ }
223
+ }
224
+ onInput($event, inputIdx) {
225
+ const inputTarget = $event.target;
226
+ const currentVal = this._currentValSignal();
227
+ const newVal = currentVal ? `${currentVal}${inputTarget.value}` : inputTarget.value;
228
+ if (this.config().allowNumbersOnly && !this.validateNumber(newVal)) {
229
+ inputTarget.value = "";
230
+ $event.stopPropagation();
231
+ this._clearInput(null, inputIdx);
232
+ this._rebuildValue();
233
+ }
234
+ }
235
+ onKeyUp($event, inputIdx) {
236
+ if (KeyboardUtil.ifTab($event)) inputIdx -= 1;
237
+ const nextInputId = this.getBoxId(inputIdx + 1);
238
+ const prevInputId = this.getBoxId(inputIdx - 1);
239
+ if (KeyboardUtil.ifRightArrow($event)) {
240
+ $event.preventDefault();
241
+ this._setSelected(nextInputId);
242
+ return;
243
+ }
244
+ if (KeyboardUtil.ifLeftArrow($event)) {
245
+ $event.preventDefault();
246
+ this._setSelected(prevInputId);
247
+ return;
248
+ }
249
+ if (!$event.target?.value) return;
250
+ }
251
+ validateNumber(val) {
252
+ return !!val && /^[0-9]+$/.test(val);
253
+ }
254
+ getBoxId(idx) {
255
+ return `otp_${idx}_${this.componentKey}`;
256
+ }
257
+ focusTo(eleId) {
258
+ const ele = this._document.getElementById(eleId);
259
+ if (ele) ele.focus();
260
+ }
261
+ setValue(value) {
262
+ const cfg = this.config();
263
+ if (cfg.allowNumbersOnly && isNaN(value)) return;
264
+ this.otpForm.reset();
265
+ if (!value) {
266
+ this._rebuildValue();
267
+ return;
268
+ }
269
+ value = value.toString().replace(/\s/g, "");
270
+ Array.from(value).forEach((c, idx) => {
271
+ if (this.otpForm.get(this._getControlName(idx))) this.otpForm.get(this._getControlName(idx)).setValue(c);
272
+ });
273
+ if (!cfg.disableAutoFocus) {
274
+ const outerTimeoutId = setTimeout(() => {
275
+ this._removePendingTimeout(outerTimeoutId);
276
+ const containerItem = this._document.getElementById(`c_${this.componentKey}`);
277
+ if (!containerItem) return;
278
+ const indexOfElementToFocus = value.length < cfg.length ? value.length : cfg.length - 1;
279
+ const ele = containerItem.getElementsByClassName("cmat-otp-input")[indexOfElementToFocus];
280
+ if (ele) {
281
+ const innerTimeoutId = setTimeout(() => {
282
+ this._removePendingTimeout(innerTimeoutId);
283
+ ele.focus();
284
+ }, 1);
285
+ this._pendingTimeouts.push(innerTimeoutId);
286
+ }
287
+ }, 0);
288
+ this._pendingTimeouts.push(outerTimeoutId);
289
+ }
290
+ this._rebuildValue();
291
+ }
292
+ handlePaste(e) {
293
+ const clipboardData = e.clipboardData ?? window.clipboardData;
294
+ let pastedData = "";
295
+ if (clipboardData) pastedData = clipboardData.getData("Text");
296
+ e.stopPropagation();
297
+ e.preventDefault();
298
+ if (!pastedData || this.config().allowNumbersOnly && !this.validateNumber(pastedData)) return;
299
+ this.setValue(pastedData);
300
+ }
301
+ getFormControl(key) {
302
+ return this.otpForm.controls[key];
303
+ }
304
+ _removePendingTimeout(timeoutId) {
305
+ const idx = this._pendingTimeouts.indexOf(timeoutId);
306
+ if (idx !== -1) this._pendingTimeouts.splice(idx, 1);
307
+ }
308
+ _getControlName(idx) {
309
+ return `ctrl_${idx}`;
310
+ }
311
+ _clearInput(eleId, inputIdx) {
312
+ const ctrlName = this._getControlName(inputIdx);
313
+ this.otpForm.controls[ctrlName]?.setValue(null);
314
+ if (eleId) {
315
+ const ele = this._document.getElementById(eleId);
316
+ if (ele && ele instanceof HTMLInputElement) ele.value = "";
317
+ }
318
+ }
319
+ _setSelected(eleId) {
320
+ this.focusTo(eleId);
321
+ const ele = this._document.getElementById(eleId);
322
+ if (ele instanceof HTMLInputElement) {
323
+ const timeoutId = setTimeout(() => {
324
+ this._removePendingTimeout(timeoutId);
325
+ ele.setSelectionRange(0, 1);
326
+ }, 0);
327
+ this._pendingTimeouts.push(timeoutId);
328
+ }
329
+ }
330
+ ifValidKeyCode(event) {
331
+ const inp = event.key;
332
+ if (this.config()?.allowNumbersOnly) return this.validateNumber(inp);
333
+ return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) || /^[a-zA-Z0-9%*_\-@#$!]$/.test(inp) && inp.length === 1;
334
+ }
335
+ _rebuildValue() {
336
+ let val = null;
337
+ const cfg = this.config();
338
+ Object.keys(this.otpForm.controls).forEach((k) => {
339
+ let ctrlVal = this.otpForm.controls[k].value;
340
+ if (typeof ctrlVal === "string" && ctrlVal) {
341
+ const isLengthExceed = ctrlVal.length > 1;
342
+ ctrlVal = ctrlVal[0];
343
+ const letterCase = cfg.letterCase?.toLocaleLowerCase();
344
+ if (!cfg.allowNumbersOnly && (letterCase === "upper" || letterCase === "lower")) {
345
+ ctrlVal = letterCase === "upper" ? ctrlVal.toUpperCase() : ctrlVal.toLowerCase();
346
+ this.otpForm.controls[k].setValue(ctrlVal);
347
+ } else if (isLengthExceed) this.otpForm.controls[k].setValue(ctrlVal);
348
+ val = val === null ? ctrlVal : val + ctrlVal;
349
+ }
350
+ });
351
+ if (this._currentValSignal() != val) {
352
+ this._currentValSignal.set(val);
353
+ this._onModelChange(val);
354
+ this.onInputChange.emit(val);
355
+ }
356
+ }
357
+ _rebuildForm() {
358
+ this._valueChangesSub?.unsubscribe();
359
+ this._valueChangesSub = null;
360
+ this.otpForm = this._formBuilder.group({});
361
+ for (let index = 0; index < this.config().length; index++) this.otpForm.addControl(this._getControlName(index), new FormControl());
362
+ this._valueChangesSub = this.otpForm.valueChanges.pipe(takeUntilDestroyed(this._destroyRef)).subscribe(() => {
363
+ Object.keys(this.otpForm.controls).forEach((k) => {
364
+ const val = this.otpForm.controls[k].value;
365
+ if (typeof val === "string" && val.length > 1) {
366
+ if (val.length >= this.config().length) this.setValue(val);
367
+ else this._rebuildValue();
368
+ }
369
+ });
370
+ });
371
+ }
372
+ static {
373
+ this.ɵfac = i0.ɵɵngDeclareFactory({
374
+ minVersion: "12.0.0",
375
+ version: "22.2.3",
376
+ ngImport: i0,
377
+ type: CmatOtpInputComponent,
378
+ deps: [],
379
+ target: i0.ɵɵFactoryTarget.Component
380
+ });
381
+ }
382
+ static {
383
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
384
+ minVersion: "17.0.0",
385
+ version: "22.2.3",
386
+ type: CmatOtpInputComponent,
387
+ isStandalone: true,
388
+ selector: "cmat-otp-input",
389
+ inputs: {
390
+ config: {
391
+ classPropertyName: "config",
392
+ publicName: "config",
393
+ isSignal: true,
394
+ isRequired: false,
395
+ transformFunction: null
396
+ },
397
+ placeholder: {
398
+ classPropertyName: "placeholder",
399
+ publicName: "placeholder",
400
+ isSignal: false,
401
+ isRequired: false,
402
+ transformFunction: null
403
+ },
404
+ required: {
405
+ classPropertyName: "required",
406
+ publicName: "required",
407
+ isSignal: false,
408
+ isRequired: false,
409
+ transformFunction: null
410
+ },
411
+ disabled: {
412
+ classPropertyName: "disabled",
413
+ publicName: "disabled",
414
+ isSignal: false,
415
+ isRequired: false,
416
+ transformFunction: null
417
+ },
418
+ value: {
419
+ classPropertyName: "value",
420
+ publicName: "value",
421
+ isSignal: false,
422
+ isRequired: false,
423
+ transformFunction: null
424
+ }
425
+ },
426
+ outputs: {
427
+ onBlur: "onBlur",
428
+ onInputChange: "onInputChange"
429
+ },
430
+ host: { properties: { "attr.id": "id" } },
431
+ providers: [{
432
+ provide: MatFormFieldControl,
433
+ useExisting: CmatOtpInputComponent
434
+ }],
435
+ exportAs: ["cmatOtpInput"],
436
+ ngImport: i0,
437
+ template: "@if(otpForm.controls){\r\n<div class=\"cmat-otp-input-wrapper wrapper {{config().containerClass}}\" id=\"c_{{componentKey}}\"\r\n [attr.tabindex]=\"disabled ? -1 : 0\" [ngStyle]=\"config().containerStyles\" (focusin)=\"onFocusIn()\" (focusout)=\"onFocusOut()\">\r\n <div class=\"n-o-c\">\r\n @for (item of controlKeys(); track item) {\r\n <input #inp class=\"cmat-otp-input {{config().inputClass}}\" autocomplete=\"one-time-code\" [pattern]=\"config().allowNumbersOnly ? '\\\\d*' : ''\"\r\n [type]=\"inputType()\" [placeholder]=\"config().placeholder || ''\"\r\n [ngStyle]=\"config().inputStyles\" [id]=\"getBoxId($index)\"\r\n [ngClass]=\"{'error-input': (config().showError && errorState)}\"\r\n [formControl]=\"getFormControl(item)\" (paste)=\"handlePaste($event)\" (keyup)=\"onKeyUp($event,$index)\"\r\n (input)=\"onInput($event,$index)\" (keydown)=\"onKeyDown($event,$index)\">\r\n @if(config().separator && !$last){\r\n {{config().separator}}\r\n }\r\n }\r\n </div>\r\n</div>\r\n}",
438
+ styles: [".cmat-otp-input{width:50px;height:50px;border-radius:4px;border:solid 1px;border-color:rgba(var(--cmat-text-hint-rgb),.5);text-align:center;font-size:32px}.cmat-otp-input:focus{background-color:var(--cmat-divider);border:solid 2px var(--cmat-primary)}.cmat-otp-input-wrapper .cmat-otp-input{margin:0 .51rem}.cmat-otp-input-wrapper .cmat-otp-input:first-child{margin-left:0}.cmat-otp-input-wrapper .cmat-otp-input:last-child{margin-right:0}.n-o-c{display:flex;align-items:center}.error-input{border-color:var(--cmat-warn)}@media screen and (max-width:767px){.cmat-otp-input{width:40px;font-size:24px;height:40px}}@media screen and (max-width:420px){.cmat-otp-input{width:30px;font-size:18px;height:30px}}\n"],
439
+ dependencies: [
440
+ {
441
+ kind: "ngmodule",
442
+ type: CommonModule
443
+ },
444
+ {
445
+ kind: "directive",
446
+ type: i1.NgClass,
447
+ selector: "[ngClass]",
448
+ inputs: ["class", "ngClass"]
449
+ },
450
+ {
451
+ kind: "directive",
452
+ type: i1.NgStyle,
453
+ selector: "[ngStyle]",
454
+ inputs: ["ngStyle"]
455
+ },
456
+ {
457
+ kind: "ngmodule",
458
+ type: ReactiveFormsModule
459
+ },
460
+ {
461
+ kind: "directive",
462
+ type: i2.DefaultValueAccessor,
463
+ selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]"
464
+ },
465
+ {
466
+ kind: "directive",
467
+ type: i2.NgControlStatus,
468
+ selector: "[formControlName],[ngModel],[formControl]"
469
+ },
470
+ {
471
+ kind: "directive",
472
+ type: i2.PatternValidator,
473
+ selector: "[pattern][formControlName],[pattern][formControl],[pattern][ngModel]",
474
+ inputs: ["pattern"]
475
+ },
476
+ {
477
+ kind: "directive",
478
+ type: i2.FormControlDirective,
479
+ selector: "[formControl]",
480
+ inputs: [
481
+ "formControl",
482
+ "disabled",
483
+ "ngModel"
484
+ ],
485
+ outputs: ["ngModelChange"],
486
+ exportAs: ["ngForm"]
487
+ }
488
+ ],
489
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
490
+ encapsulation: i0.ViewEncapsulation.None
491
+ });
492
+ }
493
+ };
494
+ i0.ɵɵngDeclareClassMetadata({
495
+ minVersion: "12.0.0",
496
+ version: "22.2.3",
497
+ ngImport: i0,
498
+ type: CmatOtpInputComponent,
499
+ decorators: [{
500
+ type: Component,
501
+ args: [{
502
+ selector: "cmat-otp-input",
503
+ exportAs: "cmatOtpInput",
504
+ imports: [CommonModule, ReactiveFormsModule],
505
+ providers: [{
506
+ provide: MatFormFieldControl,
507
+ useExisting: CmatOtpInputComponent
508
+ }],
509
+ encapsulation: ViewEncapsulation.None,
510
+ changeDetection: ChangeDetectionStrategy.OnPush,
511
+ host: { "[attr.id]": "id" },
512
+ template: "@if(otpForm.controls){\r\n<div class=\"cmat-otp-input-wrapper wrapper {{config().containerClass}}\" id=\"c_{{componentKey}}\"\r\n [attr.tabindex]=\"disabled ? -1 : 0\" [ngStyle]=\"config().containerStyles\" (focusin)=\"onFocusIn()\" (focusout)=\"onFocusOut()\">\r\n <div class=\"n-o-c\">\r\n @for (item of controlKeys(); track item) {\r\n <input #inp class=\"cmat-otp-input {{config().inputClass}}\" autocomplete=\"one-time-code\" [pattern]=\"config().allowNumbersOnly ? '\\\\d*' : ''\"\r\n [type]=\"inputType()\" [placeholder]=\"config().placeholder || ''\"\r\n [ngStyle]=\"config().inputStyles\" [id]=\"getBoxId($index)\"\r\n [ngClass]=\"{'error-input': (config().showError && errorState)}\"\r\n [formControl]=\"getFormControl(item)\" (paste)=\"handlePaste($event)\" (keyup)=\"onKeyUp($event,$index)\"\r\n (input)=\"onInput($event,$index)\" (keydown)=\"onKeyDown($event,$index)\">\r\n @if(config().separator && !$last){\r\n {{config().separator}}\r\n }\r\n }\r\n </div>\r\n</div>\r\n}",
513
+ styles: [".cmat-otp-input{width:50px;height:50px;border-radius:4px;border:solid 1px;border-color:rgba(var(--cmat-text-hint-rgb),.5);text-align:center;font-size:32px}.cmat-otp-input:focus{background-color:var(--cmat-divider);border:solid 2px var(--cmat-primary)}.cmat-otp-input-wrapper .cmat-otp-input{margin:0 .51rem}.cmat-otp-input-wrapper .cmat-otp-input:first-child{margin-left:0}.cmat-otp-input-wrapper .cmat-otp-input:last-child{margin-right:0}.n-o-c{display:flex;align-items:center}.error-input{border-color:var(--cmat-warn)}@media screen and (max-width:767px){.cmat-otp-input{width:40px;font-size:24px;height:40px}}@media screen and (max-width:420px){.cmat-otp-input{width:30px;font-size:18px;height:30px}}\n"]
514
+ }]
515
+ }],
516
+ ctorParameters: () => [],
517
+ propDecorators: {
518
+ config: [{
519
+ type: i0.Input,
520
+ args: [{
521
+ isSignal: true,
522
+ alias: "config",
523
+ required: false
524
+ }]
525
+ }],
526
+ onBlur: [{
527
+ type: i0.Output,
528
+ args: ["onBlur"]
529
+ }],
530
+ onInputChange: [{
531
+ type: i0.Output,
532
+ args: ["onInputChange"]
533
+ }],
534
+ placeholder: [{ type: Input }],
535
+ required: [{ type: Input }],
536
+ disabled: [{ type: Input }],
537
+ value: [{ type: Input }]
538
+ }
539
+ });
467
540
  export { CmatOtpInputComponent };
468
- //# sourceMappingURL=cmat-components-opt-input.mjs.map
541
+
542
+ //# sourceMappingURL=cmat-components-opt-input.mjs.map