d2coreui 23.0.52 → 23.0.54

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 (280) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +154 -0
  3. package/components/clipboard/clipboardUtils.d.ts +11 -0
  4. package/components/clipboard/clipboardUtils.js +16 -4
  5. package/components/clipboard/clipboardUtils.js.map +1 -1
  6. package/components/codemirror/SyntaxHighlighter.d.ts +13 -0
  7. package/components/codemirror/SyntaxHighlighter.js +6 -1
  8. package/components/codemirror/SyntaxHighlighter.js.map +1 -1
  9. package/components/collapse/expandable.d.ts +10 -0
  10. package/components/collapse/expandable.js +4 -0
  11. package/components/collapse/expandable.js.map +1 -1
  12. package/components/color/colorPicker.d.ts +16 -0
  13. package/components/color/colorPicker.js +4 -0
  14. package/components/color/colorPicker.js.map +1 -1
  15. package/components/color/colorSwatch.d.ts +16 -0
  16. package/components/color/colorSwatch.js +23 -2
  17. package/components/color/colorSwatch.js.map +1 -1
  18. package/components/color/colorUtils.d.ts +9 -0
  19. package/components/color/colorUtils.js +15 -0
  20. package/components/color/colorUtils.js.map +1 -1
  21. package/components/date/dateRangeInput.d.ts +76 -0
  22. package/components/date/dateRangeInput.js +63 -12
  23. package/components/date/dateRangeInput.js.map +1 -1
  24. package/components/date/dateRangeInputAdvancedPanel.d.ts +27 -0
  25. package/components/date/dateRangeInputAdvancedPanel.js +7 -0
  26. package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
  27. package/components/date/dateRangeInputConfirm.d.ts +18 -0
  28. package/components/date/dateRangeInputConfirm.js +12 -0
  29. package/components/date/dateRangeInputConfirm.js.map +1 -1
  30. package/components/date/dateTimeInput.d.ts +99 -0
  31. package/components/date/dateTimeInput.js +78 -6
  32. package/components/date/dateTimeInput.js.map +1 -1
  33. package/components/date/durationInput.d.ts +37 -0
  34. package/components/date/durationInput.js +26 -3
  35. package/components/date/durationInput.js.map +1 -1
  36. package/components/date/savedIntervals.d.ts +63 -0
  37. package/components/date/savedIntervals.js +37 -0
  38. package/components/date/savedIntervals.js.map +1 -1
  39. package/components/date/savedIntervalsDialog.d.ts +13 -0
  40. package/components/date/savedIntervalsDialog.js +7 -2
  41. package/components/date/savedIntervalsDialog.js.map +1 -1
  42. package/components/form/NiceFormItem.d.ts +9 -0
  43. package/components/form/NiceFormItem.js +4 -0
  44. package/components/form/NiceFormItem.js.map +1 -1
  45. package/components/grid/cell/beanAccessor.d.ts +12 -0
  46. package/components/grid/cell/beanAccessor.js +8 -0
  47. package/components/grid/cell/beanAccessor.js.map +1 -1
  48. package/components/grid/cell/bigNumberCellEditor.d.ts +9 -0
  49. package/components/grid/cell/bigNumberCellEditor.js +19 -0
  50. package/components/grid/cell/bigNumberCellEditor.js.map +1 -1
  51. package/components/grid/cell/cellControl.d.ts +4 -0
  52. package/components/grid/cell/cellControl.js +14 -0
  53. package/components/grid/cell/cellControl.js.map +1 -1
  54. package/components/grid/cell/cellEditorUtils.d.ts +6 -0
  55. package/components/grid/cell/cellEditorUtils.js +6 -0
  56. package/components/grid/cell/cellEditorUtils.js.map +1 -1
  57. package/components/grid/cell/customEnumCellEditor.d.ts +6 -0
  58. package/components/grid/cell/customEnumCellEditor.js +10 -0
  59. package/components/grid/cell/customEnumCellEditor.js.map +1 -1
  60. package/components/grid/cell/dataGridCellEditorComponent.d.ts +26 -0
  61. package/components/grid/cell/dataGridCellEditorComponent.js +21 -0
  62. package/components/grid/cell/dataGridCellEditorComponent.js.map +1 -1
  63. package/components/grid/cell/dateCellEditor.d.ts +6 -0
  64. package/components/grid/cell/dateCellEditor.js +10 -0
  65. package/components/grid/cell/dateCellEditor.js.map +1 -1
  66. package/components/grid/cell/dragListenerFeature.d.ts +6 -0
  67. package/components/grid/cell/dragListenerFeature.js +6 -0
  68. package/components/grid/cell/dragListenerFeature.js.map +1 -1
  69. package/components/grid/cell/durationCellEditor.d.ts +6 -0
  70. package/components/grid/cell/durationCellEditor.js +14 -0
  71. package/components/grid/cell/durationCellEditor.js.map +1 -1
  72. package/components/grid/cell/hexaOctetStringCellEditor.d.ts +6 -0
  73. package/components/grid/cell/hexaOctetStringCellEditor.js +14 -0
  74. package/components/grid/cell/hexaOctetStringCellEditor.js.map +1 -1
  75. package/components/grid/cell/hexaValueCellEditor.d.ts +6 -0
  76. package/components/grid/cell/hexaValueCellEditor.js +14 -0
  77. package/components/grid/cell/hexaValueCellEditor.js.map +1 -1
  78. package/components/grid/cell/numberCellEditor.d.ts +6 -0
  79. package/components/grid/cell/numberCellEditor.js +15 -0
  80. package/components/grid/cell/numberCellEditor.js.map +1 -1
  81. package/components/grid/cell/rangeSelector.d.ts +7 -0
  82. package/components/grid/cell/rangeSelector.js +59 -5
  83. package/components/grid/cell/rangeSelector.js.map +1 -1
  84. package/components/grid/cell/simpleStatusTextCellEditor.d.ts +7 -0
  85. package/components/grid/cell/simpleStatusTextCellEditor.js +11 -0
  86. package/components/grid/cell/simpleStatusTextCellEditor.js.map +1 -1
  87. package/components/grid/cell/statusTextCellEditor.d.ts +7 -0
  88. package/components/grid/cell/statusTextCellEditor.js +17 -0
  89. package/components/grid/cell/statusTextCellEditor.js.map +1 -1
  90. package/components/grid/cell/tableDefaultRowStyleRules.d.ts +31 -0
  91. package/components/grid/cell/tableDefaultRowStyleRules.js +5 -0
  92. package/components/grid/cell/tableDefaultRowStyleRules.js.map +1 -1
  93. package/components/grid/cell/textCellEditor.d.ts +6 -0
  94. package/components/grid/cell/textCellEditor.js +15 -0
  95. package/components/grid/cell/textCellEditor.js.map +1 -1
  96. package/components/grid/cell/withAgGridHooks.d.ts +8 -0
  97. package/components/grid/cell/withAgGridHooks.js +8 -0
  98. package/components/grid/cell/withAgGridHooks.js.map +1 -1
  99. package/components/grid/columnUtils.d.ts +10 -1
  100. package/components/grid/columnUtils.js +11 -0
  101. package/components/grid/columnUtils.js.map +1 -1
  102. package/components/grid/config/columnTransfer.d.ts +18 -0
  103. package/components/grid/config/columnTransfer.js +45 -29
  104. package/components/grid/config/columnTransfer.js.map +1 -1
  105. package/components/grid/config/dataGridEditor.d.ts +31 -0
  106. package/components/grid/config/dataGridEditor.js +14 -2
  107. package/components/grid/config/dataGridEditor.js.map +1 -1
  108. package/components/grid/config/rowHeightCalculator.d.ts +11 -0
  109. package/components/grid/config/rowHeightCalculator.js +11 -0
  110. package/components/grid/config/rowHeightCalculator.js.map +1 -1
  111. package/components/grid/config/rowStylePicker.d.ts +19 -0
  112. package/components/grid/config/rowStylePicker.js +12 -0
  113. package/components/grid/config/rowStylePicker.js.map +1 -1
  114. package/components/grid/dataGrid.d.ts +361 -12
  115. package/components/grid/dataGrid.js +201 -28
  116. package/components/grid/dataGrid.js.map +1 -1
  117. package/components/grid/detail/detailHeaderPanel.d.ts +11 -0
  118. package/components/grid/detail/detailHeaderPanel.js +5 -0
  119. package/components/grid/detail/detailHeaderPanel.js.map +1 -1
  120. package/components/grid/export/contextMenu.d.ts +31 -0
  121. package/components/grid/export/contextMenu.js +8 -0
  122. package/components/grid/export/contextMenu.js.map +1 -1
  123. package/components/grid/export/progressPopup.d.ts +21 -0
  124. package/components/grid/export/progressPopup.js +17 -0
  125. package/components/grid/export/progressPopup.js.map +1 -1
  126. package/components/grid/export/worker/pdfExport.js +5 -0
  127. package/components/grid/export/worker/pdfExport.js.map +1 -1
  128. package/components/grid/extendedDataGrid.d.ts +249 -4
  129. package/components/grid/extendedDataGrid.js +160 -19
  130. package/components/grid/extendedDataGrid.js.map +1 -1
  131. package/components/grid/filter/customColumnFilter.d.ts +5 -0
  132. package/components/grid/filter/customColumnFilter.js +5 -0
  133. package/components/grid/filter/customColumnFilter.js.map +1 -1
  134. package/components/grid/filter/dataGridColumnFilter.d.ts +19 -0
  135. package/components/grid/filter/dataGridColumnFilter.js +19 -0
  136. package/components/grid/filter/dataGridColumnFilter.js.map +1 -1
  137. package/components/grid/filter/dateColumnFilter.d.ts +6 -0
  138. package/components/grid/filter/dateColumnFilter.js +6 -0
  139. package/components/grid/filter/dateColumnFilter.js.map +1 -1
  140. package/components/grid/filter/textColumnFilter.d.ts +6 -0
  141. package/components/grid/filter/textColumnFilter.js +6 -0
  142. package/components/grid/filter/textColumnFilter.js.map +1 -1
  143. package/components/grid/filter/wildcardQuickFilterEngine.d.ts +21 -0
  144. package/components/grid/filter/wildcardQuickFilterEngine.js +21 -0
  145. package/components/grid/filter/wildcardQuickFilterEngine.js.map +1 -1
  146. package/components/grid/header/simpleHeader.d.ts +17 -0
  147. package/components/grid/header/simpleHeader.js +20 -0
  148. package/components/grid/header/simpleHeader.js.map +1 -1
  149. package/components/grid/panel/dataGridPagination.d.ts +10 -0
  150. package/components/grid/panel/dataGridPagination.js +5 -0
  151. package/components/grid/panel/dataGridPagination.js.map +1 -1
  152. package/components/grid/panel/loadingOverlay.d.ts +5 -0
  153. package/components/grid/panel/loadingOverlay.js +4 -0
  154. package/components/grid/panel/loadingOverlay.js.map +1 -1
  155. package/components/grid/panel/noRecordsOverlay.d.ts +6 -0
  156. package/components/grid/panel/noRecordsOverlay.js +5 -0
  157. package/components/grid/panel/noRecordsOverlay.js.map +1 -1
  158. package/components/grid/panel/tablePagination.d.ts +4 -0
  159. package/components/grid/panel/tablePagination.js +4 -0
  160. package/components/grid/panel/tablePagination.js.map +1 -1
  161. package/components/icons/dropdownArrow.d.ts +3 -0
  162. package/components/icons/dropdownArrow.js +2 -0
  163. package/components/icons/dropdownArrow.js.map +1 -1
  164. package/components/icons/undoIcon.d.ts +2 -0
  165. package/components/icons/undoIcon.js +2 -0
  166. package/components/icons/undoIcon.js.map +1 -1
  167. package/components/input/autoCompleteInput.d.ts +29 -0
  168. package/components/input/autoCompleteInput.js +7 -0
  169. package/components/input/autoCompleteInput.js.map +1 -1
  170. package/components/input/draftUtils.d.ts +7 -0
  171. package/components/input/draftUtils.js +9 -0
  172. package/components/input/draftUtils.js.map +1 -1
  173. package/components/input/hexaFormattedInput.d.ts +9 -0
  174. package/components/input/hexaFormattedInput.js +3 -0
  175. package/components/input/hexaFormattedInput.js.map +1 -1
  176. package/components/input/mask/helpers.d.ts +27 -0
  177. package/components/input/mask/helpers.js +27 -0
  178. package/components/input/mask/helpers.js.map +1 -1
  179. package/components/input/mask/inputMaskCore.d.ts +80 -0
  180. package/components/input/mask/inputMaskCore.js +90 -0
  181. package/components/input/mask/inputMaskCore.js.map +1 -1
  182. package/components/input/mask/pattern.d.ts +24 -0
  183. package/components/input/mask/pattern.js +26 -0
  184. package/components/input/mask/pattern.js.map +1 -1
  185. package/components/input/maskedInput.d.ts +53 -0
  186. package/components/input/maskedInput.js +44 -4
  187. package/components/input/maskedInput.js.map +1 -1
  188. package/components/input/passwordInput.d.ts +7 -0
  189. package/components/input/passwordInput.js +8 -0
  190. package/components/input/passwordInput.js.map +1 -1
  191. package/components/input/simpleAutoComplete.d.ts +6 -0
  192. package/components/input/simpleAutoComplete.js +6 -0
  193. package/components/input/simpleAutoComplete.js.map +1 -1
  194. package/components/input/textarea/extractSpansOfClasses.d.ts +17 -0
  195. package/components/input/textarea/extractSpansOfClasses.js +26 -1
  196. package/components/input/textarea/extractSpansOfClasses.js.map +1 -1
  197. package/components/input/textarea/getRanges.d.ts +7 -0
  198. package/components/input/textarea/getRanges.js +11 -0
  199. package/components/input/textarea/getRanges.js.map +1 -1
  200. package/components/input/textarea/getType.d.ts +5 -0
  201. package/components/input/textarea/getType.js +5 -0
  202. package/components/input/textarea/getType.js.map +1 -1
  203. package/components/input/textarea/highlighedContents.d.ts +4 -0
  204. package/components/input/textarea/highlighedContents.js +5 -0
  205. package/components/input/textarea/highlighedContents.js.map +1 -1
  206. package/components/input/textarea/mentionsWithHighlighting.d.ts +25 -0
  207. package/components/input/textarea/mentionsWithHighlighting.js +14 -0
  208. package/components/input/textarea/mentionsWithHighlighting.js.map +1 -1
  209. package/components/keyboard/keyboardUtils.d.ts +6 -0
  210. package/components/keyboard/keyboardUtils.js +6 -0
  211. package/components/keyboard/keyboardUtils.js.map +1 -1
  212. package/components/modal/draggableModalProvider.d.ts +6 -0
  213. package/components/modal/draggableModalProvider.js +7 -0
  214. package/components/modal/draggableModalProvider.js.map +1 -1
  215. package/components/modal/impl/clamp.js +1 -0
  216. package/components/modal/impl/clamp.js.map +1 -1
  217. package/components/modal/impl/draggableModal.d.ts +1 -0
  218. package/components/modal/impl/draggableModal.js +6 -0
  219. package/components/modal/impl/draggableModal.js.map +1 -1
  220. package/components/modal/impl/draggableModalContext.js +1 -0
  221. package/components/modal/impl/draggableModalContext.js.map +1 -1
  222. package/components/modal/impl/draggableModalInner.js +12 -1
  223. package/components/modal/impl/draggableModalInner.js.map +1 -1
  224. package/components/modal/impl/draggableModalReducer.d.ts +7 -1
  225. package/components/modal/impl/draggableModalReducer.js +6 -1
  226. package/components/modal/impl/draggableModalReducer.js.map +1 -1
  227. package/components/modal/impl/draggableModalStyles.d.ts +17 -0
  228. package/components/modal/impl/draggableModalStyles.js +31 -0
  229. package/components/modal/impl/draggableModalStyles.js.map +1 -1
  230. package/components/modal/impl/getWindowSize.js +1 -0
  231. package/components/modal/impl/getWindowSize.js.map +1 -1
  232. package/components/modal/impl/index.js +1 -0
  233. package/components/modal/impl/index.js.map +1 -1
  234. package/components/modal/impl/resizeHandle.d.ts +1 -0
  235. package/components/modal/impl/resizeHandle.js +4 -1
  236. package/components/modal/impl/resizeHandle.js.map +1 -1
  237. package/components/modal/impl/useDrag.js +1 -0
  238. package/components/modal/impl/useDrag.js.map +1 -1
  239. package/components/modal/impl/usePrevious.js +1 -0
  240. package/components/modal/impl/usePrevious.js.map +1 -1
  241. package/components/modal/impl/useResize.js +1 -0
  242. package/components/modal/impl/useResize.js.map +1 -1
  243. package/components/modal/modalDialog.d.ts +85 -0
  244. package/components/modal/modalDialog.js +80 -10
  245. package/components/modal/modalDialog.js.map +1 -1
  246. package/components/picker/enumValuePicker.d.ts +17 -0
  247. package/components/picker/enumValuePicker.js +4 -0
  248. package/components/picker/enumValuePicker.js.map +1 -1
  249. package/components/platformSpecific.d.ts +17 -0
  250. package/components/platformSpecific.js +16 -0
  251. package/components/platformSpecific.js.map +1 -1
  252. package/components/scrollTo/onlyText.d.ts +5 -0
  253. package/components/scrollTo/onlyText.js +5 -0
  254. package/components/scrollTo/onlyText.js.map +1 -1
  255. package/components/scrollTo/scrollTo.d.ts +56 -0
  256. package/components/scrollTo/scrollTo.js +40 -3
  257. package/components/scrollTo/scrollTo.js.map +1 -1
  258. package/components/style/withCss.d.ts +15 -0
  259. package/components/style/withCss.js +6 -0
  260. package/components/style/withCss.js.map +1 -1
  261. package/components/table/dragSortingTable.d.ts +15 -0
  262. package/components/table/dragSortingTable.js +12 -0
  263. package/components/table/dragSortingTable.js.map +1 -1
  264. package/components/text/impl/innerSize.js +2 -0
  265. package/components/text/impl/innerSize.js.map +1 -1
  266. package/components/text/impl/series.d.ts +10 -0
  267. package/components/text/impl/series.js +10 -0
  268. package/components/text/impl/series.js.map +1 -1
  269. package/components/text/impl/shallowEqual.js +1 -0
  270. package/components/text/impl/shallowEqual.js.map +1 -1
  271. package/components/text/impl/whilst.d.ts +7 -0
  272. package/components/text/impl/whilst.js +7 -0
  273. package/components/text/impl/whilst.js.map +1 -1
  274. package/components/text/textFit.d.ts +24 -0
  275. package/components/text/textFit.js +29 -1
  276. package/components/text/textFit.js.map +1 -1
  277. package/i18n/componentsLocaleHolder.d.ts +9 -0
  278. package/i18n/componentsLocaleHolder.js +9 -0
  279. package/i18n/componentsLocaleHolder.js.map +1 -1
  280. package/package.json +66 -65
