mepcli 2.0.0-beta.2 → 2.0.0-beta.3

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 (356) hide show
  1. package/dist/ansi.d.ts +36 -0
  2. package/dist/ansi.js +1 -0
  3. package/dist/base.d.ts +60 -0
  4. package/dist/base.js +1 -0
  5. package/dist/{src/core.js → core.d.ts} +175 -345
  6. package/dist/core.js +1 -0
  7. package/dist/data/countries.d.ts +2 -0
  8. package/dist/data/countries.js +1 -0
  9. package/dist/data/licenses.d.ts +2 -0
  10. package/dist/data/licenses.js +1 -0
  11. package/dist/highlight.d.ts +7 -0
  12. package/dist/highlight.js +1 -0
  13. package/dist/index.d.ts +48 -0
  14. package/dist/index.js +1 -0
  15. package/dist/input.d.ts +14 -0
  16. package/dist/input.js +1 -0
  17. package/dist/pipeline.d.ts +90 -0
  18. package/dist/pipeline.js +1 -0
  19. package/dist/prompts/autocomplete.d.ts +22 -0
  20. package/dist/prompts/autocomplete.js +1 -0
  21. package/dist/prompts/box.d.ts +21 -0
  22. package/dist/prompts/box.js +4 -0
  23. package/dist/prompts/breadcrumb-search.d.ts +14 -0
  24. package/dist/prompts/breadcrumb-search.js +2 -0
  25. package/dist/prompts/breadcrumb.d.ts +32 -0
  26. package/dist/prompts/breadcrumb.js +3 -0
  27. package/dist/prompts/byte.d.ts +13 -0
  28. package/dist/prompts/byte.js +5 -0
  29. package/dist/prompts/calculator.d.ts +17 -0
  30. package/dist/prompts/calculator.js +3 -0
  31. package/dist/prompts/calendar.d.ts +33 -0
  32. package/dist/prompts/calendar.js +3 -0
  33. package/dist/prompts/checkbox.d.ts +13 -0
  34. package/dist/prompts/checkbox.js +2 -0
  35. package/dist/prompts/code.d.ts +19 -0
  36. package/dist/prompts/code.js +4 -0
  37. package/dist/prompts/color.d.ts +14 -0
  38. package/dist/prompts/color.js +10 -0
  39. package/dist/prompts/confirm.d.ts +8 -0
  40. package/dist/prompts/confirm.js +1 -0
  41. package/dist/prompts/connection-string.d.ts +18 -0
  42. package/dist/prompts/connection-string.js +1 -0
  43. package/dist/prompts/cron.d.ts +13 -0
  44. package/dist/prompts/cron.js +4 -0
  45. package/dist/prompts/curl-utils.d.ts +25 -0
  46. package/dist/prompts/curl-utils.js +1 -0
  47. package/dist/prompts/curl.d.ts +41 -0
  48. package/dist/prompts/curl.js +12 -0
  49. package/dist/prompts/data-inspector.d.ts +22 -0
  50. package/dist/prompts/data-inspector.js +5 -0
  51. package/dist/prompts/date.d.ts +12 -0
  52. package/dist/prompts/date.js +2 -0
  53. package/dist/prompts/dependency.d.ts +16 -0
  54. package/dist/prompts/dependency.js +3 -0
  55. package/dist/prompts/dial.d.ts +10 -0
  56. package/dist/prompts/dial.js +3 -0
  57. package/dist/prompts/diff.d.ts +10 -0
  58. package/dist/prompts/diff.js +10 -0
  59. package/dist/prompts/draw.d.ts +20 -0
  60. package/dist/prompts/draw.js +6 -0
  61. package/dist/prompts/editor.d.ts +14 -0
  62. package/dist/prompts/editor.js +2 -0
  63. package/dist/prompts/emoji.d.ts +18 -0
  64. package/dist/prompts/emoji.js +5 -0
  65. package/dist/prompts/exec.d.ts +17 -0
  66. package/dist/prompts/exec.js +1 -0
  67. package/dist/prompts/file.d.ts +21 -0
  68. package/dist/prompts/file.js +2 -0
  69. package/dist/prompts/form.d.ts +18 -0
  70. package/dist/prompts/form.js +1 -0
  71. package/dist/prompts/fuzzy-multi-column.d.ts +12 -0
  72. package/dist/prompts/fuzzy-multi-column.js +2 -0
  73. package/dist/prompts/fuzzy.d.ts +12 -0
  74. package/dist/prompts/fuzzy.js +2 -0
  75. package/dist/prompts/gauge.d.ts +21 -0
  76. package/dist/prompts/gauge.js +4 -0
  77. package/dist/prompts/grid.d.ts +14 -0
  78. package/dist/prompts/grid.js +2 -0
  79. package/dist/prompts/heatmap.d.ts +13 -0
  80. package/dist/prompts/heatmap.js +2 -0
  81. package/dist/prompts/ip.d.ts +11 -0
  82. package/dist/prompts/ip.js +3 -0
  83. package/dist/prompts/kanban.d.ts +17 -0
  84. package/dist/prompts/kanban.js +4 -0
  85. package/dist/prompts/keypress.d.ts +7 -0
  86. package/dist/prompts/keypress.js +1 -0
  87. package/dist/prompts/license.d.ts +9 -0
  88. package/dist/prompts/license.js +13 -0
  89. package/dist/prompts/list.d.ts +9 -0
  90. package/dist/prompts/list.js +1 -0
  91. package/dist/prompts/map.d.ts +17 -0
  92. package/dist/prompts/map.js +5 -0
  93. package/dist/prompts/match.d.ts +19 -0
  94. package/dist/prompts/match.js +7 -0
  95. package/dist/prompts/miller.d.ts +15 -0
  96. package/dist/prompts/miller.js +2 -0
  97. package/dist/prompts/multi-column-select.d.ts +10 -0
  98. package/dist/prompts/multi-column-select.js +2 -0
  99. package/dist/prompts/multi-range.d.ts +9 -0
  100. package/dist/prompts/multi-range.js +3 -0
  101. package/dist/prompts/multi-select.d.ts +15 -0
  102. package/dist/prompts/multi-select.js +4 -0
  103. package/dist/prompts/number.d.ts +11 -0
  104. package/dist/prompts/number.js +2 -0
  105. package/dist/prompts/otp.d.ts +10 -0
  106. package/dist/prompts/otp.js +2 -0
  107. package/dist/prompts/pattern.d.ts +22 -0
  108. package/dist/prompts/pattern.js +4 -0
  109. package/dist/prompts/phone.d.ts +41 -0
  110. package/dist/prompts/phone.js +3 -0
  111. package/dist/prompts/quiz-select.d.ts +10 -0
  112. package/dist/prompts/quiz-select.js +7 -0
  113. package/dist/prompts/quiz-text.d.ts +11 -0
  114. package/dist/prompts/quiz-text.js +8 -0
  115. package/dist/prompts/range.d.ts +9 -0
  116. package/dist/prompts/range.js +1 -0
  117. package/dist/prompts/rating.d.ts +8 -0
  118. package/dist/prompts/rating.js +1 -0
  119. package/dist/prompts/regex.d.ts +13 -0
  120. package/dist/prompts/regex.js +5 -0
  121. package/dist/prompts/region.d.ts +11 -0
  122. package/dist/prompts/region.js +5 -0
  123. package/dist/prompts/schedule.d.ts +20 -0
  124. package/dist/prompts/schedule.js +5 -0
  125. package/dist/prompts/scroll.d.ts +13 -0
  126. package/dist/prompts/scroll.js +1 -0
  127. package/dist/prompts/seat.d.ts +17 -0
  128. package/dist/prompts/seat.js +5 -0
  129. package/dist/prompts/select-range.d.ts +8 -0
  130. package/dist/prompts/select-range.js +3 -0
  131. package/dist/prompts/select.d.ts +15 -0
  132. package/dist/prompts/select.js +2 -0
  133. package/dist/prompts/semver.d.ts +6 -0
  134. package/dist/prompts/semver.js +1 -0
  135. package/dist/prompts/shortcut.d.ts +9 -0
  136. package/dist/prompts/shortcut.js +1 -0
  137. package/dist/prompts/slider.d.ts +8 -0
  138. package/dist/prompts/slider.js +1 -0
  139. package/dist/prompts/slot.d.ts +16 -0
  140. package/dist/prompts/slot.js +8 -0
  141. package/dist/prompts/snippet.d.ts +19 -0
  142. package/dist/prompts/snippet.js +4 -0
  143. package/dist/prompts/sort-grid.d.ts +16 -0
  144. package/dist/prompts/sort-grid.js +2 -0
  145. package/dist/prompts/sort.d.ts +14 -0
  146. package/dist/prompts/sort.js +2 -0
  147. package/dist/prompts/spam.d.ts +17 -0
  148. package/dist/prompts/spam.js +2 -0
  149. package/dist/prompts/spreadsheet.d.ts +21 -0
  150. package/dist/prompts/spreadsheet.js +7 -0
  151. package/dist/prompts/table.d.ts +14 -0
  152. package/dist/prompts/table.js +3 -0
  153. package/dist/prompts/text.d.ts +17 -0
  154. package/dist/prompts/text.js +2 -0
  155. package/dist/prompts/time.d.ts +12 -0
  156. package/dist/prompts/time.js +2 -0
  157. package/dist/prompts/toggle.d.ts +8 -0
  158. package/dist/prompts/toggle.js +1 -0
  159. package/dist/prompts/transfer.d.ts +18 -0
  160. package/dist/prompts/transfer.js +5 -0
  161. package/dist/prompts/tree-select.d.ts +31 -0
  162. package/dist/prompts/tree-select.js +3 -0
  163. package/dist/prompts/tree.d.ts +20 -0
  164. package/dist/prompts/tree.js +3 -0
  165. package/dist/prompts/wait.d.ts +18 -0
  166. package/dist/prompts/wait.js +1 -0
  167. package/dist/spinner.d.ts +33 -0
  168. package/dist/spinner.js +3 -0
  169. package/dist/symbols.d.ts +33 -0
  170. package/dist/symbols.js +1 -0
  171. package/dist/tasks.d.ts +57 -0
  172. package/dist/tasks.js +1 -0
  173. package/dist/theme.d.ts +2 -0
  174. package/dist/theme.js +1 -0
  175. package/dist/types.d.ts +503 -0
  176. package/dist/types.js +1 -0
  177. package/dist/utils.d.ts +81 -0
  178. package/dist/utils.js +1 -0
  179. package/package.json +8 -9
  180. package/dist/src/ansi.js +0 -50
  181. package/dist/src/ansi.js.map +0 -1
  182. package/dist/src/base.js +0 -258
  183. package/dist/src/base.js.map +0 -1
  184. package/dist/src/core.js.map +0 -1
  185. package/dist/src/data/countries.js +0 -569
  186. package/dist/src/data/countries.js.map +0 -1
  187. package/dist/src/data/licenses.js +0 -480
  188. package/dist/src/data/licenses.js.map +0 -1
  189. package/dist/src/highlight.js +0 -185
  190. package/dist/src/highlight.js.map +0 -1
  191. package/dist/src/index.js +0 -66
  192. package/dist/src/index.js.map +0 -1
  193. package/dist/src/input.js +0 -158
  194. package/dist/src/input.js.map +0 -1
  195. package/dist/src/pipeline.js +0 -273
  196. package/dist/src/pipeline.js.map +0 -1
  197. package/dist/src/prompts/autocomplete.js +0 -171
  198. package/dist/src/prompts/autocomplete.js.map +0 -1
  199. package/dist/src/prompts/box.js +0 -225
  200. package/dist/src/prompts/box.js.map +0 -1
  201. package/dist/src/prompts/breadcrumb-search.js +0 -260
  202. package/dist/src/prompts/breadcrumb-search.js.map +0 -1
  203. package/dist/src/prompts/breadcrumb.js +0 -307
  204. package/dist/src/prompts/breadcrumb.js.map +0 -1
  205. package/dist/src/prompts/byte.js +0 -176
  206. package/dist/src/prompts/byte.js.map +0 -1
  207. package/dist/src/prompts/calculator.js +0 -243
  208. package/dist/src/prompts/calculator.js.map +0 -1
  209. package/dist/src/prompts/calendar.js +0 -430
  210. package/dist/src/prompts/calendar.js.map +0 -1
  211. package/dist/src/prompts/checkbox.js +0 -159
  212. package/dist/src/prompts/checkbox.js.map +0 -1
  213. package/dist/src/prompts/code.js +0 -271
  214. package/dist/src/prompts/code.js.map +0 -1
  215. package/dist/src/prompts/color.js +0 -165
  216. package/dist/src/prompts/color.js.map +0 -1
  217. package/dist/src/prompts/confirm.js +0 -55
  218. package/dist/src/prompts/confirm.js.map +0 -1
  219. package/dist/src/prompts/connection-string.js +0 -120
  220. package/dist/src/prompts/connection-string.js.map +0 -1
  221. package/dist/src/prompts/cron.js +0 -207
  222. package/dist/src/prompts/cron.js.map +0 -1
  223. package/dist/src/prompts/curl-utils.js +0 -71
  224. package/dist/src/prompts/curl-utils.js.map +0 -1
  225. package/dist/src/prompts/curl.js +0 -431
  226. package/dist/src/prompts/curl.js.map +0 -1
  227. package/dist/src/prompts/data-inspector.js +0 -261
  228. package/dist/src/prompts/data-inspector.js.map +0 -1
  229. package/dist/src/prompts/date.js +0 -185
  230. package/dist/src/prompts/date.js.map +0 -1
  231. package/dist/src/prompts/dependency.js +0 -283
  232. package/dist/src/prompts/dependency.js.map +0 -1
  233. package/dist/src/prompts/dial.js +0 -124
  234. package/dist/src/prompts/dial.js.map +0 -1
  235. package/dist/src/prompts/diff.js +0 -118
  236. package/dist/src/prompts/diff.js.map +0 -1
  237. package/dist/src/prompts/draw.js +0 -191
  238. package/dist/src/prompts/draw.js.map +0 -1
  239. package/dist/src/prompts/editor.js +0 -234
  240. package/dist/src/prompts/editor.js.map +0 -1
  241. package/dist/src/prompts/emoji.js +0 -226
  242. package/dist/src/prompts/emoji.js.map +0 -1
  243. package/dist/src/prompts/exec.js +0 -151
  244. package/dist/src/prompts/exec.js.map +0 -1
  245. package/dist/src/prompts/file.js +0 -217
  246. package/dist/src/prompts/file.js.map +0 -1
  247. package/dist/src/prompts/form.js +0 -241
  248. package/dist/src/prompts/form.js.map +0 -1
  249. package/dist/src/prompts/fuzzy-multi-column.js +0 -161
  250. package/dist/src/prompts/fuzzy-multi-column.js.map +0 -1
  251. package/dist/src/prompts/fuzzy.js +0 -147
  252. package/dist/src/prompts/fuzzy.js.map +0 -1
  253. package/dist/src/prompts/gauge.js +0 -137
  254. package/dist/src/prompts/gauge.js.map +0 -1
  255. package/dist/src/prompts/grid.js +0 -191
  256. package/dist/src/prompts/grid.js.map +0 -1
  257. package/dist/src/prompts/heatmap.js +0 -147
  258. package/dist/src/prompts/heatmap.js.map +0 -1
  259. package/dist/src/prompts/ip.js +0 -138
  260. package/dist/src/prompts/ip.js.map +0 -1
  261. package/dist/src/prompts/kanban.js +0 -233
  262. package/dist/src/prompts/kanban.js.map +0 -1
  263. package/dist/src/prompts/keypress.js +0 -54
  264. package/dist/src/prompts/keypress.js.map +0 -1
  265. package/dist/src/prompts/license.js +0 -144
  266. package/dist/src/prompts/license.js.map +0 -1
  267. package/dist/src/prompts/list.js +0 -124
  268. package/dist/src/prompts/list.js.map +0 -1
  269. package/dist/src/prompts/map.js +0 -262
  270. package/dist/src/prompts/map.js.map +0 -1
  271. package/dist/src/prompts/match.js +0 -271
  272. package/dist/src/prompts/match.js.map +0 -1
  273. package/dist/src/prompts/miller.js +0 -228
  274. package/dist/src/prompts/miller.js.map +0 -1
  275. package/dist/src/prompts/multi-column-select.js +0 -176
  276. package/dist/src/prompts/multi-column-select.js.map +0 -1
  277. package/dist/src/prompts/multi-range.js +0 -189
  278. package/dist/src/prompts/multi-range.js.map +0 -1
  279. package/dist/src/prompts/multi-select.js +0 -183
  280. package/dist/src/prompts/multi-select.js.map +0 -1
  281. package/dist/src/prompts/number.js +0 -166
  282. package/dist/src/prompts/number.js.map +0 -1
  283. package/dist/src/prompts/otp.js +0 -107
  284. package/dist/src/prompts/otp.js.map +0 -1
  285. package/dist/src/prompts/pattern.js +0 -252
  286. package/dist/src/prompts/pattern.js.map +0 -1
  287. package/dist/src/prompts/phone.js +0 -398
  288. package/dist/src/prompts/phone.js.map +0 -1
  289. package/dist/src/prompts/quiz-select.js +0 -114
  290. package/dist/src/prompts/quiz-select.js.map +0 -1
  291. package/dist/src/prompts/quiz-text.js +0 -98
  292. package/dist/src/prompts/quiz-text.js.map +0 -1
  293. package/dist/src/prompts/range.js +0 -164
  294. package/dist/src/prompts/range.js.map +0 -1
  295. package/dist/src/prompts/rating.js +0 -83
  296. package/dist/src/prompts/rating.js.map +0 -1
  297. package/dist/src/prompts/regex.js +0 -145
  298. package/dist/src/prompts/regex.js.map +0 -1
  299. package/dist/src/prompts/region.js +0 -170
  300. package/dist/src/prompts/region.js.map +0 -1
  301. package/dist/src/prompts/schedule.js +0 -270
  302. package/dist/src/prompts/schedule.js.map +0 -1
  303. package/dist/src/prompts/scroll.js +0 -155
  304. package/dist/src/prompts/scroll.js.map +0 -1
  305. package/dist/src/prompts/seat.js +0 -164
  306. package/dist/src/prompts/seat.js.map +0 -1
  307. package/dist/src/prompts/select-range.js +0 -148
  308. package/dist/src/prompts/select-range.js.map +0 -1
  309. package/dist/src/prompts/select.js +0 -163
  310. package/dist/src/prompts/select.js.map +0 -1
  311. package/dist/src/prompts/semver.js +0 -43
  312. package/dist/src/prompts/semver.js.map +0 -1
  313. package/dist/src/prompts/shortcut.js +0 -133
  314. package/dist/src/prompts/shortcut.js.map +0 -1
  315. package/dist/src/prompts/slider.js +0 -69
  316. package/dist/src/prompts/slider.js.map +0 -1
  317. package/dist/src/prompts/slot.js +0 -117
  318. package/dist/src/prompts/slot.js.map +0 -1
  319. package/dist/src/prompts/snippet.js +0 -228
  320. package/dist/src/prompts/snippet.js.map +0 -1
  321. package/dist/src/prompts/sort-grid.js +0 -151
  322. package/dist/src/prompts/sort-grid.js.map +0 -1
  323. package/dist/src/prompts/sort.js +0 -166
  324. package/dist/src/prompts/sort.js.map +0 -1
  325. package/dist/src/prompts/spam.js +0 -80
  326. package/dist/src/prompts/spam.js.map +0 -1
  327. package/dist/src/prompts/spreadsheet.js +0 -240
  328. package/dist/src/prompts/spreadsheet.js.map +0 -1
  329. package/dist/src/prompts/table.js +0 -120
  330. package/dist/src/prompts/table.js.map +0 -1
  331. package/dist/src/prompts/text.js +0 -317
  332. package/dist/src/prompts/text.js.map +0 -1
  333. package/dist/src/prompts/time.js +0 -211
  334. package/dist/src/prompts/time.js.map +0 -1
  335. package/dist/src/prompts/toggle.js +0 -53
  336. package/dist/src/prompts/toggle.js.map +0 -1
  337. package/dist/src/prompts/transfer.js +0 -207
  338. package/dist/src/prompts/transfer.js.map +0 -1
  339. package/dist/src/prompts/tree-select.js +0 -270
  340. package/dist/src/prompts/tree-select.js.map +0 -1
  341. package/dist/src/prompts/tree.js +0 -233
  342. package/dist/src/prompts/tree.js.map +0 -1
  343. package/dist/src/prompts/wait.js +0 -79
  344. package/dist/src/prompts/wait.js.map +0 -1
  345. package/dist/src/spinner.js +0 -105
  346. package/dist/src/spinner.js.map +0 -1
  347. package/dist/src/symbols.js +0 -66
  348. package/dist/src/symbols.js.map +0 -1
  349. package/dist/src/tasks.js +0 -231
  350. package/dist/src/tasks.js.map +0 -1
  351. package/dist/src/theme.js +0 -29
  352. package/dist/src/theme.js.map +0 -1
  353. package/dist/src/types.js +0 -8
  354. package/dist/src/types.js.map +0 -1
  355. package/dist/src/utils.js +0 -480
  356. package/dist/src/utils.js.map +0 -1