@@ -1,46 +1,126 @@
1
1
  import { FormatCharacters } from './helpers';
2
2
  import { Pattern } from './pattern';
3
+ /** Selection range within the mask, as character offsets (`end` exclusive). */
3
4
  type SelectionObject = {
4
5
  start: number;
5
6
  end: number;
6
7
  };
7
8
  type Options = {
9
+ /** Custom format characters merged over the defaults (see {@link mergeFormatCharacters}). */
8
10
  formatCharacters: FormatCharacters;
11
+ /** Pattern source, see {@link Pattern}. Required. */
9
12
  pattern: string;
13
+ /**
14
+ * When true, the pattern is shown only up to the last entered character instead of in full with placeholders.
15
+ * @default false
16
+ */
10
17
  isRevealingMask: boolean;
18
+ /**
19
+ * Single character (or empty string) shown in unfilled editable positions.
20
+ * @default "_"
21
+ */
11
22
  placeholderChar: string;
23
+ /**
24
+ * Initial selection.
25
+ * @default {start: 0, end: 0}
26
+ */
12
27
  selection: SelectionObject;
28
+ /**
29
+ * Initial value; formatted into the pattern.
30
+ * @default ""
31
+ */
13
32
  value: string;
14
33
  };
34
+ /**
35
+ * Framework-independent input-mask engine behind `MaskedInput`: holds the formatted value and the
36
+ * selection, applies single-character input, Backspace and paste according to a {@link Pattern}, and keeps an
37
+ * undo/redo history. Callers keep {@link InputMask.selection} in sync with the real input before each operation.
38
+ * @throws Error when the pattern is missing or has no editable characters, or `placeholderChar` is longer than one character.
39
+ */
15
40
  export declare class InputMask {
41
+ /** The {@link Pattern} class, exposed for convenience. */
16
42
  static Pattern: typeof Pattern;
43
+ /** Effective format characters (defaults merged with the custom ones). */
17
44
  formatCharacters: FormatCharacters;
45
+ /** The parsed current pattern. */
18
46
  pattern: Pattern;
47
+ /** Declared but never assigned; the effective flag is `pattern.isRevealingMask`. */
19
48
  isRevealingMask: boolean;
49
+ /** Character shown in unfilled editable positions. */
20
50
  placeholderChar: string;
51
+ /** Current selection; read and updated by the editing operations. */
21
52
  selection: SelectionObject;
53
+ /** Current formatted value, one entry per pattern position. */
22
54
  value: string[];
55
+ /** The formatted value with no characters entered (the pattern with placeholders). */
23
56
  emptyValue: string;
57
+ /** Internal undo/redo history. */
24
58
  _history: {
25
59
  value: string;
26
60
  selection: SelectionObject;
27
61
  lastOp: string | null;
28
62
  startUndo?: boolean;
29
63
  }[];
64
+ /** Internal: position in {@link InputMask._history} while undoing, otherwise `null`. */
30
65
  _historyIndex: null | number;
66
+ /** Internal: last editing operation (`input`, `backspace`), used to group history entries. */
31
67
  _lastOp: null | string;
68
+ /** Internal: selection after the last operation, used to group history entries. */
32
69
  _lastSelection: null | SelectionObject;
33
70
  constructor(options: Partial<Options>);
71
+ /**
72
+ * Replaces the pattern, formats `options.value` (default empty) into it, sets `options.selection` and clears the
73
+ * history. Only `value`, `selection` and `isRevealingMask` of `options` are used.
74
+ */
34
75
  setPattern(patternSource: string, options: Partial<Options>): void;
76
+ /**
77
+ * Formats `value` into the pattern, replacing the current value. Characters that do not fit a position become
78
+ * placeholders; literal pattern characters in `value` are skipped over. Does not touch history or selection.
79
+ */
35
80
  setValue(value?: string): void;
81
+ /** Internal: clears the undo/redo history. */
36
82
  _resetHistory(): void;
83
+ /** The formatted value including literals and placeholders. */
37
84
  getValue(): string;
85
+ /** Only the characters at editable positions (placeholders included), without literals. */
38
86
  getRawValue(): string;
87
+ /**
88
+ * Applies a single character of input based on the current selection.
89
+ * Invalid characters are rejected; typing over a selected range blanks the rest of the range, and the cursor
90
+ * skips following literals.
91
+ * @returns true if the value or selection changed, false if the input was rejected or the cursor is at the end.
92
+ */
39
93
  input(char: string): boolean;
94
+ /**
95
+ * Attempts to delete from the value based on the current cursor position or
96
+ * selection.
97
+ * @returns true if the value or selection changed, false when the cursor is at the start.
98
+ */
40
99
  backspace(): boolean;
100
+ /**
101
+ * Attempts to paste a string of input at the current cursor position or over
102
+ * the top of the current selection.
103
+ * Invalid content at any position will cause the paste to be rejected, and it
104
+ * may contain static parts of the mask's pattern.
105
+ * On rejection the previous state is restored.
106
+ * @returns true if the paste was successful, false otherwise.
107
+ */
41
108
  paste(input: string): boolean;
109
+ /**
110
+ * Restores the previous history state (value and selection).
111
+ * @returns false when there is nothing to undo.
112
+ */
42
113
  undo(): boolean;
114
+ /**
115
+ * Re-applies a state previously undone.
116
+ * @returns false when there is nothing to redo.
117
+ */
43
118
  redo(): boolean;
119
+ /**
120
+ * Sets the selection. A collapsed cursor is moved back to just after the last entered character before it
121
+ * (never before the first editable position).
122
+ * @returns true when the selection was collapsed (and possibly adjusted), false for a range.
123
+ */
44
124
  setSelection(selection: SelectionObject): boolean;
45
125
  }