@@ -1,398 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "PhonePrompt", {
6
- enumerable: true,
7
- get: function() {
8
- return PhonePrompt;
9
- }
10
- });
11
- const _base = require("../base");
12
- const _countries = require("../data/countries");
13
- const _theme = require("../theme");
14
- const _ansi = require("../ansi");
15
- const _utils = require("../utils");
16
- function _define_property(obj, key, value) {
17
- if (key in obj) {
18
- Object.defineProperty(obj, key, {
19
- value: value,
20
- enumerable: true,
21
- configurable: true,
22
- writable: true
23
- });
24
- } else {
25
- obj[key] = value;
26
- }
27
- return obj;
28
- }
29
- let PhonePrompt = class PhonePrompt extends _base.Prompt {
30
- get currentCountry() {
31
- return _countries.COUNTRIES[this.selectedCountryIndex];
32
- }
33
- get mask() {
34
- return this.currentCountry[3];
35
- }
36
- get dialCode() {
37
- return this.currentCountry[2];
38
- }
39
- /**
40
- * Maps a raw index (index in the digit-only string) to a visual index in the formatted string.
41
- */ getVisualIndex(rawIndex, mask) {
42
- let rawCounter = 0;
43
- for(let i = 0; i < mask.length; i++){
44
- if (rawCounter === rawIndex) {
45
- if (mask[i] === '#') {
46
- return i;
47
- }
48
- }
49
- if (mask[i] === '#') {
50
- rawCounter++;
51
- }
52
- }
53
- // If we went past the end
54
- return mask.length;
55
- }
56
- /**
57
- * Maps rawIndex to visual index, handling skipping of static characters.
58
- */ getVisualPosition(rawIndex) {
59
- const mask = this.mask;
60
- let v = 0;
61
- let r = 0;
62
- while(v < mask.length){
63
- if (r === rawIndex) {
64
- // We reached the raw position.
65
- // However, if the current mask char is NOT a placeholder, we should skip it
66
- // because the user doesn't type it.
67
- // E.g. mask "###-###". rawIndex 3.
68
- // v=0(#), r=0 -> next
69
- // v=1(#), r=1 -> next
70
- // v=2(#), r=2 -> next
71
- // v=3(-). We are at r=3. The cursor should be at v=4 (the next #).
72
- while(v < mask.length && mask[v] !== '#'){
73
- v++;
74
- }
75
- return v;
76
- }
77
- if (mask[v] === '#') {
78
- r++;
79
- }
80
- v++;
81
- }
82
- return v;
83
- }
84
- /**
85
- * Formats the raw number according to the mask.
86
- */ formatNumber() {
87
- const mask = this.mask;
88
- let result = '';
89
- let rawIdx = 0;
90
- for(let i = 0; i < mask.length; i++){
91
- const m = mask[i];
92
- if (m === '#') {
93
- if (rawIdx < this.rawNumber.length) {
94
- result += this.rawNumber[rawIdx];
95
- rawIdx++;
96
- } else {
97
- result += m; // Placeholder
98
- }
99
- } else {
100
- result += m;
101
- }
102
- }
103
- return result;
104
- }
105
- /**
106
- * Renders the formatted number with highlighting.
107
- */ renderFormattedNumber() {
108
- const mask = this.mask;
109
- let output = '';
110
- let rawIdx = 0;
111
- for(let i = 0; i < mask.length; i++){
112
- const m = mask[i];
113
- if (m === '#') {
114
- if (rawIdx < this.rawNumber.length) {
115
- // Typed digit
116
- output += _theme.theme.main + this.rawNumber[rawIdx] + _ansi.ANSI.RESET;
117
- rawIdx++;
118
- } else {
119
- // Placeholder
120
- output += _theme.theme.muted + '#' + _ansi.ANSI.RESET;
121
- }
122
- } else {
123
- if (rawIdx > 0 || rawIdx === 0 && this.rawNumber.length > 0) {
124
- output += _theme.theme.muted + m + _ansi.ANSI.RESET;
125
- } else {
126
- output += _theme.theme.muted + m + _ansi.ANSI.RESET;
127
- }
128
- }
129
- }
130
- return output;
131
- }
132
- render(firstRender) {
133
- if (!firstRender && this.lastLinesUp > 0) {
134
- this.print(`\x1b[${this.lastLinesUp}B`);
135
- }
136
- // 1. Title/Message
137
- const check = this.errorMsg ? _theme.theme.error + '✖' : _theme.theme.success + '?';
138
- const title = `${check} ${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET} `;
139
- // 2. Build Components
140
- const country = this.currentCountry;
141
- // Country Section: "+84 (VN)"
142
- // Highlight if active
143
- const prefixStr = `+${country[2]} (${country[0]})`;
144
- let prefixRender = '';
145
- if (this.activeSection === 'country') {
146
- prefixRender = _ansi.ANSI.BG_BLUE + _ansi.ANSI.FG_WHITE + prefixStr + _ansi.ANSI.RESET;
147
- } else {
148
- prefixRender = _theme.theme.muted + prefixStr + _ansi.ANSI.RESET;
149
- }
150
- // Input Section
151
- const formatted = this.renderFormattedNumber();
152
- const inputRender = formatted;
153
- // Layout: [Prefix] [Input]
154
- const line = `${prefixRender} ${inputRender}`;
155
- let output = title + line;
156
- if (this.errorMsg) {
157
- output += `\n${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`;
158
- } else if (this.activeSection === 'country' && this.searchBuffer) {
159
- output += `\n${_theme.theme.muted}Searching: "${this.searchBuffer}"...${_ansi.ANSI.RESET}`;
160
- }
161
- this.renderFrame(output);
162
- // 3. Cursor Positioning
163
- const errorOffset = this.errorMsg || this.activeSection === 'country' && this.searchBuffer ? 1 : 0;
164
- const totalRows = 1 + errorOffset;
165
- // Reset cursor to end of render
166
- const linesUp = totalRows - 1;
167
- if (linesUp > 0) {
168
- this.print(`\x1b[${linesUp}A`);
169
- }
170
- this.lastLinesUp = linesUp;
171
- this.print(_ansi.ANSI.CURSOR_LEFT);
172
- // Calculate horizontal position
173
- const titleWidth = (0, _utils.stripAnsi)(title).length;
174
- if (this.activeSection === 'country') {
175
- // Place cursor at end of prefix text? Or keep it hidden?
176
- // Let's place it at the end of the prefix.
177
- const prefixWidth = prefixStr.length;
178
- const target = titleWidth + prefixWidth;
179
- if (target > 0) this.print(`\x1b[${target}C`);
180
- } else {
181
- // Active is number
182
- // Start position = Title + Prefix + Space
183
- const prefixWidth = prefixStr.length;
184
- const startX = titleWidth + prefixWidth + 1;
185
- // Visual offset within input
186
- const visualOffset = this.getVisualPosition(this.cursor);
187
- const target = startX + visualOffset;
188
- if (target > 0) this.print(`\x1b[${target}C`);
189
- }
190
- this.print(_ansi.ANSI.SHOW_CURSOR);
191
- }
192
- cleanup() {
193
- if (this.lastLinesUp > 0) {
194
- this.print(`\x1b[${this.lastLinesUp}B`);
195
- this.lastLinesUp = 0;
196
- }
197
- super.cleanup();
198
- }
199
- handleInput(char) {
200
- // Handle common keys
201
- if (char === '\r' || char === '\n') {
202
- this.validateAndSubmit();
203
- return;
204
- }
205
- if (char === '\t') {
206
- // Toggle section
207
- this.activeSection = this.activeSection === 'country' ? 'number' : 'country';
208
- this.render(false);
209
- return;
210
- }
211
- // Backspace
212
- if (char === '\x7f' || char === '\u0008') {
213
- if (this.activeSection === 'number') {
214
- if (this.cursor > 0) {
215
- this.rawNumber = this.rawNumber.slice(0, this.cursor - 1) + this.rawNumber.slice(this.cursor);
216
- this.cursor--;
217
- this.errorMsg = '';
218
- this.render(false);
219
- } else {
220
- // If at start of number, maybe backspace into country section?
221
- this.activeSection = 'country';
222
- this.render(false);
223
- }
224
- } else {
225
- // Country section
226
- if (this.searchBuffer.length > 0) {
227
- this.searchBuffer = this.searchBuffer.slice(0, -1);
228
- this.filterCountries();
229
- this.render(false);
230
- }
231
- }
232
- return;
233
- }
234
- // Arrows
235
- if (char === '\u001b[D') {
236
- if (this.activeSection === 'number') {
237
- if (this.cursor > 0) {
238
- this.cursor--;
239
- } else {
240
- this.activeSection = 'country';
241
- }
242
- }
243
- this.render(false);
244
- return;
245
- }
246
- if (char === '\u001b[C') {
247
- if (this.activeSection === 'country') {
248
- this.activeSection = 'number';
249
- } else {
250
- if (this.cursor < this.rawNumber.length) {
251
- this.cursor++;
252
- }
253
- }
254
- this.render(false);
255
- return;
256
- }
257
- if (char === '\u001b[A') {
258
- if (this.activeSection === 'country') {
259
- this.cycleCountry(-1);
260
- }
261
- this.render(false);
262
- return;
263
- }
264
- if (char === '\u001b[B') {
265
- if (this.activeSection === 'country') {
266
- this.cycleCountry(1);
267
- }
268
- this.render(false);
269
- return;
270
- }
271
- // Typing
272
- if (!/^[\x00-\x1F]/.test(char) && !char.startsWith('\x1b')) {
273
- if (this.activeSection === 'country') {
274
- this.searchBuffer += char;
275
- this.filterCountries();
276
- this.render(false);
277
- } else {
278
- // Number input: digits only
279
- if (/^\d+$/.test(char)) {
280
- // Check max length
281
- const maxLen = this.getMaxRawLength();
282
- if (this.rawNumber.length < maxLen) {
283
- this.rawNumber = this.rawNumber.slice(0, this.cursor) + char + this.rawNumber.slice(this.cursor);
284
- this.cursor++;
285
- this.errorMsg = '';
286
- this.render(false);
287
- }
288
- }
289
- }
290
- }
291
- }
292
- filterCountries() {
293
- // Simple search logic
294
- if (!this.searchBuffer) {
295
- this.filteredIndices = _countries.COUNTRIES.map((_, i)=>i);
296
- return;
297
- }
298
- // Prioritize: Starts with ISO, Starts with Name, Fuzzy Name
299
- const buf = this.searchBuffer.toLowerCase();
300
- const matches = _countries.COUNTRIES.map((c, i)=>{
301
- const iso = c[0].toLowerCase();
302
- const name = c[1].toLowerCase();
303
- const dial = c[2];
304
- let score = 0;
305
- if (iso.startsWith(buf)) score += 100;
306
- if (name.startsWith(buf)) score += 50;
307
- if (dial.startsWith(buf)) score += 20; // Search by code
308
- const fuzzy = (0, _utils.fuzzyMatch)(this.searchBuffer, c[1]);
309
- if (fuzzy) score += fuzzy.score;
310
- return {
311
- index: i,
312
- score
313
- };
314
- }).filter((x)=>x.score > 0).sort((a, b)=>b.score - a.score);
315
- this.filteredIndices = matches.map((m)=>m.index);
316
- // Auto-select first match
317
- if (this.filteredIndices.length > 0) {
318
- this.selectedCountryIndex = this.filteredIndices[0];
319
- // If we changed country, we should validate/truncate current rawNumber?
320
- // The mask might change.
321
- this.enforceMaxLen();
322
- }
323
- }
324
- cycleCountry(dir) {
325
- // Cycle within filtered list
326
- const currentInFiltered = this.filteredIndices.indexOf(this.selectedCountryIndex);
327
- let nextIdx = currentInFiltered + dir;
328
- if (nextIdx < 0) nextIdx = this.filteredIndices.length - 1;
329
- if (nextIdx >= this.filteredIndices.length) nextIdx = 0;
330
- this.selectedCountryIndex = this.filteredIndices[nextIdx];
331
- this.enforceMaxLen();
332
- }
333
- getMaxRawLength() {
334
- return this.mask.split('#').length - 1;
335
- }
336
- enforceMaxLen() {
337
- const max = this.getMaxRawLength();
338
- if (this.rawNumber.length > max) {
339
- this.rawNumber = this.rawNumber.slice(0, max);
340
- if (this.cursor > max) this.cursor = max;
341
- }
342
- }
343
- validateAndSubmit() {
344
- if (this.options.strict) {
345
- const max = this.getMaxRawLength();
346
- if (this.rawNumber.length !== max) {
347
- this.errorMsg = `Number too short (expected ${max} digits)`;
348
- this.render(false);
349
- return;
350
- }
351
- }
352
- // Validation callback
353
- const e164 = `+${this.dialCode}${this.rawNumber}`;
354
- if (this.options.validate) {
355
- const valid = this.options.validate(e164); // Pass strict format
356
- if (typeof valid === 'string') {
357
- this.errorMsg = valid;
358
- this.render(false);
359
- return;
360
- }
361
- if (valid === false) {
362
- this.errorMsg = 'Invalid phone number';
363
- this.render(false);
364
- return;
365
- }
366
- }
367
- this.submit(e164);
368
- }
369
- handleMouse(event) {
370
- if (event.action === 'press' || event.action === 'move') {
371
- // This is hard to map without exact coordinates of sections.
372
- // Simplified: Scroll changes country if active.
373
- }
374
- if (event.scroll) {
375
- if (this.activeSection === 'country') {
376
- this.cycleCountry(event.scroll === 'up' ? -1 : 1);
377
- this.render(false);
378
- }
379
- }
380
- }
381
- constructor(options){
382
- super(options), _define_property(this, "activeSection", 'number'), _define_property(this, "selectedCountryIndex", 0), _define_property(this, "rawNumber", '') // Only digits
383
- , _define_property(this, "cursor", 0) // Index in rawNumber
384
- , _define_property(this, "searchBuffer", ''), _define_property(this, "lastLinesUp", 0), _define_property(this, "errorMsg", ''), // For country search/filtering
385
- _define_property(this, "filteredIndices", []);
386
- // Initialize country
387
- if (options.defaultCountry) {
388
- const idx = _countries.COUNTRIES.findIndex((c)=>c[0] === options.defaultCountry?.toUpperCase());
389
- if (idx !== -1) this.selectedCountryIndex = idx;
390
- } else {
391
- // Default to US or VN? Let's default to index 0 (US in our list usually, or whatever is first)
392
- this.selectedCountryIndex = 0;
393
- }
394
- this.filteredIndices = _countries.COUNTRIES.map((_, i)=>i);
395
- }
396
- };
397
-
398
- //# sourceMappingURL=phone.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/prompts/phone.ts"],"sourcesContent":["import { Prompt } from '../base';\nimport { PhoneOptions } from '../types';\nimport { COUNTRIES, CountryEntry } from '../data/countries';\nimport { theme } from '../theme';\nimport { ANSI } from '../ansi';\nimport { fuzzyMatch, stripAnsi } from '../utils';\n\nexport class PhonePrompt extends Prompt<string, PhoneOptions> {\n protected activeSection: 'country' | 'number' = 'number';\n protected selectedCountryIndex: number = 0;\n protected rawNumber: string = ''; // Only digits\n protected cursor: number = 0; // Index in rawNumber\n protected searchBuffer: string = '';\n protected lastLinesUp: number = 0;\n protected errorMsg: string = '';\n\n // For country search/filtering\n protected filteredIndices: number[] = [];\n\n constructor(options: PhoneOptions) {\n super(options);\n\n // Initialize country\n if (options.defaultCountry) {\n const idx = COUNTRIES.findIndex(c => c[0] === options.defaultCountry?.toUpperCase());\n if (idx !== -1) this.selectedCountryIndex = idx;\n } else {\n // Default to US or VN? Let's default to index 0 (US in our list usually, or whatever is first)\n this.selectedCountryIndex = 0;\n }\n\n this.filteredIndices = COUNTRIES.map((_, i) => i);\n }\n\n private get currentCountry(): CountryEntry {\n return COUNTRIES[this.selectedCountryIndex];\n }\n\n private get mask(): string {\n return this.currentCountry[3];\n }\n\n private get dialCode(): string {\n return this.currentCountry[2];\n }\n\n /**\n * Maps a raw index (index in the digit-only string) to a visual index in the formatted string.\n */\n private getVisualIndex(rawIndex: number, mask: string): number {\n let rawCounter = 0;\n for (let i = 0; i < mask.length; i++) {\n if (rawCounter === rawIndex) {\n if (mask[i] === '#') {\n return i;\n }\n }\n\n if (mask[i] === '#') {\n rawCounter++;\n }\n }\n // If we went past the end\n return mask.length;\n }\n\n /**\n * Maps rawIndex to visual index, handling skipping of static characters.\n */\n private getVisualPosition(rawIndex: number): number {\n const mask = this.mask;\n let v = 0;\n let r = 0;\n\n while (v < mask.length) {\n if (r === rawIndex) {\n // We reached the raw position. \n // However, if the current mask char is NOT a placeholder, we should skip it\n // because the user doesn't type it.\n // E.g. mask \"###-###\". rawIndex 3.\n // v=0(#), r=0 -> next\n // v=1(#), r=1 -> next\n // v=2(#), r=2 -> next\n // v=3(-). We are at r=3. The cursor should be at v=4 (the next #).\n while (v < mask.length && mask[v] !== '#') {\n v++;\n }\n return v;\n }\n\n if (mask[v] === '#') {\n r++;\n }\n v++;\n }\n return v;\n }\n\n /**\n * Formats the raw number according to the mask.\n */\n private formatNumber(): string {\n const mask = this.mask;\n let result = '';\n let rawIdx = 0;\n\n for (let i = 0; i < mask.length; i++) {\n const m = mask[i];\n if (m === '#') {\n if (rawIdx < this.rawNumber.length) {\n result += this.rawNumber[rawIdx];\n rawIdx++;\n } else {\n result += m; // Placeholder\n }\n } else {\n result += m;\n }\n }\n return result;\n }\n\n /**\n * Renders the formatted number with highlighting.\n */\n private renderFormattedNumber(): string {\n const mask = this.mask;\n let output = '';\n let rawIdx = 0;\n\n for (let i = 0; i < mask.length; i++) {\n const m = mask[i];\n if (m === '#') {\n if (rawIdx < this.rawNumber.length) {\n // Typed digit\n output += theme.main + this.rawNumber[rawIdx] + ANSI.RESET;\n rawIdx++;\n } else {\n // Placeholder\n output += theme.muted + '#' + ANSI.RESET;\n }\n } else {\n if (rawIdx > 0 || (rawIdx === 0 && this.rawNumber.length > 0)) {\n output += theme.muted + m + ANSI.RESET;\n } else {\n output += theme.muted + m + ANSI.RESET;\n }\n }\n }\n return output;\n }\n\n protected render(firstRender: boolean) {\n if (!firstRender && this.lastLinesUp > 0) {\n this.print(`\\x1b[${this.lastLinesUp}B`);\n }\n\n // 1. Title/Message\n const check = this.errorMsg ? theme.error + '✖' : theme.success + '?';\n const title = `${check} ${theme.title}${this.options.message}${ANSI.RESET} `;\n\n // 2. Build Components\n const country = this.currentCountry;\n\n // Country Section: \"+84 (VN)\"\n // Highlight if active\n const prefixStr = `+${country[2]} (${country[0]})`;\n let prefixRender = '';\n if (this.activeSection === 'country') {\n prefixRender = ANSI.BG_BLUE + ANSI.FG_WHITE + prefixStr + ANSI.RESET;\n } else {\n prefixRender = theme.muted + prefixStr + ANSI.RESET;\n }\n\n // Input Section\n const formatted = this.renderFormattedNumber();\n const inputRender = formatted;\n\n // Layout: [Prefix] [Input]\n const line = `${prefixRender} ${inputRender}`;\n\n let output = title + line;\n\n if (this.errorMsg) {\n output += `\\n${theme.error}>> ${this.errorMsg}${ANSI.RESET}`;\n } else if (this.activeSection === 'country' && this.searchBuffer) {\n output += `\\n${theme.muted}Searching: \"${this.searchBuffer}\"...${ANSI.RESET}`;\n }\n\n this.renderFrame(output);\n\n // 3. Cursor Positioning\n const errorOffset = (this.errorMsg || (this.activeSection === 'country' && this.searchBuffer)) ? 1 : 0;\n const totalRows = 1 + errorOffset;\n\n // Reset cursor to end of render\n const linesUp = totalRows - 1;\n if (linesUp > 0) {\n this.print(`\\x1b[${linesUp}A`);\n }\n this.lastLinesUp = linesUp;\n\n this.print(ANSI.CURSOR_LEFT);\n\n // Calculate horizontal position\n const titleWidth = stripAnsi(title).length;\n\n if (this.activeSection === 'country') {\n // Place cursor at end of prefix text? Or keep it hidden?\n // Let's place it at the end of the prefix.\n const prefixWidth = prefixStr.length;\n const target = titleWidth + prefixWidth;\n if (target > 0) this.print(`\\x1b[${target}C`);\n } else {\n // Active is number\n // Start position = Title + Prefix + Space\n const prefixWidth = prefixStr.length;\n const startX = titleWidth + prefixWidth + 1;\n\n // Visual offset within input\n const visualOffset = this.getVisualPosition(this.cursor);\n const target = startX + visualOffset;\n\n if (target > 0) this.print(`\\x1b[${target}C`);\n }\n\n this.print(ANSI.SHOW_CURSOR);\n }\n\n protected cleanup() {\n if (this.lastLinesUp > 0) {\n this.print(`\\x1b[${this.lastLinesUp}B`);\n this.lastLinesUp = 0;\n }\n super.cleanup();\n }\n\n protected handleInput(char: string) {\n // Handle common keys\n if (char === '\\r' || char === '\\n') {\n this.validateAndSubmit();\n return;\n }\n\n if (char === '\\t') {\n // Toggle section\n this.activeSection = this.activeSection === 'country' ? 'number' : 'country';\n this.render(false);\n return;\n }\n\n // Backspace\n if (char === '\\x7f' || char === '\\u0008') {\n if (this.activeSection === 'number') {\n if (this.cursor > 0) {\n this.rawNumber = this.rawNumber.slice(0, this.cursor - 1) + this.rawNumber.slice(this.cursor);\n this.cursor--;\n this.errorMsg = '';\n this.render(false);\n } else {\n // If at start of number, maybe backspace into country section?\n this.activeSection = 'country';\n this.render(false);\n }\n } else {\n // Country section\n if (this.searchBuffer.length > 0) {\n this.searchBuffer = this.searchBuffer.slice(0, -1);\n this.filterCountries();\n this.render(false);\n }\n }\n return;\n }\n\n // Arrows\n if (char === '\\u001b[D') { // Left\n if (this.activeSection === 'number') {\n if (this.cursor > 0) {\n this.cursor--;\n } else {\n this.activeSection = 'country';\n }\n }\n this.render(false);\n return;\n }\n\n if (char === '\\u001b[C') { // Right\n if (this.activeSection === 'country') {\n this.activeSection = 'number';\n } else {\n if (this.cursor < this.rawNumber.length) {\n this.cursor++;\n }\n }\n this.render(false);\n return;\n }\n\n if (char === '\\u001b[A') { // Up\n if (this.activeSection === 'country') {\n this.cycleCountry(-1);\n }\n this.render(false);\n return;\n }\n\n if (char === '\\u001b[B') { // Down\n if (this.activeSection === 'country') {\n this.cycleCountry(1);\n }\n this.render(false);\n return;\n }\n\n // Typing\n if (!/^[\\x00-\\x1F]/.test(char) && !char.startsWith('\\x1b')) {\n if (this.activeSection === 'country') {\n this.searchBuffer += char;\n this.filterCountries();\n this.render(false);\n } else {\n // Number input: digits only\n if (/^\\d+$/.test(char)) {\n // Check max length\n const maxLen = this.getMaxRawLength();\n if (this.rawNumber.length < maxLen) {\n this.rawNumber = this.rawNumber.slice(0, this.cursor) + char + this.rawNumber.slice(this.cursor);\n this.cursor++;\n this.errorMsg = '';\n this.render(false);\n }\n }\n }\n }\n }\n\n private filterCountries() {\n // Simple search logic\n if (!this.searchBuffer) {\n this.filteredIndices = COUNTRIES.map((_, i) => i);\n return;\n }\n\n // Prioritize: Starts with ISO, Starts with Name, Fuzzy Name\n const buf = this.searchBuffer.toLowerCase();\n\n const matches = COUNTRIES.map((c, i) => {\n const iso = c[0].toLowerCase();\n const name = c[1].toLowerCase();\n const dial = c[2];\n\n let score = 0;\n if (iso.startsWith(buf)) score += 100;\n if (name.startsWith(buf)) score += 50;\n if (dial.startsWith(buf)) score += 20; // Search by code\n\n const fuzzy = fuzzyMatch(this.searchBuffer, c[1]);\n if (fuzzy) score += fuzzy.score;\n\n return { index: i, score };\n }).filter(x => x.score > 0)\n .sort((a, b) => b.score - a.score);\n\n this.filteredIndices = matches.map(m => m.index);\n\n // Auto-select first match\n if (this.filteredIndices.length > 0) {\n this.selectedCountryIndex = this.filteredIndices[0];\n\n // If we changed country, we should validate/truncate current rawNumber?\n // The mask might change.\n this.enforceMaxLen();\n }\n }\n\n private cycleCountry(dir: number) {\n // Cycle within filtered list\n const currentInFiltered = this.filteredIndices.indexOf(this.selectedCountryIndex);\n let nextIdx = currentInFiltered + dir;\n\n if (nextIdx < 0) nextIdx = this.filteredIndices.length - 1;\n if (nextIdx >= this.filteredIndices.length) nextIdx = 0;\n\n this.selectedCountryIndex = this.filteredIndices[nextIdx];\n this.enforceMaxLen();\n }\n\n private getMaxRawLength(): number {\n return this.mask.split('#').length - 1;\n }\n\n private enforceMaxLen() {\n const max = this.getMaxRawLength();\n if (this.rawNumber.length > max) {\n this.rawNumber = this.rawNumber.slice(0, max);\n if (this.cursor > max) this.cursor = max;\n }\n }\n\n private validateAndSubmit() {\n if (this.options.strict) {\n const max = this.getMaxRawLength();\n if (this.rawNumber.length !== max) {\n this.errorMsg = `Number too short (expected ${max} digits)`;\n this.render(false);\n return;\n }\n }\n\n // Validation callback\n const e164 = `+${this.dialCode}${this.rawNumber}`;\n if (this.options.validate) {\n const valid = this.options.validate(e164); // Pass strict format\n if (typeof valid === 'string') {\n this.errorMsg = valid;\n this.render(false);\n return;\n }\n if (valid === false) {\n this.errorMsg = 'Invalid phone number';\n this.render(false);\n return;\n }\n }\n\n this.submit(e164);\n }\n\n protected handleMouse(event: any) {\n if (event.action === 'press' || event.action === 'move') {\n // This is hard to map without exact coordinates of sections.\n // Simplified: Scroll changes country if active.\n }\n\n if (event.scroll) {\n if (this.activeSection === 'country') {\n this.cycleCountry(event.scroll === 'up' ? -1 : 1);\n this.render(false);\n }\n }\n }\n}\n"],"names":["PhonePrompt","Prompt","currentCountry","COUNTRIES","selectedCountryIndex","mask","dialCode","getVisualIndex","rawIndex","rawCounter","i","length","getVisualPosition","v","r","formatNumber","result","rawIdx","m","rawNumber","renderFormattedNumber","output","theme","main","ANSI","RESET","muted","render","firstRender","lastLinesUp","print","check","errorMsg","error","success","title","options","message","country","prefixStr","prefixRender","activeSection","BG_BLUE","FG_WHITE","formatted","inputRender","line","searchBuffer","renderFrame","errorOffset","totalRows","linesUp","CURSOR_LEFT","titleWidth","stripAnsi","prefixWidth","target","startX","visualOffset","cursor","SHOW_CURSOR","cleanup","handleInput","char","validateAndSubmit","slice","filterCountries","cycleCountry","test","startsWith","maxLen","getMaxRawLength","filteredIndices","map","_","buf","toLowerCase","matches","c","iso","name","dial","score","fuzzy","fuzzyMatch","index","filter","x","sort","a","b","enforceMaxLen","dir","currentInFiltered","indexOf","nextIdx","split","max","strict","e164","validate","valid","submit","handleMouse","event","action","scroll","defaultCountry","idx","findIndex","toUpperCase"],"mappings":";;;;+BAOaA;;;eAAAA;;;sBAPU;2BAEiB;uBAClB;sBACD;uBACiB;;;;;;;;;;;;;;AAE/B,IAAA,AAAMA,cAAN,MAAMA,oBAAoBC,YAAM;IA2BnC,IAAYC,iBAA+B;QACvC,OAAOC,oBAAS,CAAC,IAAI,CAACC,oBAAoB,CAAC;IAC/C;IAEA,IAAYC,OAAe;QACvB,OAAO,IAAI,CAACH,cAAc,CAAC,EAAE;IACjC;IAEA,IAAYI,WAAmB;QAC3B,OAAO,IAAI,CAACJ,cAAc,CAAC,EAAE;IACjC;IAEA;;KAEC,GACD,AAAQK,eAAeC,QAAgB,EAAEH,IAAY,EAAU;QAC3D,IAAII,aAAa;QACjB,IAAK,IAAIC,IAAI,GAAGA,IAAIL,KAAKM,MAAM,EAAED,IAAK;YAClC,IAAID,eAAeD,UAAU;gBACzB,IAAIH,IAAI,CAACK,EAAE,KAAK,KAAK;oBACjB,OAAOA;gBACX;YACJ;YAEA,IAAIL,IAAI,CAACK,EAAE,KAAK,KAAK;gBACjBD;YACJ;QACJ;QACA,0BAA0B;QAC1B,OAAOJ,KAAKM,MAAM;IACtB;IAEA;;KAEC,GACD,AAAQC,kBAAkBJ,QAAgB,EAAU;QAChD,MAAMH,OAAO,IAAI,CAACA,IAAI;QACtB,IAAIQ,IAAI;QACR,IAAIC,IAAI;QAER,MAAOD,IAAIR,KAAKM,MAAM,CAAE;YACpB,IAAIG,MAAMN,UAAU;gBAChB,gCAAgC;gBAChC,4EAA4E;gBAC5E,oCAAoC;gBACpC,mCAAmC;gBACnC,sBAAsB;gBACtB,sBAAsB;gBACtB,sBAAsB;gBACtB,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WAChD,uBAAUrC,wBAA+B,IACzC,uBAAUe,aAAoB,IAAI,cAAc;UAChD,uBAAUwC,UAAiB,GAAG,qBAAqB;UACnD,uBAAUZ,gBAAuB,KACjC,uBAAUlB,eAAsB,IAChC,uBAAUG,YAAmB,KAE7B,+BAA+B;QAC/B,uBAAUwC,mBAA4B,EAAE;QAKpC,qBAAqB;QACrB,IAAIpC,QAAQuE,cAAc,EAAE;YACxB,MAAMC,MAAMzG,oBAAS,CAAC0G,SAAS,CAAC/B,CAAAA,IAAKA,CAAC,CAAC,EAAE,KAAK1C,QAAQuE,cAAc,EAAEG;YACtE,IAAIF,QAAQ,CAAC,GAAG,IAAI,CAACxG,oBAAoB,GAAGwG;QAChD,OAAO;YACH,+FAA+F;YAC/F,IAAI,CAACxG,oBAAoB,GAAG;QAChC;QAEA,IAAI,CAACoE,eAAe,GAAGrE,oBAAS,CAACsE,GAAG,CAAC,CAACC,GAAGhE,IAAMA;IACnD;AA2ZJ"}
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "QuizSelectPrompt", {
6
- enumerable: true,
7
- get: function() {
8
- return QuizSelectPrompt;
9
- }
10
- });
11
- const _ansi = require("../ansi");
12
- const _theme = require("../theme");
13
- const _symbols = require("../symbols");
14
- const _select = require("./select");
15
- function _define_property(obj, key, value) {
16
- if (key in obj) {
17
- Object.defineProperty(obj, key, {
18
- value: value,
19
- enumerable: true,
20
- configurable: true,
21
- writable: true
22
- });
23
- } else {
24
- obj[key] = value;
25
- }
26
- return obj;
27
- }
28
- let QuizSelectPrompt = class QuizSelectPrompt extends _select.SelectPrompt {
29
- handleInput(char) {
30
- if (this.status === 'revealed') {
31
- // Wait for Enter to submit
32
- if (char === '\r' || char === '\n') {
33
- const choices = this.getFilteredChoices();
34
- // Ensure index is valid, though it should be captured
35
- const value = choices[this.userSelectionIndex] ? choices[this.userSelectionIndex].value : null;
36
- this.submit(value);
37
- }
38
- return;
39
- }
40
- if (this.status === 'pending') {
41
- // Intercept Enter
42
- if (char === '\r' || char === '\n') {
43
- const choices = this.getFilteredChoices();
44
- if (choices.length === 0) return;
45
- if (this.isSeparator(choices[this.selectedIndex])) return;
46
- this.userSelectionIndex = this.selectedIndex;
47
- const selectedChoice = choices[this.userSelectionIndex];
48
- // Check correctness
49
- this.isCorrect = selectedChoice.value === this.options.correctValue;
50
- this.status = 'revealed';
51
- this.render(false);
52
- return;
53
- }
54
- // Delegate navigation to super
55
- super.handleInput(char);
56
- }
57
- }
58
- render(firstRender) {
59
- if (this.status === 'pending') {
60
- super.render(firstRender);
61
- return;
62
- }
63
- // Revealed State
64
- let output = '';
65
- const choices = this.getFilteredChoices();
66
- // Header
67
- const icon = this.isCorrect ? `${_theme.theme.success}${_symbols.symbols.tick}` : `${_theme.theme.error}${_symbols.symbols.cross}`;
68
- output += `${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}\n`;
69
- const visibleChoices = choices.slice(this.scrollTop, this.scrollTop + this.pageSize);
70
- visibleChoices.forEach((choice, index)=>{
71
- if (index > 0) output += '\n';
72
- if (this.isSeparator(choice)) {
73
- output += ` ${_ansi.ANSI.DIM}${choice.text || _symbols.symbols.line.repeat(8)}${_ansi.ANSI.RESET}`;
74
- } else {
75
- // Determine absolute index to match with user selection
76
- const actualIndex = this.scrollTop + index;
77
- const isSelected = actualIndex === this.userSelectionIndex;
78
- const isCorrectAnswer = choice.value === this.options.correctValue;
79
- let prefix = ' ';
80
- let style = _ansi.ANSI.RESET;
81
- if (isSelected) {
82
- if (this.isCorrect) {
83
- prefix = `${_theme.theme.success}${_symbols.symbols.pointer} `;
84
- style = _theme.theme.success;
85
- } else {
86
- prefix = `${_theme.theme.error}${_symbols.symbols.cross} `;
87
- style = _theme.theme.error;
88
- }
89
- } else if (isCorrectAnswer) {
90
- prefix = `${_theme.theme.success}${_symbols.symbols.pointer} `;
91
- style = _theme.theme.success;
92
- }
93
- output += `${prefix}${style}${choice.title}${_ansi.ANSI.RESET}`;
94
- if (isSelected && !this.isCorrect) {
95
- output += ` ${_theme.theme.error}(Your Answer)${_ansi.ANSI.RESET}`;
96
- }
97
- if (isCorrectAnswer && !isSelected) {
98
- output += ` ${_theme.theme.success}(Correct)${_ansi.ANSI.RESET}`;
99
- }
100
- }
101
- });
102
- // Explanation
103
- if (this.options.explanation) {
104
- output += `\n\n${_ansi.ANSI.BOLD}Explanation:${_ansi.ANSI.RESET}\n${_theme.theme.muted}${this.options.explanation}${_ansi.ANSI.RESET}`;
105
- }
106
- output += `\n\n${_ansi.ANSI.DIM}(Press Enter to continue)${_ansi.ANSI.RESET}`;
107
- this.renderFrame(output);
108
- }
109
- constructor(options){
110
- super(options), _define_property(this, "status", 'pending'), _define_property(this, "isCorrect", false), _define_property(this, "userSelectionIndex", -1);
111
- }
112
- };
113
-
114
- //# sourceMappingURL=quiz-select.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/prompts/quiz-select.ts"],"sourcesContent":["import { ANSI } from '../ansi';\nimport { theme } from '../theme';\nimport { symbols } from '../symbols';\nimport { QuizSelectOptions } from '../types';\nimport { SelectPrompt } from './select';\n\nexport class QuizSelectPrompt<V> extends SelectPrompt<V, QuizSelectOptions<V>> {\n private status: 'pending' | 'revealed' = 'pending';\n private isCorrect: boolean = false;\n private userSelectionIndex: number = -1;\n\n constructor(options: QuizSelectOptions<V>) {\n super(options);\n }\n\n protected handleInput(char: string) {\n if (this.status === 'revealed') {\n // Wait for Enter to submit\n if (char === '\\r' || char === '\\n') {\n const choices = this.getFilteredChoices();\n // Ensure index is valid, though it should be captured\n const value = choices[this.userSelectionIndex]\n ? (choices[this.userSelectionIndex] as any).value\n : null;\n this.submit(value as V);\n }\n return;\n }\n\n if (this.status === 'pending') {\n // Intercept Enter\n if (char === '\\r' || char === '\\n') {\n const choices = this.getFilteredChoices();\n if (choices.length === 0) return;\n if (this.isSeparator(choices[this.selectedIndex])) return;\n\n this.userSelectionIndex = this.selectedIndex;\n const selectedChoice = choices[this.userSelectionIndex] as any;\n\n // Check correctness\n this.isCorrect = selectedChoice.value === this.options.correctValue;\n\n this.status = 'revealed';\n this.render(false);\n return;\n }\n\n // Delegate navigation to super\n super.handleInput(char);\n }\n }\n\n protected render(firstRender: boolean) {\n if (this.status === 'pending') {\n super.render(firstRender);\n return;\n }\n\n // Revealed State\n let output = '';\n const choices = this.getFilteredChoices();\n\n // Header\n const icon = this.isCorrect ? `${theme.success}${symbols.tick}` : `${theme.error}${symbols.cross}`;\n output += `${icon} ${ANSI.BOLD}${theme.title}${this.options.message}${ANSI.RESET}\\n`;\n\n const visibleChoices = choices.slice(this.scrollTop, this.scrollTop + this.pageSize);\n\n visibleChoices.forEach((choice, index) => {\n if (index > 0) output += '\\n';\n\n if (this.isSeparator(choice)) {\n output += ` ${ANSI.DIM}${(choice as any).text || symbols.line.repeat(8)}${ANSI.RESET}`;\n } else {\n // Determine absolute index to match with user selection\n const actualIndex = this.scrollTop + index;\n const isSelected = actualIndex === this.userSelectionIndex;\n const isCorrectAnswer = (choice as any).value === this.options.correctValue;\n\n let prefix = ' ';\n let style = ANSI.RESET;\n\n if (isSelected) {\n if (this.isCorrect) {\n prefix = `${theme.success}${symbols.pointer} `;\n style = theme.success;\n } else {\n prefix = `${theme.error}${symbols.cross} `;\n style = theme.error;\n }\n } else if (isCorrectAnswer) {\n prefix = `${theme.success}${symbols.pointer} `;\n style = theme.success;\n }\n\n output += `${prefix}${style}${(choice as any).title}${ANSI.RESET}`;\n\n if (isSelected && !this.isCorrect) {\n output += ` ${theme.error}(Your Answer)${ANSI.RESET}`;\n }\n if (isCorrectAnswer && !isSelected) {\n output += ` ${theme.success}(Correct)${ANSI.RESET}`;\n }\n }\n });\n\n // Explanation\n if (this.options.explanation) {\n output += `\\n\\n${ANSI.BOLD}Explanation:${ANSI.RESET}\\n${theme.muted}${this.options.explanation}${ANSI.RESET}`;\n }\n\n output += `\\n\\n${ANSI.DIM}(Press Enter to continue)${ANSI.RESET}`;\n\n this.renderFrame(output);\n }\n}\n"],"names":["QuizSelectPrompt","SelectPrompt","handleInput","char","status","choices","getFilteredChoices","value","userSelectionIndex","submit","length","isSeparator","selectedIndex","selectedChoice","isCorrect","options","correctValue","render","firstRender","output","icon","theme","success","symbols","tick","error","cross","ANSI","BOLD","title","message","RESET","visibleChoices","slice","scrollTop","pageSize","forEach","choice","index","DIM","text","line","repeat","actualIndex","isSelected","isCorrectAnswer","prefix","style","pointer","explanation","muted","renderFrame"],"mappings":";;;;+BAMaA;;;eAAAA;;;sBANQ;uBACC;yBACE;wBAEK;;;;;;;;;;;;;;AAEtB,IAAA,AAAMA,mBAAN,MAAMA,yBAA4BC,oBAAY;IASvCC,YAAYC,IAAY,EAAE;QAChC,IAAI,IAAI,CAACC,MAAM,KAAK,YAAY;YAC5B,2BAA2B;YAC3B,IAAID,SAAS,QAAQA,SAAS,MAAM;gBAChC,MAAME,UAAU,IAAI,CAACC,kBAAkB;gBACvC,sDAAsD;gBACtD,MAAMC,QAAQF,OAAO,CAAC,IAAI,CAACG,kBAAkB,CAAC,GACxC,AAACH,OAAO,CAAC,IAAI,CAACG,kBAAkB,CAAC,CAASD,KAAK,GAC/C;gBACN,IAAI,CAACE,MAAM,CAACF;YAChB;YACA;QACJ;QAEA,IAAI,IAAI,CAACH,MAAM,KAAK,WAAW;YAC3B,kBAAkB;YAClB,IAAID,SAAS,QAAQA,SAAS,MAAM;gBAChC,MAAME,UAAU,IAAI,CAACC,kBAAkB;gBACvC,IAAID,QAAQK,MAAM,KAAK,GAAG;gBAC1B,IAAI,IAAI,CAACC,WAAW,CAACN,OAAO,CAAC,IAAI,CAACO,aAAa,CAAC,GAAG;gBAEnD,IAAI,CAACJ,kBAAkB,GAAG,IAAI,CAACI,aAAa;gBAC5C,MAAMC,iBAAiBR,OAAO,CAAC,IAAI,CAACG,kBAAkB,CAAC;gBAEvD,oBAAoB;gBACpB,IAAI,CAACM,SAA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