46
126
  export default InputMask;
@@ -1,11 +1,22 @@
1
1
  import { DEFAULT_PLACEHOLDER_CHAR, mergeFormatCharacters } from './helpers';
2
2
  import { Pattern } from './pattern';
3
+ /**
4
+ * Framework-independent input-mask engine behind `MaskedInput`: holds the formatted value and the
5
+ * selection, applies single-character input, Backspace and paste according to a {@link Pattern}, and keeps an
6
+ * undo/redo history. Callers keep {@link InputMask.selection} in sync with the real input before each operation.
7
+ * @throws Error when the pattern is missing or has no editable characters, or `placeholderChar` is longer than one character.
8
+ */
3
9
  export class InputMask {
4
10
  constructor(options) {
11
+ /** The formatted value with no characters entered (the pattern with placeholders). */
5
12
  this.emptyValue = '';
13
+ /** Internal undo/redo history. */
6
14
  this._history = [];
15
+ /** Internal: position in {@link InputMask._history} while undoing, otherwise `null`. */
7
16
  this._historyIndex = null;
17
+ /** Internal: last editing operation (`input`, `backspace`), used to group history entries. */
8
18
  this._lastOp = null;
19
+ /** Internal: selection after the last operation, used to group history entries. */
9
20
  this._lastSelection = null;
10
21
  const mergedOptions = Object.assign({
11
22
  isRevealingMask: false,
@@ -28,6 +39,10 @@ export class InputMask {
28
39
  isRevealingMask: mergedOptions.isRevealingMask
29
40
  });
30
41
  }
42
+ /**
43
+ * Replaces the pattern, formats `options.value` (default empty) into it, sets `options.selection` and clears the
44
+ * history. Only `value`, `selection` and `isRevealingMask` of `options` are used.
45
+ */
31
46
  setPattern(patternSource, options) {
32
47
  const merged = Object.assign({ selection: { start: 0, end: 0 }, value: '' }, options);
33
48
  this.pattern = new Pattern(patternSource, this.formatCharacters, this.placeholderChar, merged.isRevealingMask);
@@ -36,24 +51,31 @@ export class InputMask {
36
51
  this.selection = merged.selection;
37
52
  this._resetHistory();
38
53
  }
54
+ /**
55
+ * Formats `value` into the pattern, replacing the current value. Characters that do not fit a position become
56
+ * placeholders; literal pattern characters in `value` are skipped over. Does not touch history or selection.
57
+ */
39
58
  setValue(value) {
40
59
  if (value == null) {
41
60
  value = '';
42
61
  }
43
62
  this.value = this.pattern.formatValue((value || '').split(''));
44
63
  }
64
+ /** Internal: clears the undo/redo history. */
45
65
  _resetHistory() {
46
66
  this._history = [];
47
67
  this._historyIndex = null;
48
68
  this._lastOp = null;
49
69
  this._lastSelection = Object.assign({}, this.selection);
50
70
  }
71
+ /** The formatted value including literals and placeholders. */
51
72
  getValue() {
52
73
  if (this.pattern.isRevealingMask) {
53
74
  this.value = this.pattern.formatValue((this.getRawValue() || '').split(''));
54
75
  }
55
76
  return (this.value || []).join('');
56
77
  }
78
+ /** Only the characters at editable positions (placeholders included), without literals. */
57
79
  getRawValue() {
58
80
  var rawValue = [];
59
81
  for (var i = 0; i < this.value.length; i++) {
@@ -63,7 +85,14 @@ export class InputMask {
63
85
  }
64
86
  return rawValue.join('');
65
87
  }
88
+ /**
89
+ * Applies a single character of input based on the current selection.
90
+ * Invalid characters are rejected; typing over a selected range blanks the rest of the range, and the cursor
91
+ * skips following literals.
92
+ * @returns true if the value or selection changed, false if the input was rejected or the cursor is at the end.
93
+ */
66
94
  input(char) {
95
+ // Ignore additional input if the cursor's at the end of the pattern
67
96
  if (this.selection.start === this.selection.end &&
68
97
  this.selection.start === this.pattern.length) {
69
98
  return false;
@@ -71,9 +100,12 @@ export class InputMask {
71
100
  const selectionBefore = copy(this.selection);
72
101
  const valueBefore = this.getValue();
73
102
  let inputIndex = this.selection.start;
103
+ // If the cursor or selection is prior to the first editable character, make
104
+ // sure any input given is applied to it.
74
105
  if (this.pattern.firstEditableIndex && inputIndex < this.pattern.firstEditableIndex) {
75
106
  inputIndex = this.pattern.firstEditableIndex;
76
107
  }
108
+ // Bail out or add the character to input
77
109
  if (this.pattern.isEditableIndex(inputIndex)) {
78
110
  if (!this.pattern.isValidAtIndex(char, inputIndex)) {
79
111
  return false;
@@ -83,6 +115,8 @@ export class InputMask {
83
115
  else {
84
116
  console.log('not editable');
85
117
  }
118
+ // If multiple characters were selected, blank the remainder out based on the
119
+ // pattern.
86
120
  let end = this.selection.end - 1;
87
121
  while (end > inputIndex) {
88
122
  if (this.pattern.isEditableIndex(end)) {
@@ -90,13 +124,17 @@ export class InputMask {
90
124
  }
91
125
  end--;
92
126
  }
127
+ // Advance the cursor to the next character
93
128
  this.selection.start = this.selection.end = inputIndex + 1;
129
+ // Skip over any subsequent static characters
94
130
  while (this.pattern.length > this.selection.start &&
95
131
  !this.pattern.isEditableIndex(this.selection.start)) {
96
132
  this.selection.start++;
97
133
  this.selection.end++;
98
134
  }
135
+ // History
99
136
  if (this._historyIndex != null) {
137
+ // Took more input after undoing, so blow any subsequent history away
100
138
  this._history.splice(this._historyIndex, this._history.length - this._historyIndex);
101
139
  this._historyIndex = null;
102
140
  }
@@ -114,12 +152,19 @@ export class InputMask {
114
152
  this._lastSelection = copy(this.selection);
115
153
  return true;
116
154
  }
155
+ /**
156
+ * Attempts to delete from the value based on the current cursor position or
157
+ * selection.
158
+ * @returns true if the value or selection changed, false when the cursor is at the start.
159
+ */
117
160
  backspace() {
161
+ // If the cursor is at the start there's nothing to do
118
162
  if (this.selection.start === 0 && this.selection.end === 0) {
119
163
  return false;
120
164
  }
121
165
  var selectionBefore = Object.assign({}, this.selection);
122
166
  var valueBefore = this.getValue();
167
+ // No range selected - work on the character preceding the cursor
123
168
  if (this.selection.start === this.selection.end) {
124
169
  if (this.pattern.isEditableIndex(this.selection.start - 1)) {
125
170
  if (this.pattern.isRevealingMask) {
@@ -132,6 +177,7 @@ export class InputMask {
132
177
  this.selection.start--;
133
178
  this.selection.end--;
134
179
  }
180
+ // Range selected - delete characters and leave the cursor at the start of the selection
135
181
  else {
136
182
  var end = this.selection.end - 1;
137
183
  while (end >= this.selection.start) {
@@ -142,7 +188,9 @@ export class InputMask {
142
188
  }
143
189
  this.selection.end = this.selection.start;
144
190
  }
191
+ // History
145
192
  if (this._historyIndex != null) {
193
+ // Took more input after undoing, so blow any subsequent history away
146
194
  this._history.splice(this._historyIndex, this._history.length - this._historyIndex);
147
195
  }
148
196
  if (this._lastOp !== 'backspace' ||
@@ -159,7 +207,17 @@ export class InputMask {
159
207
  this._lastSelection = Object.assign({}, this.selection);
160
208
  return true;
161
209
  }
210
+ /**
211
+ * Attempts to paste a string of input at the current cursor position or over
212
+ * the top of the current selection.
213
+ * Invalid content at any position will cause the paste to be rejected, and it
214
+ * may contain static parts of the mask's pattern.
215
+ * On rejection the previous state is restored.
216
+ * @returns true if the paste was successful, false otherwise.
217
+ */
162
218
  paste(input) {
219
+ // This is necessary because we're just calling input() with each character
220
+ // and rolling back if any were invalid, rather than checking up-front.
163
221
  var initialState = {
164
222
  value: this.value.slice(),
165
223
  selection: Object.assign({}, this.selection),
@@ -168,19 +226,28 @@ export class InputMask {
168
226
  _historyIndex: this._historyIndex,
169
227
  _lastSelection: Object.assign({}, this._lastSelection)
170
228
  };
229
+ // If there are static characters at the start of the pattern and the cursor
230
+ // or selection is within them, the static characters must match for a valid
231
+ // paste.
171
232
  if (this.selection.start < this.pattern.firstEditableIndex) {
172
233
  for (var i = 0, l = this.pattern.firstEditableIndex - this.selection.start; i < l; i++) {
173
234
  if (input.charAt(i) !== this.pattern.pattern[i]) {
174
235
  return false;
175
236
  }
176
237
  }
238
+ // Continue as if the selection and input started from the editable part of
239
+ // the pattern.
177
240
  input = input.substring(this.pattern.firstEditableIndex - this.selection.start);
178
241
  this.selection.start = this.pattern.firstEditableIndex;
179
242
  }
180
243
  for (i = 0, l = input.length; i < l && this.selection.start <= this.pattern.lastEditableIndex; i++) {
181
244
  var valid = this.input(input.charAt(i));
245
+ // Allow static parts of the pattern to appear in pasted input - they will
246
+ // already have been stepped over by input(), so verify that the value
247
+ // deemed invalid by input() was the expected static character.
182
248
  if (!valid) {
183
249
  if (this.selection.start > 0) {
250
+ // XXX This only allows for one static character to be skipped
184
251
  var patternIndex = this.selection.start - 1;
185
252
  if (!this.pattern.isEditableIndex(patternIndex) &&
186
253
  input.charAt(i) === this.pattern.pattern[patternIndex]) {
@@ -188,6 +255,7 @@ export class InputMask {
188
255
  }
189
256
  }
190
257
  Object.keys(initialState).forEach(key => {
258
+ // @ts-ignore
191
259
  this[key] = initialState[key];
192
260
  });
193
261
  return false;
@@ -195,14 +263,22 @@ export class InputMask {
195
263
  }
196
264
  return true;
197
265
  }
266
+ /**
267
+ * Restores the previous history state (value and selection).
268
+ * @returns false when there is nothing to undo.
269
+ */
198
270
  undo() {
271
+ // If there is no history, or nothing more on the history stack, we can't undo
199
272
  if (this._history.length === 0 || this._historyIndex === 0) {
200
273
  return false;
201
274
  }
202
275
  var historyItem;
203
276
  if (this._historyIndex == null) {
277
+ // Not currently undoing, set up the initial history index
204
278
  this._historyIndex = this._history.length - 1;
205
279
  historyItem = this._history[this._historyIndex];
280
+ // Add a new history entry if anything has changed since the last one, so we
281
+ // can redo back to the initial state we started undoing from.
206
282
  var value = this.getValue();
207
283
  if (historyItem.value !== value ||
208
284
  historyItem.selection.start !== this.selection.start ||
@@ -223,13 +299,19 @@ export class InputMask {
223
299
  this._lastOp = historyItem.lastOp;
224
300
  return true;
225
301
  }
302
+ /**
303
+ * Re-applies a state previously undone.
304
+ * @returns false when there is nothing to redo.
305
+ */
226
306
  redo() {
227
307
  if (this._history.length === 0 || this._historyIndex == null) {
228
308
  return false;
229
309
  }
230
310
  var historyItem = this._history[++this._historyIndex];
311
+ // If this is the last history item, we're done redoing
231
312
  if (this._historyIndex === this._history.length - 1) {
232
313
  this._historyIndex = null;
314
+ // If the last history item was only added to start undoing, remove it
233
315
  if (historyItem.startUndo) {
234
316
  this._history.pop();
235
317
  }
@@ -239,6 +321,11 @@ export class InputMask {
239
321
  this._lastOp = historyItem.lastOp;
240
322
  return true;
241
323
  }
324
+ /**
325
+ * Sets the selection. A collapsed cursor is moved back to just after the last entered character before it
326
+ * (never before the first editable position).
327
+ * @returns true when the selection was collapsed (and possibly adjusted), false for a range.
328
+ */
242
329
  setSelection(selection) {
243
330
  this.selection = Object.assign({}, selection);
244
331
  if (this.selection.start === this.selection.end) {
@@ -247,6 +334,8 @@ export class InputMask {
247
334
  .firstEditableIndex;
248
335
  return true;
249
336
  }
337
+ // Set selection to the first editable, non-placeholder character before the selection
338
+ // OR to the beginning of the pattern
250
339
  var index = this.selection.start;
251
340
  while (index >= this.pattern.firstEditableIndex) {
252
341
  if ((this.pattern.isEditableIndex(index - 1) &&
@@ -262,6 +351,7 @@ export class InputMask {
262
351
  return false;
263
352
  }
264
353
  }
354
+ /** The {@link Pattern} class, exposed for convenience. */
265
355
  InputMask.Pattern = Pattern;
266
356
  function extend(dest, src) {
267
357
  if (src) {
@@ -1 +1 @@
1
- {"version":3,"file":"inputMaskCore.js","sourceRoot":"","sources":["../../../../../components/input/mask/inputMaskCore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,wBAAwB,EAAoB,qBAAqB,EAAC,MAAM,WAAW,CAAC;AAC5F,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAalC,MAAM,OAAO,SAAS;IAsBlB,YAAY,OAAyB;QAbrC,eAAU,GAAG,EAAE,CAAC;QAEhB,aAAQ,GAKF,EAAE,CAAC;QAET,kBAAa,GAAkB,IAAI,CAAC;QACpC,YAAO,GAAkB,IAAI,CAAC;QAC9B,mBAAc,GAA2B,IAAI,CAAC;QAG1C,MAAM,aAAa,GAAY,cACxB;YACC,eAAe,EAAE,KAAK;YACtB,eAAe,EAAE,wBAAwB;YACzC,SAAS,EAAE,EAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC;YAC7B,KAAK,EAAE,EAAE;SACZ,EACE,OAAO,CACF,CAAC;QAEb,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC9D,CAAC;QAED,IACI,OAAO,aAAa,CAAC,eAAe,KAAK,QAAQ;YACjD,aAAa,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAC1C,CAAC;YACC,MAAM,IAAI,KAAK,CACX,6EAA6E,CAChF,CAAC;QACN,CAAC;QAED,IAAI,CAAC,eAAe,GAAG,aAAa,CAAC,eAAe,CAAC;QACr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AAC;oBACnD,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAC3C,CAAC;oBACC,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,GAAG,KAAK,CAAC;oBAClD,MAAM;gBACV,CAAC;gBACD,KAAK,EAAE,CAAC;YACZ,CAAC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;;AAjaM,iBAAO,GAAG,OAAO,AAAV,CAAW;AAoa7B,SAAS,MAAM,CAAC,IAAS,EAAE,GAAQ;IAC/B,IAAI,GAAG,EAAE,CAAC;QACN,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,IAAI,CAAU,GAAM;IACzB,OAAO,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,eAAe,SAAS,CAAC","sourcesContent":["import {DEFAULT_PLACEHOLDER_CHAR, FormatCharacters, mergeFormatCharacters} from './helpers';\r\nimport {Pattern} from './pattern';\r\n\r\ntype SelectionObject = { start: number; end: number };\r\n\r\ntype Options = {\r\n formatCharacters: FormatCharacters;\r\n pattern: string;\r\n isRevealingMask: boolean;\r\n placeholderChar: string;\r\n selection: SelectionObject;\r\n value: string;\r\n};\r\n\r\nexport class InputMask {\r\n static Pattern = Pattern;\r\n\r\n formatCharacters!: FormatCharacters;\r\n pattern!: Pattern;\r\n isRevealingMask!: boolean;\r\n placeholderChar!: string;\r\n selection!: SelectionObject;\r\n value!: string[];\r\n emptyValue = '';\r\n\r\n _history: {\r\n value: string;\r\n selection: SelectionObject;\r\n lastOp: string | null;\r\n startUndo?: boolean;\r\n }[] = [];\r\n\r\n _historyIndex: null | number = null;\r\n _lastOp: null | string = null;\r\n _lastSelection: null | SelectionObject = null;\r\n\r\n constructor(options: Partial<Options>) {\r\n const mergedOptions: Options = {\r\n ...{\r\n isRevealingMask: false,\r\n placeholderChar: DEFAULT_PLACEHOLDER_CHAR,\r\n selection: {start: 0, end: 0},\r\n value: ''\r\n },\r\n ...options\r\n } as Options;\r\n\r\n if (!mergedOptions.pattern) {\r\n throw new Error('InputMask: you must provide a pattern.');\r\n }\r\n\r\n if (\r\n typeof mergedOptions.placeholderChar !== 'string' ||\r\n mergedOptions.placeholderChar.length > 1\r\n ) {\r\n throw new Error(\r\n 'InputMask: placeholderChar should be a single character or an empty string.'\r\n );\r\n }\r\n\r\n this.placeholderChar = mergedOptions.placeholderChar;\r\n this.formatCharacters = mergeFormatCharacters(\r\n mergedOptions.formatCharacters\r\n );\r\n\r\n this.setPattern(mergedOptions.pattern, {\r\n value: mergedOptions.value,\r\n selection: mergedOptions.selection,\r\n isRevealingMask: mergedOptions.isRevealingMask\r\n });\r\n }\r\n\r\n setPattern(patternSource: string, options: Partial<Options>) {\r\n const merged = {\r\n selection: {start: 0, end: 0},\r\n value: '',\r\n ...options\r\n };\r\n\r\n this.pattern = new Pattern(\r\n patternSource,\r\n this.formatCharacters,\r\n this.placeholderChar,\r\n merged.isRevealingMask\r\n );\r\n\r\n this.setValue(merged.value);\r\n\r\n this.emptyValue = this.pattern.formatValue([]).join('');\r\n this.selection = merged.selection;\r\n this._resetHistory();\r\n }\r\n\r\n setValue(value?: string) {\r\n if (value == null) {\r\n value = '';\r\n }\r\n this.value = this.pattern.formatValue((value || '').split(''));\r\n }\r\n\r\n _resetHistory() {\r\n this._history = [];\r\n this._historyIndex = null;\r\n this._lastOp = null;\r\n this._lastSelection = {...this.selection};\r\n }\r\n\r\n getValue(): string {\r\n if (this.pattern.isRevealingMask) {\r\n this.value = this.pattern.formatValue(\r\n (this.getRawValue() || '').split('')\r\n );\r\n }\r\n return (this.value || []).join('');\r\n }\r\n\r\n getRawValue(): string {\r\n var rawValue = [];\r\n for (var i = 0; i < this.value.length; i++) {\r\n if (this.pattern._editableIndices[i] === true) {\r\n rawValue.push(this.value[i]);\r\n }\r\n }\r\n return rawValue.join('');\r\n }\r\n\r\n /**\r\n * Applies a single character of input based on the current selection.\r\n * @param {string} char\r\n * @return {boolean} true if a change has been made to value or selection as a\r\n * result of the input, false otherwise.\r\n */\r\n input(char: string) {\r\n // Ignore additional input if the cursor's at the end of the pattern\r\n if (\r\n this.selection.start === this.selection.end &&\r\n this.selection.start === this.pattern.length\r\n ) {\r\n return false;\r\n }\r\n\r\n const selectionBefore = copy(this.selection);\r\n const valueBefore = this.getValue();\r\n\r\n let inputIndex = this.selection.start;\r\n\r\n // If the cursor or selection is prior to the first editable character, make\r\n // sure any input given is applied to it.\r\n if (this.pattern.firstEditableIndex && inputIndex < this.pattern.firstEditableIndex) {\r\n inputIndex = this.pattern.firstEditableIndex;\r\n }\r\n\r\n // Bail out or add the character to input\r\n if (this.pattern.isEditableIndex(inputIndex)) {\r\n if (!this.pattern.isValidAtIndex(char, inputIndex)) {\r\n return false;\r\n }\r\n this.value[inputIndex] = this.pattern.transform(char, inputIndex);\r\n } else {\r\n console.log('not editable');\r\n }\r\n\r\n // If multiple characters were selected, blank the remainder out based on the\r\n // pattern.\r\n let end = this.selection.end - 1;\r\n while (end > inputIndex) {\r\n if (this.pattern.isEditableIndex(end)) {\r\n this.value[end] = this.placeholderChar;\r\n }\r\n end--;\r\n }\r\n\r\n // Advance the cursor to the next character\r\n this.selection.start = this.selection.end = inputIndex + 1;\r\n\r\n // Skip over any subsequent static characters\r\n while (\r\n this.pattern.length > this.selection.start &&\r\n !this.pattern.isEditableIndex(this.selection.start)\r\n ) {\r\n this.selection.start++;\r\n this.selection.end++;\r\n }\r\n\r\n // History\r\n if (this._historyIndex != null) {\r\n // Took more input after undoing, so blow any subsequent history away\r\n this._history.splice(\r\n this._historyIndex,\r\n this._history.length - this._historyIndex\r\n );\r\n this._historyIndex = null;\r\n }\r\n if (\r\n this._lastOp !== 'input' ||\r\n selectionBefore.start !== selectionBefore.end ||\r\n (this._lastSelection !== null &&\r\n selectionBefore.start !== this._lastSelection.start)\r\n ) {\r\n this._history.push({\r\n value: valueBefore,\r\n selection: selectionBefore,\r\n lastOp: this._lastOp\r\n });\r\n }\r\n this._lastOp = 'input';\r\n this._lastSelection = copy(this.selection);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Attempts to delete from the value based on the current cursor position or\r\n * selection.\r\n * @return {boolean} true if the value or selection changed as the result of\r\n * backspacing, false otherwise.\r\n */\r\n backspace() {\r\n // If the cursor is at the start there's nothing to do\r\n if (this.selection.start === 0 && this.selection.end === 0) {\r\n return false;\r\n }\r\n\r\n var selectionBefore = {...this.selection};\r\n var valueBefore = this.getValue();\r\n\r\n // No range selected - work on the character preceding the cursor\r\n if (this.selection.start === this.selection.end) {\r\n if (this.pattern.isEditableIndex(this.selection.start - 1)) {\r\n if (this.pattern.isRevealingMask) {\r\n this.value.splice(this.selection.start - 1);\r\n } else {\r\n this.value[this.selection.start - 1] = this.placeholderChar;\r\n }\r\n }\r\n this.selection.start--;\r\n this.selection.end--;\r\n }\r\n // Range selected - delete characters and leave the cursor at the start of the selection\r\n else {\r\n var end = this.selection.end - 1;\r\n while (end >= this.selection.start) {\r\n if (this.pattern.isEditableIndex(end)) {\r\n this.value[end] = this.placeholderChar;\r\n }\r\n end--;\r\n }\r\n this.selection.end = this.selection.start;\r\n }\r\n\r\n // History\r\n if (this._historyIndex != null) {\r\n // Took more input after undoing, so blow any subsequent history away\r\n this._history.splice(\r\n this._historyIndex,\r\n this._history.length - this._historyIndex\r\n );\r\n }\r\n if (\r\n this._lastOp !== 'backspace' ||\r\n selectionBefore.start !== selectionBefore.end ||\r\n (this._lastSelection !== null &&\r\n selectionBefore.start !== this._lastSelection.start)\r\n ) {\r\n this._history.push({\r\n value: valueBefore,\r\n selection: selectionBefore,\r\n lastOp: this._lastOp\r\n });\r\n }\r\n this._lastOp = 'backspace';\r\n this._lastSelection = {...this.selection};\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Attempts to paste a string of input at the current cursor position or over\r\n * the top of the current selection.\r\n * Invalid content at any position will cause the paste to be rejected, and it\r\n * may contain static parts of the mask's pattern.\r\n * @param {string} input\r\n * @return {boolean} true if the paste was successful, false otherwise.\r\n */\r\n paste(input: string) {\r\n // This is necessary because we're just calling input() with each character\r\n // and rolling back if any were invalid, rather than checking up-front.\r\n var initialState = {\r\n value: this.value.slice(),\r\n selection: {...this.selection},\r\n _lastOp: this._lastOp,\r\n _history: this._history.slice(),\r\n _historyIndex: this._historyIndex,\r\n _lastSelection: {...this._lastSelection}\r\n };\r\n\r\n // If there are static characters at the start of the pattern and the cursor\r\n // or selection is within them, the static characters must match for a valid\r\n // paste.\r\n if (this.selection.start < this.pattern.firstEditableIndex!) {\r\n for (\r\n var i = 0, l = this.pattern.firstEditableIndex! - this.selection.start;\r\n i < l;\r\n i++\r\n ) {\r\n if (input.charAt(i) !== this.pattern.pattern[i]) {\r\n return false;\r\n }\r\n }\r\n\r\n // Continue as if the selection and input started from the editable part of\r\n // the pattern.\r\n input = input.substring(\r\n this.pattern.firstEditableIndex! - this.selection.start\r\n );\r\n this.selection.start = this.pattern.firstEditableIndex!;\r\n }\r\n\r\n for (\r\n i = 0, l = input.length;\r\n i < l && this.selection.start <= this.pattern.lastEditableIndex!;\r\n i++\r\n ) {\r\n var valid = this.input(input.charAt(i));\r\n // Allow static parts of the pattern to appear in pasted input - they will\r\n // already have been stepped over by input(), so verify that the value\r\n // deemed invalid by input() was the expected static character.\r\n if (!valid) {\r\n if (this.selection.start > 0) {\r\n // XXX This only allows for one static character to be skipped\r\n var patternIndex = this.selection.start - 1;\r\n if (\r\n !this.pattern.isEditableIndex(patternIndex) &&\r\n input.charAt(i) === this.pattern.pattern[patternIndex]\r\n ) {\r\n continue;\r\n }\r\n }\r\n\r\n Object.keys(initialState).forEach(key => {\r\n // @ts-ignore\r\n this[key] = initialState[key];\r\n });\r\n\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n undo() {\r\n // If there is no history, or nothing more on the history stack, we can't undo\r\n if (this._history.length === 0 || this._historyIndex === 0) {\r\n return false;\r\n }\r\n\r\n var historyItem;\r\n if (this._historyIndex == null) {\r\n // Not currently undoing, set up the initial history index\r\n this._historyIndex = this._history.length - 1;\r\n historyItem = this._history[this._historyIndex];\r\n // Add a new history entry if anything has changed since the last one, so we\r\n // can redo back to the initial state we started undoing from.\r\n var value = this.getValue();\r\n if (\r\n historyItem.value !== value ||\r\n historyItem.selection.start !== this.selection.start ||\r\n historyItem.selection.end !== this.selection.end\r\n ) {\r\n this._history.push({\r\n value: value,\r\n selection: {...this.selection},\r\n lastOp: this._lastOp,\r\n startUndo: true\r\n });\r\n }\r\n } else {\r\n historyItem = this._history[--this._historyIndex];\r\n }\r\n\r\n this.value = historyItem.value.split('');\r\n this.selection = historyItem.selection;\r\n this._lastOp = historyItem.lastOp;\r\n return true;\r\n }\r\n\r\n redo() {\r\n if (this._history.length === 0 || this._historyIndex == null) {\r\n return false;\r\n }\r\n var historyItem = this._history[++this._historyIndex];\r\n // If this is the last history item, we're done redoing\r\n if (this._historyIndex === this._history.length - 1) {\r\n this._historyIndex = null;\r\n // If the last history item was only added to start undoing, remove it\r\n if (historyItem.startUndo) {\r\n this._history.pop();\r\n }\r\n }\r\n this.value = historyItem.value.split('');\r\n this.selection = historyItem.selection;\r\n this._lastOp = historyItem.lastOp;\r\n return true;\r\n }\r\n\r\n setSelection(selection: SelectionObject) {\r\n this.selection = {...selection};\r\n\r\n if (this.selection.start === this.selection.end) {\r\n if (this.selection.start < this.pattern.firstEditableIndex!) {\r\n this.selection!.start = this.selection!.end = this.pattern\r\n .firstEditableIndex as number;\r\n return true;\r\n }\r\n // Set selection to the first editable, non-placeholder character before the selection\r\n // OR to the beginning of the pattern\r\n var index = this.selection.start;\r\n while (index >= this.pattern.firstEditableIndex!) {\r\n if (\r\n (this.pattern.isEditableIndex(index - 1) &&\r\n this.value[index - 1] !== this.placeholderChar) ||\r\n index === this.pattern.firstEditableIndex\r\n ) {\r\n this.selection.start = this.selection.end = index;\r\n break;\r\n }\r\n index--;\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n}\r\n\r\nfunction extend(dest: any, src: any) {\r\n if (src) {\r\n let props = Object.keys(src);\r\n\r\n for (var i = 0, l = props.length; i < l; i++) {\r\n dest[props[i]] = src[props[i]];\r\n }\r\n }\r\n\r\n return dest;\r\n}\r\n\r\nfunction copy<T = any>(obj: T): T {\r\n return extend({}, obj);\r\n}\r\n\r\nexport default InputMask;"]}
1
+ {"version":3,"file":"inputMaskCore.js","sourceRoot":"","sources":["../../../../../components/input/mask/inputMaskCore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,wBAAwB,EAAoB,qBAAqB,EAAC,MAAM,WAAW,CAAC;AAC5F,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAgClC;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IAkClB,YAAY,OAAyB;QAlBrC,sFAAsF;QACtF,eAAU,GAAG,EAAE,CAAC;QAEhB,kCAAkC;QAClC,aAAQ,GAKF,EAAE,CAAC;QAET,wFAAwF;QACxF,kBAAa,GAAkB,IAAI,CAAC;QACpC,8FAA8F;QAC9F,YAAO,GAAkB,IAAI,CAAC;QAC9B,mFAAmF;QACnF,mBAAc,GAA2B,IAAI,CAAC;QAG1C,MAAM,aAAa,GAAY,cACxB;YACC,eAAe,EAAE,KAAK;YACtB,eAAe,EAAE,wBAAwB;YACzC,SAAS,EAAE,EAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC;YAC7B,KAAK,EAA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,CAAC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;;AApcD,0DAA0D;AACnD,iBAAO,GAAG,OAAO,AAAV,CAAW;AAsc7B,SAAS,MAAM,CAAC,IAAS,EAAE,GAAQ;IAC/B,IAAI,GAAG,EAAE,CAAC;QACN,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,IAAI,CAAU,GAAM;IACzB,OAAO,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,eAAe,SAAS,CAAC","sourcesContent":["import {DEFAULT_PLACEHOLDER_CHAR, FormatCharacters, mergeFormatCharacters} from './helpers';\r\nimport {Pattern} from './pattern';\r\n\r\n/** Selection range within the mask, as character offsets (`end` exclusive). */\r\ntype SelectionObject = { start: number; end: number };\r\n\r\ntype Options = {\r\n /** Custom format characters merged over the defaults (see {@link mergeFormatCharacters}). */\r\n formatCharacters: FormatCharacters;\r\n /** Pattern source, see {@link Pattern}. Required. */\r\n pattern: string;\r\n /**\r\n * When true, the pattern is shown only up to the last entered character instead of in full with placeholders.\r\n * @default false\r\n */\r\n isRevealingMask: boolean;\r\n /**\r\n * Single character (or empty string) shown in unfilled editable positions.\r\n * @default \"_\"\r\n */\r\n placeholderChar: string;\r\n /**\r\n * Initial selection.\r\n * @default {start: 0, end: 0}\r\n */\r\n selection: SelectionObject;\r\n /**\r\n * Initial value; formatted into the pattern.\r\n * @default \"\"\r\n */\r\n value: string;\r\n};\r\n\r\n/**\r\n * Framework-independent input-mask engine behind `MaskedInput`: holds the formatted value and the\r\n * selection, applies single-character input, Backspace and paste according to a {@link Pattern}, and keeps an\r\n * undo/redo history. Callers keep {@link InputMask.selection} in sync with the real input before each operation.\r\n * @throws Error when the pattern is missing or has no editable characters, or `placeholderChar` is longer than one character.\r\n */\r\nexport class InputMask {\r\n /** The {@link Pattern} class, exposed for convenience. */\r\n static Pattern = Pattern;\r\n\r\n /** Effective format characters (defaults merged with the custom ones). */\r\n formatCharacters!: FormatCharacters;\r\n /** The parsed current pattern. */\r\n pattern!: Pattern;\r\n /** Declared but never assigned; the effective flag is `pattern.isRevealingMask`. */\r\n isRevealingMask!: boolean;\r\n /** Character shown in unfilled editable positions. */\r\n placeholderChar!: string;\r\n /** Current selection; read and updated by the editing operations. */\r\n selection!: SelectionObject;\r\n /** Current formatted value, one entry per pattern position. */\r\n value!: string[];\r\n /** The formatted value with no characters entered (the pattern with placeholders). */\r\n emptyValue = '';\r\n\r\n /** Internal undo/redo history. */\r\n _history: {\r\n value: string;\r\n selection: SelectionObject;\r\n lastOp: string | null;\r\n startUndo?: boolean;\r\n }[] = [];\r\n\r\n /** Internal: position in {@link InputMask._history} while undoing, otherwise `null`. */\r\n _historyIndex: null | number = null;\r\n /** Internal: last editing operation (`input`, `backspace`), used to group history entries. */\r\n _lastOp: null | string = null;\r\n /** Internal: selection after the last operation, used to group history entries. */\r\n _lastSelection: null | SelectionObject = null;\r\n\r\n constructor(options: Partial<Options>) {\r\n const mergedOptions: Options = {\r\n ...{\r\n isRevealingMask: false,\r\n placeholderChar: DEFAULT_PLACEHOLDER_CHAR,\r\n selection: {start: 0, end: 0},\r\n value: ''\r\n },\r\n ...options\r\n } as Options;\r\n\r\n if (!mergedOptions.pattern) {\r\n throw new Error('InputMask: you must provide a pattern.');\r\n }\r\n\r\n if (\r\n typeof mergedOptions.placeholderChar !== 'string' ||\r\n mergedOptions.placeholderChar.length > 1\r\n ) {\r\n throw new Error(\r\n 'InputMask: placeholderChar should be a single character or an empty string.'\r\n );\r\n }\r\n\r\n this.placeholderChar = mergedOptions.placeholderChar;\r\n this.formatCharacters = mergeFormatCharacters(\r\n mergedOptions.formatCharacters\r\n );\r\n\r\n this.setPattern(mergedOptions.pattern, {\r\n value: mergedOptions.value,\r\n selection: mergedOptions.selection,\r\n isRevealingMask: mergedOptions.isRevealingMask\r\n });\r\n }\r\n\r\n /**\r\n * Replaces the pattern, formats `options.value` (default empty) into it, sets `options.selection` and clears the\r\n * history. Only `value`, `selection` and `isRevealingMask` of `options` are used.\r\n */\r\n setPattern(patternSource: string, options: Partial<Options>) {\r\n const merged = {\r\n selection: {start: 0, end: 0},\r\n value: '',\r\n ...options\r\n };\r\n\r\n this.pattern = new Pattern(\r\n patternSource,\r\n this.formatCharacters,\r\n this.placeholderChar,\r\n merged.isRevealingMask\r\n );\r\n\r\n this.setValue(merged.value);\r\n\r\n this.emptyValue = this.pattern.formatValue([]).join('');\r\n this.selection = merged.selection;\r\n this._resetHistory();\r\n }\r\n\r\n /**\r\n * Formats `value` into the pattern, replacing the current value. Characters that do not fit a position become\r\n * placeholders; literal pattern characters in `value` are skipped over. Does not touch history or selection.\r\n */\r\n setValue(value?: string) {\r\n if (value == null) {\r\n value = '';\r\n }\r\n this.value = this.pattern.formatValue((value || '').split(''));\r\n }\r\n\r\n /** Internal: clears the undo/redo history. */\r\n _resetHistory() {\r\n this._history = [];\r\n this._historyIndex = null;\r\n this._lastOp = null;\r\n this._lastSelection = {...this.selection};\r\n }\r\n\r\n /** The formatted value including literals and placeholders. */\r\n getValue(): string {\r\n if (this.pattern.isRevealingMask) {\r\n this.value = this.pattern.formatValue(\r\n (this.getRawValue() || '').split('')\r\n );\r\n }\r\n return (this.value || []).join('');\r\n }\r\n\r\n /** Only the characters at editable positions (placeholders included), without literals. */\r\n getRawValue(): string {\r\n var rawValue = [];\r\n for (var i = 0; i < this.value.length; i++) {\r\n if (this.pattern._editableIndices[i] === true) {\r\n rawValue.push(this.value[i]);\r\n }\r\n }\r\n return rawValue.join('');\r\n }\r\n\r\n /**\r\n * Applies a single character of input based on the current selection.\r\n * Invalid characters are rejected; typing over a selected range blanks the rest of the range, and the cursor\r\n * skips following literals.\r\n * @returns true if the value or selection changed, false if the input was rejected or the cursor is at the end.\r\n */\r\n input(char: string) {\r\n // Ignore additional input if the cursor's at the end of the pattern\r\n if (\r\n this.selection.start === this.selection.end &&\r\n this.selection.start === this.pattern.length\r\n ) {\r\n return false;\r\n }\r\n\r\n const selectionBefore = copy(this.selection);\r\n const valueBefore = this.getValue();\r\n\r\n let inputIndex = this.selection.start;\r\n\r\n // If the cursor or selection is prior to the first editable character, make\r\n // sure any input given is applied to it.\r\n if (this.pattern.firstEditableIndex && inputIndex < this.pattern.firstEditableIndex) {\r\n inputIndex = this.pattern.firstEditableIndex;\r\n }\r\n\r\n // Bail out or add the character to input\r\n if (this.pattern.isEditableIndex(inputIndex)) {\r\n if (!this.pattern.isValidAtIndex(char, inputIndex)) {\r\n return false;\r\n }\r\n this.value[inputIndex] = this.pattern.transform(char, inputIndex);\r\n } else {\r\n console.log('not editable');\r\n }\r\n\r\n // If multiple characters were selected, blank the remainder out based on the\r\n // pattern.\r\n let end = this.selection.end - 1;\r\n while (end > inputIndex) {\r\n if (this.pattern.isEditableIndex(end)) {\r\n this.value[end] = this.placeholderChar;\r\n }\r\n end--;\r\n }\r\n\r\n // Advance the cursor to the next character\r\n this.selection.start = this.selection.end = inputIndex + 1;\r\n\r\n // Skip over any subsequent static characters\r\n while (\r\n this.pattern.length > this.selection.start &&\r\n !this.pattern.isEditableIndex(this.selection.start)\r\n ) {\r\n this.selection.start++;\r\n this.selection.end++;\r\n }\r\n\r\n // History\r\n if (this._historyIndex != null) {\r\n // Took more input after undoing, so blow any subsequent history away\r\n this._history.splice(\r\n this._historyIndex,\r\n this._history.length - this._historyIndex\r\n );\r\n this._historyIndex = null;\r\n }\r\n if (\r\n this._lastOp !== 'input' ||\r\n selectionBefore.start !== selectionBefore.end ||\r\n (this._lastSelection !== null &&\r\n selectionBefore.start !== this._lastSelection.start)\r\n ) {\r\n this._history.push({\r\n value: valueBefore,\r\n selection: selectionBefore,\r\n lastOp: this._lastOp\r\n });\r\n }\r\n this._lastOp = 'input';\r\n this._lastSelection = copy(this.selection);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Attempts to delete from the value based on the current cursor position or\r\n * selection.\r\n * @returns true if the value or selection changed, false when the cursor is at the start.\r\n */\r\n backspace() {\r\n // If the cursor is at the start there's nothing to do\r\n if (this.selection.start === 0 && this.selection.end === 0) {\r\n return false;\r\n }\r\n\r\n var selectionBefore = {...this.selection};\r\n var valueBefore = this.getValue();\r\n\r\n // No range selected - work on the character preceding the cursor\r\n if (this.selection.start === this.selection.end) {\r\n if (this.pattern.isEditableIndex(this.selection.start - 1)) {\r\n if (this.pattern.isRevealingMask) {\r\n this.value.splice(this.selection.start - 1);\r\n } else {\r\n this.value[this.selection.start - 1] = this.placeholderChar;\r\n }\r\n }\r\n this.selection.start--;\r\n this.selection.end--;\r\n }\r\n // Range selected - delete characters and leave the cursor at the start of the selection\r\n else {\r\n var end = this.selection.end - 1;\r\n while (end >= this.selection.start) {\r\n if (this.pattern.isEditableIndex(end)) {\r\n this.value[end] = this.placeholderChar;\r\n }\r\n end--;\r\n }\r\n this.selection.end = this.selection.start;\r\n }\r\n\r\n // History\r\n if (this._historyIndex != null) {\r\n // Took more input after undoing, so blow any subsequent history away\r\n this._history.splice(\r\n this._historyIndex,\r\n this._history.length - this._historyIndex\r\n );\r\n }\r\n if (\r\n this._lastOp !== 'backspace' ||\r\n selectionBefore.start !== selectionBefore.end ||\r\n (this._lastSelection !== null &&\r\n selectionBefore.start !== this._lastSelection.start)\r\n ) {\r\n this._history.push({\r\n value: valueBefore,\r\n selection: selectionBefore,\r\n lastOp: this._lastOp\r\n });\r\n }\r\n this._lastOp = 'backspace';\r\n this._lastSelection = {...this.selection};\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Attempts to paste a string of input at the current cursor position or over\r\n * the top of the current selection.\r\n * Invalid content at any position will cause the paste to be rejected, and it\r\n * may contain static parts of the mask's pattern.\r\n * On rejection the previous state is restored.\r\n * @returns true if the paste was successful, false otherwise.\r\n */\r\n paste(input: string) {\r\n // This is necessary because we're just calling input() with each character\r\n // and rolling back if any were invalid, rather than checking up-front.\r\n var initialState = {\r\n value: this.value.slice(),\r\n selection: {...this.selection},\r\n _lastOp: this._lastOp,\r\n _history: this._history.slice(),\r\n _historyIndex: this._historyIndex,\r\n _lastSelection: {...this._lastSelection}\r\n };\r\n\r\n // If there are static characters at the start of the pattern and the cursor\r\n // or selection is within them, the static characters must match for a valid\r\n // paste.\r\n if (this.selection.start < this.pattern.firstEditableIndex!) {\r\n for (\r\n var i = 0, l = this.pattern.firstEditableIndex! - this.selection.start;\r\n i < l;\r\n i++\r\n ) {\r\n if (input.charAt(i) !== this.pattern.pattern[i]) {\r\n return false;\r\n }\r\n }\r\n\r\n // Continue as if the selection and input started from the editable part of\r\n // the pattern.\r\n input = input.substring(\r\n this.pattern.firstEditableIndex! - this.selection.start\r\n );\r\n this.selection.start = this.pattern.firstEditableIndex!;\r\n }\r\n\r\n for (\r\n i = 0, l = input.length;\r\n i < l && this.selection.start <= this.pattern.lastEditableIndex!;\r\n i++\r\n ) {\r\n var valid = this.input(input.charAt(i));\r\n // Allow static parts of the pattern to appear in pasted input - they will\r\n // already have been stepped over by input(), so verify that the value\r\n // deemed invalid by input() was the expected static character.\r\n if (!valid) {\r\n if (this.selection.start > 0) {\r\n // XXX This only allows for one static character to be skipped\r\n var patternIndex = this.selection.start - 1;\r\n if (\r\n !this.pattern.isEditableIndex(patternIndex) &&\r\n input.charAt(i) === this.pattern.pattern[patternIndex]\r\n ) {\r\n continue;\r\n }\r\n }\r\n\r\n Object.keys(initialState).forEach(key => {\r\n // @ts-ignore\r\n this[key] = initialState[key];\r\n });\r\n\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Restores the previous history state (value and selection).\r\n * @returns false when there is nothing to undo.\r\n */\r\n undo() {\r\n // If there is no history, or nothing more on the history stack, we can't undo\r\n if (this._history.length === 0 || this._historyIndex === 0) {\r\n return false;\r\n }\r\n\r\n var historyItem;\r\n if (this._historyIndex == null) {\r\n // Not currently undoing, set up the initial history index\r\n this._historyIndex = this._history.length - 1;\r\n historyItem = this._history[this._historyIndex];\r\n // Add a new history entry if anything has changed since the last one, so we\r\n // can redo back to the initial state we started undoing from.\r\n var value = this.getValue();\r\n if (\r\n historyItem.value !== value ||\r\n historyItem.selection.start !== this.selection.start ||\r\n historyItem.selection.end !== this.selection.end\r\n ) {\r\n this._history.push({\r\n value: value,\r\n selection: {...this.selection},\r\n lastOp: this._lastOp,\r\n startUndo: true\r\n });\r\n }\r\n } else {\r\n historyItem = this._history[--this._historyIndex];\r\n }\r\n\r\n this.value = historyItem.value.split('');\r\n this.selection = historyItem.selection;\r\n this._lastOp = historyItem.lastOp;\r\n return true;\r\n }\r\n\r\n /**\r\n * Re-applies a state previously undone.\r\n * @returns false when there is nothing to redo.\r\n */\r\n redo() {\r\n if (this._history.length === 0 || this._historyIndex == null) {\r\n return false;\r\n }\r\n var historyItem = this._history[++this._historyIndex];\r\n // If this is the last history item, we're done redoing\r\n if (this._historyIndex === this._history.length - 1) {\r\n this._historyIndex = null;\r\n // If the last history item was only added to start undoing, remove it\r\n if (historyItem.startUndo) {\r\n this._history.pop();\r\n }\r\n }\r\n this.value = historyItem.value.split('');\r\n this.selection = historyItem.selection;\r\n this._lastOp = historyItem.lastOp;\r\n return true;\r\n }\r\n\r\n /**\r\n * Sets the selection. A collapsed cursor is moved back to just after the last entered character before it\r\n * (never before the first editable position).\r\n * @returns true when the selection was collapsed (and possibly adjusted), false for a range.\r\n */\r\n setSelection(selection: SelectionObject) {\r\n this.selection = {...selection};\r\n\r\n if (this.selection.start === this.selection.end) {\r\n if (this.selection.start < this.pattern.firstEditableIndex!) {\r\n this.selection!.start = this.selection!.end = this.pattern\r\n .firstEditableIndex as number;\r\n return true;\r\n }\r\n // Set selection to the first editable, non-placeholder character before the selection\r\n // OR to the beginning of the pattern\r\n var index = this.selection.start;\r\n while (index >= this.pattern.firstEditableIndex!) {\r\n if (\r\n (this.pattern.isEditableIndex(index - 1) &&\r\n this.value[index - 1] !== this.placeholderChar) ||\r\n index === this.pattern.firstEditableIndex\r\n ) {\r\n this.selection.start = this.selection.end = index;\r\n break;\r\n }\r\n index--;\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n}\r\n\r\nfunction extend(dest: any, src: any) {\r\n if (src) {\r\n let props = Object.keys(src);\r\n\r\n for (var i = 0, l = props.length; i < l; i++) {\r\n dest[props[i]] = src[props[i]];\r\n }\r\n }\r\n\r\n return dest;\r\n}\r\n\r\nfunction copy<T = any>(obj: T): T {\r\n return extend({}, obj);\r\n}\r\n\r\nexport default InputMask;"]}
@@ -1,20 +1,44 @@
1
1
  import { FormatCharacters } from './helpers';
2
+ /**
3
+ * Parsed mask pattern. Characters listed in `formatCharacters` mark editable positions, every other character is a
4
+ * literal, and {@link ESCAPE_CHAR} turns the next character into a literal.
5
+ * @throws Error when the source ends with a bare escape character or contains no editable position.
6
+ */
2
7
  export declare class Pattern {
8
+ /** Character used for unfilled editable positions. */
3
9
  placeholderChar: string;
10
+ /** Format character definitions. */
4
11
  formatCharacters: FormatCharacters;
12
+ /** Pattern definition string, including escape characters. */
5
13
  source: string;
14
+ /** Pattern characters after escape characters have been processed. */
6
15
  pattern: never[];
16
+ /** Length of the pattern after escape characters have been processed. */
7
17
  length: number;
18
+ /** Index of the first editable character. */
8
19
  firstEditableIndex: null | number;
20
+ /** Index of the last editable character. */
9
21
  lastEditableIndex: null | number;
22
+ /** Lookup for indices of editable characters in the pattern. */
10
23
  _editableIndices: {
11
24
  [key: number]: boolean;
12
25
  };
26
+ /** If true, only the pattern before the last valid value character shows. */
13
27
  isRevealingMask: boolean;
14
28
  constructor(source: string, formatCharacters: FormatCharacters, placeholderChar: string, isRevealingMask?: boolean);
29
+ /** Internal: parses {@link Pattern.source}; called by the constructor. */
15
30
  _parse(): void;
31
+ /**
32
+ * Lays the characters of `value` into the pattern: literals are inserted (and skipped in `value` when it already
33
+ * contains them), valid characters are transformed and invalid ones replaced by the placeholder.
34
+ * @returns one entry per pattern position; for a revealing mask the entries after the entered characters stay
35
+ * `undefined`.
36
+ */
16
37
  formatValue(value: string[]): string[];
38
+ /** Whether the position holds a format character. */
17
39
  isEditableIndex(index: number): boolean;
40
+ /** Whether `char` is accepted at the editable position `index`. */
18
41
  isValidAtIndex(char: string, index: number): boolean;
42
+ /** Applies the format character's `transform` at `index`, if it defines one. */
19
43
  transform(char: string, index: number): string;
20
44
  }