d2coreui 23.0.52 → 23.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +154 -0
- package/components/clipboard/clipboardUtils.d.ts +11 -0
- package/components/clipboard/clipboardUtils.js +16 -4
- package/components/clipboard/clipboardUtils.js.map +1 -1
- package/components/codemirror/SyntaxHighlighter.d.ts +13 -0
- package/components/codemirror/SyntaxHighlighter.js +6 -1
- package/components/codemirror/SyntaxHighlighter.js.map +1 -1
- package/components/collapse/expandable.d.ts +10 -0
- package/components/collapse/expandable.js +4 -0
- package/components/collapse/expandable.js.map +1 -1
- package/components/color/colorPicker.d.ts +16 -0
- package/components/color/colorPicker.js +4 -0
- package/components/color/colorPicker.js.map +1 -1
- package/components/color/colorSwatch.d.ts +16 -0
- package/components/color/colorSwatch.js +23 -2
- package/components/color/colorSwatch.js.map +1 -1
- package/components/color/colorUtils.d.ts +9 -0
- package/components/color/colorUtils.js +15 -0
- package/components/color/colorUtils.js.map +1 -1
- package/components/date/dateRangeInput.d.ts +76 -0
- package/components/date/dateRangeInput.js +63 -12
- package/components/date/dateRangeInput.js.map +1 -1
- package/components/date/dateRangeInputAdvancedPanel.d.ts +27 -0
- package/components/date/dateRangeInputAdvancedPanel.js +7 -0
- package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
- package/components/date/dateRangeInputConfirm.d.ts +18 -0
- package/components/date/dateRangeInputConfirm.js +12 -0
- package/components/date/dateRangeInputConfirm.js.map +1 -1
- package/components/date/dateTimeInput.d.ts +99 -0
- package/components/date/dateTimeInput.js +78 -6
- package/components/date/dateTimeInput.js.map +1 -1
- package/components/date/durationInput.d.ts +37 -0
- package/components/date/durationInput.js +26 -3
- package/components/date/durationInput.js.map +1 -1
- package/components/date/savedIntervals.d.ts +63 -0
- package/components/date/savedIntervals.js +37 -0
- package/components/date/savedIntervals.js.map +1 -1
- package/components/date/savedIntervalsDialog.d.ts +13 -0
- package/components/date/savedIntervalsDialog.js +7 -2
- package/components/date/savedIntervalsDialog.js.map +1 -1
- package/components/form/NiceFormItem.d.ts +9 -0
- package/components/form/NiceFormItem.js +4 -0
- package/components/form/NiceFormItem.js.map +1 -1
- package/components/grid/cell/beanAccessor.d.ts +12 -0
- package/components/grid/cell/beanAccessor.js +8 -0
- package/components/grid/cell/beanAccessor.js.map +1 -1
- package/components/grid/cell/bigNumberCellEditor.d.ts +9 -0
- package/components/grid/cell/bigNumberCellEditor.js +19 -0
- package/components/grid/cell/bigNumberCellEditor.js.map +1 -1
- package/components/grid/cell/cellControl.d.ts +4 -0
- package/components/grid/cell/cellControl.js +14 -0
- package/components/grid/cell/cellControl.js.map +1 -1
- package/components/grid/cell/cellEditorUtils.d.ts +6 -0
- package/components/grid/cell/cellEditorUtils.js +6 -0
- package/components/grid/cell/cellEditorUtils.js.map +1 -1
- package/components/grid/cell/customEnumCellEditor.d.ts +6 -0
- package/components/grid/cell/customEnumCellEditor.js +10 -0
- package/components/grid/cell/customEnumCellEditor.js.map +1 -1
- package/components/grid/cell/dataGridCellEditorComponent.d.ts +26 -0
- package/components/grid/cell/dataGridCellEditorComponent.js +21 -0
- package/components/grid/cell/dataGridCellEditorComponent.js.map +1 -1
- package/components/grid/cell/dateCellEditor.d.ts +6 -0
- package/components/grid/cell/dateCellEditor.js +10 -0
- package/components/grid/cell/dateCellEditor.js.map +1 -1
- package/components/grid/cell/dragListenerFeature.d.ts +6 -0
- package/components/grid/cell/dragListenerFeature.js +6 -0
- package/components/grid/cell/dragListenerFeature.js.map +1 -1
- package/components/grid/cell/durationCellEditor.d.ts +6 -0
- package/components/grid/cell/durationCellEditor.js +14 -0
- package/components/grid/cell/durationCellEditor.js.map +1 -1
- package/components/grid/cell/hexaOctetStringCellEditor.d.ts +6 -0
- package/components/grid/cell/hexaOctetStringCellEditor.js +14 -0
- package/components/grid/cell/hexaOctetStringCellEditor.js.map +1 -1
- package/components/grid/cell/hexaValueCellEditor.d.ts +6 -0
- package/components/grid/cell/hexaValueCellEditor.js +14 -0
- package/components/grid/cell/hexaValueCellEditor.js.map +1 -1
- package/components/grid/cell/numberCellEditor.d.ts +6 -0
- package/components/grid/cell/numberCellEditor.js +15 -0
- package/components/grid/cell/numberCellEditor.js.map +1 -1
- package/components/grid/cell/rangeSelector.d.ts +7 -0
- package/components/grid/cell/rangeSelector.js +59 -5
- package/components/grid/cell/rangeSelector.js.map +1 -1
- package/components/grid/cell/simpleStatusTextCellEditor.d.ts +7 -0
- package/components/grid/cell/simpleStatusTextCellEditor.js +11 -0
- package/components/grid/cell/simpleStatusTextCellEditor.js.map +1 -1
- package/components/grid/cell/statusTextCellEditor.d.ts +7 -0
- package/components/grid/cell/statusTextCellEditor.js +17 -0
- package/components/grid/cell/statusTextCellEditor.js.map +1 -1
- package/components/grid/cell/tableDefaultRowStyleRules.d.ts +31 -0
- package/components/grid/cell/tableDefaultRowStyleRules.js +5 -0
- package/components/grid/cell/tableDefaultRowStyleRules.js.map +1 -1
- package/components/grid/cell/textCellEditor.d.ts +6 -0
- package/components/grid/cell/textCellEditor.js +15 -0
- package/components/grid/cell/textCellEditor.js.map +1 -1
- package/components/grid/cell/withAgGridHooks.d.ts +8 -0
- package/components/grid/cell/withAgGridHooks.js +8 -0
- package/components/grid/cell/withAgGridHooks.js.map +1 -1
- package/components/grid/columnUtils.d.ts +7 -0
- package/components/grid/columnUtils.js +7 -0
- package/components/grid/columnUtils.js.map +1 -1
- package/components/grid/config/columnTransfer.d.ts +18 -0
- package/components/grid/config/columnTransfer.js +14 -3
- package/components/grid/config/columnTransfer.js.map +1 -1
- package/components/grid/config/dataGridEditor.d.ts +31 -0
- package/components/grid/config/dataGridEditor.js +14 -2
- package/components/grid/config/dataGridEditor.js.map +1 -1
- package/components/grid/config/rowHeightCalculator.d.ts +11 -0
- package/components/grid/config/rowHeightCalculator.js +11 -0
- package/components/grid/config/rowHeightCalculator.js.map +1 -1
- package/components/grid/config/rowStylePicker.d.ts +19 -0
- package/components/grid/config/rowStylePicker.js +12 -0
- package/components/grid/config/rowStylePicker.js.map +1 -1
- package/components/grid/dataGrid.d.ts +331 -0
- package/components/grid/dataGrid.js +168 -11
- package/components/grid/dataGrid.js.map +1 -1
- package/components/grid/detail/detailHeaderPanel.d.ts +11 -0
- package/components/grid/detail/detailHeaderPanel.js +5 -0
- package/components/grid/detail/detailHeaderPanel.js.map +1 -1
- package/components/grid/export/contextMenu.d.ts +31 -0
- package/components/grid/export/contextMenu.js +8 -0
- package/components/grid/export/contextMenu.js.map +1 -1
- package/components/grid/export/progressPopup.d.ts +21 -0
- package/components/grid/export/progressPopup.js +17 -0
- package/components/grid/export/progressPopup.js.map +1 -1
- package/components/grid/export/worker/pdfExport.js +5 -0
- package/components/grid/export/worker/pdfExport.js.map +1 -1
- package/components/grid/extendedDataGrid.d.ts +240 -0
- package/components/grid/extendedDataGrid.js +116 -2
- package/components/grid/extendedDataGrid.js.map +1 -1
- package/components/grid/filter/customColumnFilter.d.ts +5 -0
- package/components/grid/filter/customColumnFilter.js +5 -0
- package/components/grid/filter/customColumnFilter.js.map +1 -1
- package/components/grid/filter/dataGridColumnFilter.d.ts +19 -0
- package/components/grid/filter/dataGridColumnFilter.js +19 -0
- package/components/grid/filter/dataGridColumnFilter.js.map +1 -1
- package/components/grid/filter/dateColumnFilter.d.ts +6 -0
- package/components/grid/filter/dateColumnFilter.js +6 -0
- package/components/grid/filter/dateColumnFilter.js.map +1 -1
- package/components/grid/filter/textColumnFilter.d.ts +6 -0
- package/components/grid/filter/textColumnFilter.js +6 -0
- package/components/grid/filter/textColumnFilter.js.map +1 -1
- package/components/grid/filter/wildcardQuickFilterEngine.d.ts +21 -0
- package/components/grid/filter/wildcardQuickFilterEngine.js +21 -0
- package/components/grid/filter/wildcardQuickFilterEngine.js.map +1 -1
- package/components/grid/header/simpleHeader.d.ts +17 -0
- package/components/grid/header/simpleHeader.js +20 -0
- package/components/grid/header/simpleHeader.js.map +1 -1
- package/components/grid/panel/dataGridPagination.d.ts +10 -0
- package/components/grid/panel/dataGridPagination.js +5 -0
- package/components/grid/panel/dataGridPagination.js.map +1 -1
- package/components/grid/panel/loadingOverlay.d.ts +5 -0
- package/components/grid/panel/loadingOverlay.js +4 -0
- package/components/grid/panel/loadingOverlay.js.map +1 -1
- package/components/grid/panel/noRecordsOverlay.d.ts +6 -0
- package/components/grid/panel/noRecordsOverlay.js +5 -0
- package/components/grid/panel/noRecordsOverlay.js.map +1 -1
- package/components/grid/panel/tablePagination.d.ts +4 -0
- package/components/grid/panel/tablePagination.js +4 -0
- package/components/grid/panel/tablePagination.js.map +1 -1
- package/components/icons/dropdownArrow.d.ts +3 -0
- package/components/icons/dropdownArrow.js +2 -0
- package/components/icons/dropdownArrow.js.map +1 -1
- package/components/icons/undoIcon.d.ts +2 -0
- package/components/icons/undoIcon.js +2 -0
- package/components/icons/undoIcon.js.map +1 -1
- package/components/input/autoCompleteInput.d.ts +29 -0
- package/components/input/autoCompleteInput.js +7 -0
- package/components/input/autoCompleteInput.js.map +1 -1
- package/components/input/draftUtils.d.ts +7 -0
- package/components/input/draftUtils.js +9 -0
- package/components/input/draftUtils.js.map +1 -1
- package/components/input/hexaFormattedInput.d.ts +9 -0
- package/components/input/hexaFormattedInput.js +3 -0
- package/components/input/hexaFormattedInput.js.map +1 -1
- package/components/input/mask/helpers.d.ts +27 -0
- package/components/input/mask/helpers.js +27 -0
- package/components/input/mask/helpers.js.map +1 -1
- package/components/input/mask/inputMaskCore.d.ts +80 -0
- package/components/input/mask/inputMaskCore.js +90 -0
- package/components/input/mask/inputMaskCore.js.map +1 -1
- package/components/input/mask/pattern.d.ts +24 -0
- package/components/input/mask/pattern.js +26 -0
- package/components/input/mask/pattern.js.map +1 -1
- package/components/input/maskedInput.d.ts +53 -0
- package/components/input/maskedInput.js +44 -4
- package/components/input/maskedInput.js.map +1 -1
- package/components/input/passwordInput.d.ts +7 -0
- package/components/input/passwordInput.js +8 -0
- package/components/input/passwordInput.js.map +1 -1
- package/components/input/simpleAutoComplete.d.ts +6 -0
- package/components/input/simpleAutoComplete.js +6 -0
- package/components/input/simpleAutoComplete.js.map +1 -1
- package/components/input/textarea/extractSpansOfClasses.d.ts +17 -0
- package/components/input/textarea/extractSpansOfClasses.js +26 -1
- package/components/input/textarea/extractSpansOfClasses.js.map +1 -1
- package/components/input/textarea/getRanges.d.ts +7 -0
- package/components/input/textarea/getRanges.js +11 -0
- package/components/input/textarea/getRanges.js.map +1 -1
- package/components/input/textarea/getType.d.ts +5 -0
- package/components/input/textarea/getType.js +5 -0
- package/components/input/textarea/getType.js.map +1 -1
- package/components/input/textarea/highlighedContents.d.ts +4 -0
- package/components/input/textarea/highlighedContents.js +5 -0
- package/components/input/textarea/highlighedContents.js.map +1 -1
- package/components/input/textarea/mentionsWithHighlighting.d.ts +25 -0
- package/components/input/textarea/mentionsWithHighlighting.js +14 -0
- package/components/input/textarea/mentionsWithHighlighting.js.map +1 -1
- package/components/keyboard/keyboardUtils.d.ts +6 -0
- package/components/keyboard/keyboardUtils.js +6 -0
- package/components/keyboard/keyboardUtils.js.map +1 -1
- package/components/modal/draggableModalProvider.d.ts +6 -0
- package/components/modal/draggableModalProvider.js +7 -0
- package/components/modal/draggableModalProvider.js.map +1 -1
- package/components/modal/impl/clamp.js +1 -0
- package/components/modal/impl/clamp.js.map +1 -1
- package/components/modal/impl/draggableModal.d.ts +1 -0
- package/components/modal/impl/draggableModal.js +6 -0
- package/components/modal/impl/draggableModal.js.map +1 -1
- package/components/modal/impl/draggableModalContext.js +1 -0
- package/components/modal/impl/draggableModalContext.js.map +1 -1
- package/components/modal/impl/draggableModalInner.js +12 -1
- package/components/modal/impl/draggableModalInner.js.map +1 -1
- package/components/modal/impl/draggableModalReducer.d.ts +7 -1
- package/components/modal/impl/draggableModalReducer.js +6 -1
- package/components/modal/impl/draggableModalReducer.js.map +1 -1
- package/components/modal/impl/draggableModalStyles.d.ts +17 -0
- package/components/modal/impl/draggableModalStyles.js +31 -0
- package/components/modal/impl/draggableModalStyles.js.map +1 -1
- package/components/modal/impl/getWindowSize.js +1 -0
- package/components/modal/impl/getWindowSize.js.map +1 -1
- package/components/modal/impl/index.js +1 -0
- package/components/modal/impl/index.js.map +1 -1
- package/components/modal/impl/resizeHandle.d.ts +1 -0
- package/components/modal/impl/resizeHandle.js +4 -1
- package/components/modal/impl/resizeHandle.js.map +1 -1
- package/components/modal/impl/useDrag.js +1 -0
- package/components/modal/impl/useDrag.js.map +1 -1
- package/components/modal/impl/usePrevious.js +1 -0
- package/components/modal/impl/usePrevious.js.map +1 -1
- package/components/modal/impl/useResize.js +1 -0
- package/components/modal/impl/useResize.js.map +1 -1
- package/components/modal/modalDialog.d.ts +85 -0
- package/components/modal/modalDialog.js +80 -10
- package/components/modal/modalDialog.js.map +1 -1
- package/components/picker/enumValuePicker.d.ts +17 -0
- package/components/picker/enumValuePicker.js +4 -0
- package/components/picker/enumValuePicker.js.map +1 -1
- package/components/platformSpecific.d.ts +17 -0
- package/components/platformSpecific.js +16 -0
- package/components/platformSpecific.js.map +1 -1
- package/components/scrollTo/onlyText.d.ts +5 -0
- package/components/scrollTo/onlyText.js +5 -0
- package/components/scrollTo/onlyText.js.map +1 -1
- package/components/scrollTo/scrollTo.d.ts +56 -0
- package/components/scrollTo/scrollTo.js +40 -3
- package/components/scrollTo/scrollTo.js.map +1 -1
- package/components/style/withCss.d.ts +15 -0
- package/components/style/withCss.js +6 -0
- package/components/style/withCss.js.map +1 -1
- package/components/table/dragSortingTable.d.ts +15 -0
- package/components/table/dragSortingTable.js +12 -0
- package/components/table/dragSortingTable.js.map +1 -1
- package/components/text/impl/innerSize.js +2 -0
- package/components/text/impl/innerSize.js.map +1 -1
- package/components/text/impl/series.d.ts +10 -0
- package/components/text/impl/series.js +10 -0
- package/components/text/impl/series.js.map +1 -1
- package/components/text/impl/shallowEqual.js +1 -0
- package/components/text/impl/shallowEqual.js.map +1 -1
- package/components/text/impl/whilst.d.ts +7 -0
- package/components/text/impl/whilst.js +7 -0
- package/components/text/impl/whilst.js.map +1 -1
- package/components/text/textFit.d.ts +24 -0
- package/components/text/textFit.js +29 -1
- package/components/text/textFit.js.map +1 -1
- package/i18n/componentsLocaleHolder.d.ts +9 -0
- package/i18n/componentsLocaleHolder.js +9 -0
- package/i18n/componentsLocaleHolder.js.map +1 -1
- package/package.json +66 -65
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
import { DEFAULT_FORMAT_CHARACTERS, DEFAULT_PLACEHOLDER_CHAR, ESCAPE_CHAR, } 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 class Pattern {
|
|
3
8
|
constructor(source, formatCharacters, placeholderChar, isRevealingMask = false) {
|
|
9
|
+
/** Pattern characters after escape characters have been processed. */
|
|
4
10
|
this.pattern = [];
|
|
11
|
+
/** Length of the pattern after escape characters have been processed. */
|
|
5
12
|
this.length = 0;
|
|
13
|
+
/** Index of the first editable character. */
|
|
6
14
|
this.firstEditableIndex = null;
|
|
15
|
+
/** Index of the last editable character. */
|
|
7
16
|
this.lastEditableIndex = null;
|
|
17
|
+
/** Lookup for indices of editable characters in the pattern. */
|
|
8
18
|
this._editableIndices = {};
|
|
19
|
+
/** Placeholder character */
|
|
9
20
|
this.placeholderChar = placeholderChar || DEFAULT_PLACEHOLDER_CHAR;
|
|
21
|
+
/** Format character definitions. */
|
|
10
22
|
this.formatCharacters = formatCharacters || DEFAULT_FORMAT_CHARACTERS;
|
|
23
|
+
/** Pattern definition string with escape characters. */
|
|
11
24
|
this.source = source;
|
|
12
25
|
this.isRevealingMask = isRevealingMask;
|
|
13
26
|
this._parse();
|
|
14
27
|
}
|
|
28
|
+
/** Internal: parses {@link Pattern.source}; called by the constructor. */
|
|
15
29
|
_parse() {
|
|
16
30
|
var sourceChars = this.source.split('');
|
|
17
31
|
var patternIndex = 0;
|
|
@@ -37,9 +51,16 @@ export class Pattern {
|
|
|
37
51
|
if (this.firstEditableIndex === null) {
|
|
38
52
|
throw new Error('InputMask: pattern "' + this.source + '" does not contain any editable characters.');
|
|
39
53
|
}
|
|
54
|
+
// @ts-ignore
|
|
40
55
|
this.pattern = pattern;
|
|
41
56
|
this.length = pattern.length;
|
|
42
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Lays the characters of `value` into the pattern: literals are inserted (and skipped in `value` when it already
|
|
60
|
+
* contains them), valid characters are transformed and invalid ones replaced by the placeholder.
|
|
61
|
+
* @returns one entry per pattern position; for a revealing mask the entries after the entered characters stay
|
|
62
|
+
* `undefined`.
|
|
63
|
+
*/
|
|
43
64
|
formatValue(value) {
|
|
44
65
|
var valueBuffer = new Array(this.length);
|
|
45
66
|
var valueIndex = 0;
|
|
@@ -58,6 +79,8 @@ export class Pattern {
|
|
|
58
79
|
}
|
|
59
80
|
else {
|
|
60
81
|
valueBuffer[i] = this.pattern[i];
|
|
82
|
+
// Also allow the value to contain static values from the pattern by
|
|
83
|
+
// advancing its index.
|
|
61
84
|
if (value.length > valueIndex && value[valueIndex] === this.pattern[i]) {
|
|
62
85
|
valueIndex++;
|
|
63
86
|
}
|
|
@@ -65,12 +88,15 @@ export class Pattern {
|
|
|
65
88
|
}
|
|
66
89
|
return valueBuffer;
|
|
67
90
|
}
|
|
91
|
+
/** Whether the position holds a format character. */
|
|
68
92
|
isEditableIndex(index) {
|
|
69
93
|
return !!this._editableIndices[index];
|
|
70
94
|
}
|
|
95
|
+
/** Whether `char` is accepted at the editable position `index`. */
|
|
71
96
|
isValidAtIndex(char, index) {
|
|
72
97
|
return this.formatCharacters[this.pattern[index]].validate(char);
|
|
73
98
|
}
|
|
99
|
+
/** Applies the format character's `transform` at `index`, if it defines one. */
|
|
74
100
|
transform(char, index) {
|
|
75
101
|
var format = this.formatCharacters[this.pattern[index]];
|
|
76
102
|
return typeof format.transform == 'function' ? format.transform(char) : char;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pattern.js","sourceRoot":"","sources":["../../../../../components/input/mask/pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,yBAAyB,EAAE,wBAAwB,EAAE,WAAW,GAAoB,MAAM,WAAW,CAAC;AAE9G,MAAM,OAAO,OAAO;
|
|
1
|
+
{"version":3,"file":"pattern.js","sourceRoot":"","sources":["../../../../../components/input/mask/pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,yBAAyB,EAAE,wBAAwB,EAAE,WAAW,GAAoB,MAAM,WAAW,CAAC;AAE9G;;;;GAIG;AACH,MAAM,OAAO,OAAO;IA0BhB,YACI,MAAc,EACd,gBAAkC,EAClC,eAAuB,EACvB,eAAe,GAAG,KAAK;QAtB3B,sEAAsE;QACtE,YAAO,GAAG,EAAE,CAAC;QAEb,yEAAyE;QACzE,WAAM,GAAG,CAAC,CAAC;QAEX,6CAA6C;QAC7C,uBAAkB,GAAkB,IAAI,CAAC;QAEzC,4CAA4C;QAC5C,sBAAiB,GAAkB,IAAI,CAAC;QAExC,gEAAgE;QAChE,qBAAgB,GAA+B,EAAE,CAAC;QAW9C,4BAA4B;QAC5B,IAAI,CAAC,eAAe,GAAG,eAAe,IAAI,wBAAwB,CAAC;QACnE,oCAAoC;QACpC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,IAAI,yBAAyB,CAAC;QACtE,wDAAwD;QACxD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QAEvC,IAAI,CAAC,MAAM,EAAE,CAAC;IAClB,CAAC;IAED,0EAA0E;IAC1E,MAAM;QACF,IAAI,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACxC,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,IAAI,OAAO,GAAa,EAAE,C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AI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;IAED,gFAAgF;IAChF,SAAS,CAAC,IAAY,EAAE,KAAa;QACjC,IAAI,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACxD,OAAO,OAAO,MAAM,CAAC,SAAS,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjF,CAAC;CACJ","sourcesContent":["import {DEFAULT_FORMAT_CHARACTERS, DEFAULT_PLACEHOLDER_CHAR, ESCAPE_CHAR, FormatCharacters,} from './helpers';\r\n\r\n/**\r\n * Parsed mask pattern. Characters listed in `formatCharacters` mark editable positions, every other character is a\r\n * literal, and {@link ESCAPE_CHAR} turns the next character into a literal.\r\n * @throws Error when the source ends with a bare escape character or contains no editable position.\r\n */\r\nexport class Pattern {\r\n /** Character used for unfilled editable positions. */\r\n placeholderChar: string;\r\n /** Format character definitions. */\r\n formatCharacters: FormatCharacters;\r\n /** Pattern definition string, including escape characters. */\r\n source: string;\r\n\r\n /** Pattern characters after escape characters have been processed. */\r\n pattern = [];\r\n\r\n /** Length of the pattern after escape characters have been processed. */\r\n length = 0;\r\n\r\n /** Index of the first editable character. */\r\n firstEditableIndex: null | number = null;\r\n\r\n /** Index of the last editable character. */\r\n lastEditableIndex: null | number = null;\r\n\r\n /** Lookup for indices of editable characters in the pattern. */\r\n _editableIndices: { [key: number]: boolean } = {};\r\n\r\n /** If true, only the pattern before the last valid value character shows. */\r\n isRevealingMask: boolean;\r\n\r\n constructor(\r\n source: string,\r\n formatCharacters: FormatCharacters,\r\n placeholderChar: string,\r\n isRevealingMask = false,\r\n ) {\r\n /** Placeholder character */\r\n this.placeholderChar = placeholderChar || DEFAULT_PLACEHOLDER_CHAR;\r\n /** Format character definitions. */\r\n this.formatCharacters = formatCharacters || DEFAULT_FORMAT_CHARACTERS;\r\n /** Pattern definition string with escape characters. */\r\n this.source = source;\r\n\r\n this.isRevealingMask = isRevealingMask;\r\n\r\n this._parse();\r\n }\r\n\r\n /** Internal: parses {@link Pattern.source}; called by the constructor. */\r\n _parse() {\r\n var sourceChars = this.source.split('');\r\n var patternIndex = 0;\r\n var pattern: string[] = [];\r\n\r\n for (var i = 0, l = sourceChars.length; i < l; i++) {\r\n var char = sourceChars[i];\r\n if (char === ESCAPE_CHAR) {\r\n if (i === l - 1) {\r\n throw new Error('InputMask: pattern ends with a raw ' + ESCAPE_CHAR);\r\n }\r\n char = sourceChars[++i];\r\n } else if (char in this.formatCharacters) {\r\n if (this.firstEditableIndex === null) {\r\n this.firstEditableIndex = patternIndex;\r\n }\r\n this.lastEditableIndex = patternIndex;\r\n this._editableIndices[patternIndex] = true;\r\n }\r\n\r\n pattern.push(char);\r\n patternIndex++;\r\n }\r\n\r\n if (this.firstEditableIndex === null) {\r\n throw new Error(\r\n 'InputMask: pattern \"' + this.source + '\" does not contain any editable characters.',\r\n );\r\n }\r\n\r\n // @ts-ignore\r\n this.pattern = pattern;\r\n this.length = pattern.length;\r\n }\r\n\r\n /**\r\n * Lays the characters of `value` into the pattern: literals are inserted (and skipped in `value` when it already\r\n * contains them), valid characters are transformed and invalid ones replaced by the placeholder.\r\n * @returns one entry per pattern position; for a revealing mask the entries after the entered characters stay\r\n * `undefined`.\r\n */\r\n formatValue(value: string[]): string[] {\r\n var valueBuffer = new Array(this.length);\r\n var valueIndex = 0;\r\n\r\n for (var i = 0, l = this.length; i < l; i++) {\r\n if (this.isEditableIndex(i)) {\r\n if (\r\n this.isRevealingMask &&\r\n value.length <= valueIndex &&\r\n !this.isValidAtIndex(value[valueIndex], i)\r\n ) {\r\n break;\r\n }\r\n valueBuffer[i] =\r\n value.length > valueIndex && this.isValidAtIndex(value[valueIndex], i)\r\n ? this.transform(value[valueIndex], i)\r\n : this.placeholderChar;\r\n valueIndex++;\r\n } else {\r\n valueBuffer[i] = this.pattern[i];\r\n // Also allow the value to contain static values from the pattern by\r\n // advancing its index.\r\n if (value.length > valueIndex && value[valueIndex] === this.pattern[i]) {\r\n valueIndex++;\r\n }\r\n }\r\n }\r\n\r\n return valueBuffer;\r\n }\r\n\r\n /** Whether the position holds a format character. */\r\n isEditableIndex(index: number) {\r\n return !!this._editableIndices[index];\r\n }\r\n\r\n /** Whether `char` is accepted at the editable position `index`. */\r\n isValidAtIndex(char: string, index: number) {\r\n return this.formatCharacters[this.pattern[index]].validate(char);\r\n }\r\n\r\n /** Applies the format character's `transform` at `index`, if it defines one. */\r\n transform(char: string, index: number) {\r\n var format = this.formatCharacters[this.pattern[index]];\r\n return typeof format.transform == 'function' ? format.transform(char) : char;\r\n }\r\n}"]}
|
|
@@ -2,34 +2,80 @@ import React, { ChangeEvent, ClipboardEvent, Component, KeyboardEvent } from 're
|
|
|
2
2
|
import { InputRef } from 'antd';
|
|
3
3
|
import InputMask from 'd2coreui/components/input/mask/inputMaskCore';
|
|
4
4
|
import { InputProps } from 'antd/lib/input';
|
|
5
|
+
/**
|
|
6
|
+
* Props of {@link MaskedInput}: all antd `Input` props plus the mask settings. `maxLength` is always replaced by
|
|
7
|
+
* the mask length and `placeholder` defaults to the empty mask (e.g. `__.__.____`).
|
|
8
|
+
*/
|
|
5
9
|
export type MaskedInputProps = InputProps & {
|
|
10
|
+
/**
|
|
11
|
+
* Mask pattern. Format characters mark editable positions: `1` digit, `a` letter, `A` letter (upper-cased),
|
|
12
|
+
* `*` alphanumeric, `#` alphanumeric (upper-cased). Every other character is a literal that is inserted
|
|
13
|
+
* automatically; prefix a format character with `\` to make it literal. The pattern may change at any time,
|
|
14
|
+
* the entered characters are kept.
|
|
15
|
+
*/
|
|
6
16
|
mask: string;
|
|
17
|
+
/**
|
|
18
|
+
* Custom format characters (a `FormatCharacters` map from `mask/helpers`), merged over
|
|
19
|
+
* `DEFAULT_FORMAT_CHARACTERS`; a `null` entry removes a default. Read only on construction.
|
|
20
|
+
*/
|
|
7
21
|
formatCharacters?: object;
|
|
22
|
+
/**
|
|
23
|
+
* Single character shown in unfilled editable positions. Read only on construction.
|
|
24
|
+
* @default "_"
|
|
25
|
+
*/
|
|
8
26
|
placeholderChar?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Controlled value; whenever it changes it is formatted into the mask (invalid characters become placeholders).
|
|
29
|
+
* Without it the input is uncontrolled and a string `defaultValue` is applied once on mount.
|
|
30
|
+
*/
|
|
9
31
|
value?: string;
|
|
10
32
|
};
|
|
11
33
|
type TChangeEvent = ChangeEvent<HTMLInputElement>;
|
|
12
34
|
type TKeyboardEvent = KeyboardEvent<HTMLInputElement> & InputEvent;
|
|
13
35
|
type TClipboardEvent = ClipboardEvent<any>;
|
|
36
|
+
/**
|
|
37
|
+
* antd `Input` that restricts typing, Backspace and paste to a fixed pattern (see {@link MaskedInputProps.mask})
|
|
38
|
+
* and supports undo/redo (Ctrl+Z, Ctrl+Y / Ctrl+Shift+Z). `onChange` fires after every accepted edit, but the
|
|
39
|
+
* event may be a change, keyboard or clipboard event - read only `event.target.value`, which holds the formatted
|
|
40
|
+
* text with placeholder characters in the unfilled positions.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // "1" is a format character, so the literal "1" of the prefix has to be escaped
|
|
44
|
+
* <MaskedInput mask={"+42\\1 111 111 111"}
|
|
45
|
+
* value={phone}
|
|
46
|
+
* onChange={e => setPhone(e.target.value)}/>
|
|
47
|
+
*/
|
|
14
48
|
export default class MaskedInput extends Component<MaskedInputProps, {
|
|
15
49
|
value?: string;
|
|
16
50
|
}> {
|
|
51
|
+
/** The mask engine holding the current value, selection and undo history. */
|
|
17
52
|
mask: InputMask;
|
|
53
|
+
/** The underlying DOM input element; assigned on mount. */
|
|
18
54
|
input: HTMLInputElement;
|
|
19
55
|
constructor(props: MaskedInputProps);
|
|
20
56
|
componentDidMount(): void;
|
|
21
57
|
UNSAFE_componentWillReceiveProps(nextProps: MaskedInputProps): void;
|
|
22
58
|
UNSAFE_componentWillUpdate(nextProps: MaskedInputProps): null | undefined;
|
|
23
59
|
componentDidUpdate(prevProps: MaskedInputProps): null | undefined;
|
|
60
|
+
/** Internal: applies the mask of `props`, keeping the raw value and the input selection. */
|
|
24
61
|
_updatePattern(props: MaskedInputProps): void;
|
|
62
|
+
/** Internal: copies the input selection into the mask. */
|
|
25
63
|
_updateMaskSelection(): void;
|
|
64
|
+
/** Internal: applies the mask selection to the input. */
|
|
26
65
|
_updateInputSelection(): void;
|
|
66
|
+
/** Internal `change` handler: reformats changed text through the mask, then calls `onChange`. */
|
|
27
67
|
_onChange: (e: TChangeEvent) => void;
|
|
68
|
+
/** Internal `keydown` handler: undo/redo and Backspace. */
|
|
28
69
|
_onKeyDown: (e: TKeyboardEvent) => void;
|
|
70
|
+
/** Internal `keypress` (`beforeinput` on Android) handler: feeds typed characters into the mask; modified keys and Enter pass through. */
|
|
29
71
|
_onKeyPress: (e: TKeyboardEvent) => void;
|
|
72
|
+
/** Internal `paste` handler: pastes clipboard text through the mask; a paste with invalid content is rejected as a whole. */
|
|
30
73
|
_onPaste: (e: TClipboardEvent) => void;
|
|
74
|
+
/** Internal: the formatted value, or an empty string when nothing has been entered. */
|
|
31
75
|
_getDisplayValue(): string;
|
|
76
|
+
/** Internal: name of the event prop used for character input (`onBeforeInput` on Android, `onKeyPress` elsewhere). */
|
|
32
77
|
_keyPressPropName(): "onBeforeInput" | "onKeyPress";
|
|
78
|
+
/** Internal: the event handlers passed to the antd `Input`. */
|
|
33
79
|
_getEventHandlers(): {
|
|
34
80
|
onChange: (e: TChangeEvent) => void;
|
|
35
81
|
onKeyDown: (e: TKeyboardEvent) => void;
|
|
@@ -37,8 +83,11 @@ export default class MaskedInput extends Component<MaskedInputProps, {
|
|
|
37
83
|
onBeforeInput?: (e: TChangeEvent) => void;
|
|
38
84
|
onKeyPress?: (e: TKeyboardEvent) => void;
|
|
39
85
|
};
|
|
86
|
+
/** Moves the keyboard focus to the input. */
|
|
40
87
|
focus(): void;
|
|
88
|
+
/** Removes the keyboard focus from the input. */
|
|
41
89
|
blur(): void;
|
|
90
|
+
/** Props passed to the antd `Input`: own props without the mask settings and `value`, plus the mask handlers, `maxLength` and `placeholder`. */
|
|
42
91
|
getInputProps: () => {
|
|
43
92
|
maxLength: number;
|
|
44
93
|
placeholder: string;
|
|
@@ -359,9 +408,13 @@ export default class MaskedInput extends Component<MaskedInputProps, {
|
|
|
359
408
|
};
|
|
360
409
|
mask: string;
|
|
361
410
|
};
|
|
411
|
+
/** Internal: last value written to the input, `null` before the first write. */
|
|
362
412
|
_lastValue: any;
|
|
413
|
+
/** Writes `value` directly to the DOM input and to the component state; ignored before mount and when unchanged. */
|
|
363
414
|
setInputValue: (value: string) => void;
|
|
415
|
+
/** Internal: the antd `Input` ref. */
|
|
364
416
|
_Input: InputRef | null;
|
|
417
|
+
/** Ref callback of the antd `Input`; on first attach applies a string `defaultValue`. */
|
|
365
418
|
handleInputRef: (ref: InputRef) => void;
|
|
366
419
|
render(): React.JSX.Element;
|
|
367
420
|
}
|
|
@@ -13,22 +13,37 @@ import React, { Component } from 'react';
|
|
|
13
13
|
import { Input } from 'antd';
|
|
14
14
|
import InputMask from 'd2coreui/components/input/mask/inputMaskCore';
|
|
15
15
|
import { getSelection, isRedo, isUndo, setSelection } from 'd2coreui/components/input/mask/helpers';
|
|
16
|
+
/**
|
|
17
|
+
* antd `Input` that restricts typing, Backspace and paste to a fixed pattern (see {@link MaskedInputProps.mask})
|
|
18
|
+
* and supports undo/redo (Ctrl+Z, Ctrl+Y / Ctrl+Shift+Z). `onChange` fires after every accepted edit, but the
|
|
19
|
+
* event may be a change, keyboard or clipboard event - read only `event.target.value`, which holds the formatted
|
|
20
|
+
* text with placeholder characters in the unfilled positions.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // "1" is a format character, so the literal "1" of the prefix has to be escaped
|
|
24
|
+
* <MaskedInput mask={"+42\\1 111 111 111"}
|
|
25
|
+
* value={phone}
|
|
26
|
+
* onChange={e => setPhone(e.target.value)}/>
|
|
27
|
+
*/
|
|
16
28
|
export default class MaskedInput extends Component {
|
|
17
29
|
constructor(props) {
|
|
18
30
|
super(props);
|
|
31
|
+
/** Internal `change` handler: reformats changed text through the mask, then calls `onChange`. */
|
|
19
32
|
this._onChange = (e) => {
|
|
20
33
|
let maskValue = this.mask.getValue();
|
|
21
34
|
let incomingValue = e.target.value;
|
|
22
35
|
if (incomingValue !== maskValue) {
|
|
36
|
+
// only modify mask if form contents actually changed
|
|
23
37
|
this._updateMaskSelection();
|
|
24
|
-
this.mask.setValue(incomingValue);
|
|
25
|
-
this.setInputValue(this._getDisplayValue());
|
|
38
|
+
this.mask.setValue(incomingValue); // write the whole updated value into the mask
|
|
39
|
+
this.setInputValue(this._getDisplayValue()); // update the form with pattern applied to the value
|
|
26
40
|
this._updateInputSelection();
|
|
27
41
|
}
|
|
28
42
|
if (this.props.onChange) {
|
|
29
43
|
this.props.onChange(e);
|
|
30
44
|
}
|
|
31
45
|
};
|
|
46
|
+
/** Internal `keydown` handler: undo/redo and Backspace. */
|
|
32
47
|
this._onKeyDown = (e) => {
|
|
33
48
|
setTimeout(() => {
|
|
34
49
|
this.input.classList[this.input.value ? 'add' : 'remove']('has-value');
|
|
@@ -70,7 +85,10 @@ export default class MaskedInput extends Component {
|
|
|
70
85
|
}
|
|
71
86
|
}
|
|
72
87
|
};
|
|
88
|
+
/** Internal `keypress` (`beforeinput` on Android) handler: feeds typed characters into the mask; modified keys and Enter pass through. */
|
|
73
89
|
this._onKeyPress = (e) => {
|
|
90
|
+
// Ignore modified key presses
|
|
91
|
+
// Ignore enter key to allow form submission
|
|
74
92
|
if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') {
|
|
75
93
|
return;
|
|
76
94
|
}
|
|
@@ -84,17 +102,23 @@ export default class MaskedInput extends Component {
|
|
|
84
102
|
}
|
|
85
103
|
}
|
|
86
104
|
};
|
|
105
|
+
/** Internal `paste` handler: pastes clipboard text through the mask; a paste with invalid content is rejected as a whole. */
|
|
87
106
|
this._onPaste = (e) => {
|
|
88
107
|
e.preventDefault();
|
|
89
108
|
this._updateMaskSelection();
|
|
109
|
+
// getData value needed for IE also works in FF & Chrome
|
|
90
110
|
if (this.mask.paste(e.clipboardData.getData('Text'))) {
|
|
111
|
+
// @ts-ignore
|
|
91
112
|
this.setInputValue(this.mask.getValue());
|
|
113
|
+
// Timeout needed for IE
|
|
92
114
|
setTimeout(() => this._updateInputSelection(), 0);
|
|
93
115
|
if (this.props.onChange) {
|
|
116
|
+
// @ts-ignore
|
|
94
117
|
this.props.onChange(e);
|
|
95
118
|
}
|
|
96
119
|
}
|
|
97
120
|
};
|
|
121
|
+
/** Props passed to the antd `Input`: own props without the mask settings and `value`, plus the mask handlers, `maxLength` and `placeholder`. */
|
|
98
122
|
this.getInputProps = () => {
|
|
99
123
|
let maxLength = this.mask.pattern.length;
|
|
100
124
|
let eventHandlers = this._getEventHandlers();
|
|
@@ -104,7 +128,9 @@ export default class MaskedInput extends Component {
|
|
|
104
128
|
delete props.value;
|
|
105
129
|
return props;
|
|
106
130
|
};
|
|
131
|
+
/** Internal: last value written to the input, `null` before the first write. */
|
|
107
132
|
this._lastValue = null;
|
|
133
|
+
/** Writes `value` directly to the DOM input and to the component state; ignored before mount and when unchanged. */
|
|
108
134
|
this.setInputValue = (value) => {
|
|
109
135
|
if (!this._Input)
|
|
110
136
|
return;
|
|
@@ -116,7 +142,9 @@ export default class MaskedInput extends Component {
|
|
|
116
142
|
this._Input.input.value = value;
|
|
117
143
|
}
|
|
118
144
|
};
|
|
145
|
+
/** Internal: the antd `Input` ref. */
|
|
119
146
|
this._Input = null;
|
|
147
|
+
/** Ref callback of the antd `Input`; on first attach applies a string `defaultValue`. */
|
|
120
148
|
this.handleInputRef = (ref) => {
|
|
121
149
|
if (!ref || !ref.input)
|
|
122
150
|
return;
|
|
@@ -124,8 +152,8 @@ export default class MaskedInput extends Component {
|
|
|
124
152
|
this.input = ref.input;
|
|
125
153
|
if (this._lastValue === null &&
|
|
126
154
|
typeof this.props.defaultValue === 'string') {
|
|
127
|
-
this.mask.setValue(this.props.defaultValue);
|
|
128
|
-
this.setInputValue(this._getDisplayValue());
|
|
155
|
+
this.mask.setValue(this.props.defaultValue); // write the whole updated value into the mask
|
|
156
|
+
this.setInputValue(this._getDisplayValue()); // update the form with pattern applied to the value
|
|
129
157
|
}
|
|
130
158
|
};
|
|
131
159
|
this.state = {
|
|
@@ -147,6 +175,10 @@ export default class MaskedInput extends Component {
|
|
|
147
175
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
148
176
|
if (this.props.mask !== nextProps.mask &&
|
|
149
177
|
this.props.value !== nextProps.mask) {
|
|
178
|
+
// if we get a new value and a new mask at the same time
|
|
179
|
+
// check if the mask.value is still the initial value
|
|
180
|
+
// - if so use the nextProps value
|
|
181
|
+
// - otherwise the `this.mask` has a value for us (most likely from paste action)
|
|
150
182
|
if (this.mask.getValue() === this.mask.emptyValue) {
|
|
151
183
|
this.mask.setPattern(nextProps.mask, { value: nextProps.value });
|
|
152
184
|
}
|
|
@@ -180,22 +212,27 @@ export default class MaskedInput extends Component {
|
|
|
180
212
|
}
|
|
181
213
|
return;
|
|
182
214
|
}
|
|
215
|
+
/** Internal: applies the mask of `props`, keeping the raw value and the input selection. */
|
|
183
216
|
_updatePattern(props) {
|
|
184
217
|
this.mask.setPattern(props.mask, {
|
|
185
218
|
value: this.mask.getRawValue(),
|
|
186
219
|
selection: getSelection(this.input)
|
|
187
220
|
});
|
|
188
221
|
}
|
|
222
|
+
/** Internal: copies the input selection into the mask. */
|
|
189
223
|
_updateMaskSelection() {
|
|
190
224
|
this.mask.selection = getSelection(this.input);
|
|
191
225
|
}
|
|
226
|
+
/** Internal: applies the mask selection to the input. */
|
|
192
227
|
_updateInputSelection() {
|
|
193
228
|
setSelection(this.input, this.mask.selection);
|
|
194
229
|
}
|
|
230
|
+
/** Internal: the formatted value, or an empty string when nothing has been entered. */
|
|
195
231
|
_getDisplayValue() {
|
|
196
232
|
let value = this.mask.getValue();
|
|
197
233
|
return value === this.mask.emptyValue ? '' : value;
|
|
198
234
|
}
|
|
235
|
+
/** Internal: name of the event prop used for character input (`onBeforeInput` on Android, `onKeyPress` elsewhere). */
|
|
199
236
|
_keyPressPropName() {
|
|
200
237
|
if (typeof navigator !== 'undefined') {
|
|
201
238
|
return navigator.userAgent.match(/Android/i)
|
|
@@ -204,6 +241,7 @@ export default class MaskedInput extends Component {
|
|
|
204
241
|
}
|
|
205
242
|
return 'onKeyPress';
|
|
206
243
|
}
|
|
244
|
+
/** Internal: the event handlers passed to the antd `Input`. */
|
|
207
245
|
_getEventHandlers() {
|
|
208
246
|
return {
|
|
209
247
|
onChange: this._onChange,
|
|
@@ -212,9 +250,11 @@ export default class MaskedInput extends Component {
|
|
|
212
250
|
[this._keyPressPropName()]: this._onKeyPress
|
|
213
251
|
};
|
|
214
252
|
}
|
|
253
|
+
/** Moves the keyboard focus to the input. */
|
|
215
254
|
focus() {
|
|
216
255
|
this.input.focus();
|
|
217
256
|
}
|
|
257
|
+
/** Removes the keyboard focus from the input. */
|
|
218
258
|
blur() {
|
|
219
259
|
this.input.blur();
|
|
220
260
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maskedInput.js","sourceRoot":"","sources":["../../../../components/input/maskedInput.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAA8B,SAAS,EAAgB,MAAM,OAAO,CAAC;AACnF,OAAO,EAAC,KAAK,EAAW,MAAM,MAAM,CAAC;AACrC,OAAO,SAAS,MAAM,8CAA8C,CAAC;AACrE,OAAO,EAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAC,MAAM,wCAAwC,CAAC;AAclG,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,SAA6C;IAIlF,YAAY,KAAuB;QAC/B,KAAK,CAAC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AAC;IACjG,CAAC;CACJ","sourcesContent":["import React, {ChangeEvent, ClipboardEvent, Component, KeyboardEvent} from 'react';\r\nimport {Input, InputRef} from 'antd';\r\nimport InputMask from 'd2coreui/components/input/mask/inputMaskCore';\r\nimport {getSelection, isRedo, isUndo, setSelection} from 'd2coreui/components/input/mask/helpers';\r\nimport {InputProps} from 'antd/lib/input';\r\n\r\nexport type MaskedInputProps = InputProps & {\r\n mask: string;\r\n formatCharacters?: object;\r\n placeholderChar?: string;\r\n value?: string;\r\n};\r\n\r\ntype TChangeEvent = ChangeEvent<HTMLInputElement>;\r\ntype TKeyboardEvent = KeyboardEvent<HTMLInputElement> & InputEvent; // on mobile devices InputEvent is called\r\ntype TClipboardEvent = ClipboardEvent<any>;\r\n\r\nexport default class MaskedInput extends Component<MaskedInputProps, {value?: string}> {\r\n mask: InputMask;\r\n input!: HTMLInputElement;\r\n\r\n constructor(props: MaskedInputProps) {\r\n super(props);\r\n\r\n this.state = {\r\n value: this.props.value,\r\n }\r\n\r\n let options: any = {\r\n pattern: this.props.mask,\r\n value: this.props.value,\r\n formatCharacters: this.props.formatCharacters\r\n };\r\n\r\n if (this.props.placeholderChar) {\r\n options.placeholderChar = this.props.placeholderChar;\r\n }\r\n\r\n this.mask = new InputMask(options);\r\n }\r\n\r\n componentDidMount() {\r\n this.setInputValue(this._getDisplayValue());\r\n }\r\n\r\n UNSAFE_componentWillReceiveProps(nextProps: MaskedInputProps) {\r\n if (\r\n this.props.mask !== nextProps.mask &&\r\n this.props.value !== nextProps.mask\r\n ) {\r\n // if we get a new value and a new mask at the same time\r\n // check if the mask.value is still the initial value\r\n // - if so use the nextProps value\r\n // - otherwise the `this.mask` has a value for us (most likely from paste action)\r\n if (this.mask.getValue() === this.mask.emptyValue) {\r\n this.mask.setPattern(nextProps.mask, {value: nextProps.value});\r\n } else {\r\n this.mask.setPattern(nextProps.mask, {\r\n value: this.mask.getRawValue()\r\n });\r\n }\r\n } else if (this.props.mask !== nextProps.mask) {\r\n this.mask.setPattern(nextProps.mask, {value: this.mask.getRawValue()});\r\n }\r\n\r\n if (this.props.value !== nextProps.value) {\r\n this.mask.setValue(nextProps.value);\r\n this.setInputValue(this._getDisplayValue());\r\n }\r\n }\r\n\r\n UNSAFE_componentWillUpdate(nextProps: MaskedInputProps) {\r\n if (!this.props.mask) return null;\r\n if (nextProps.mask !== this.props.mask) {\r\n this._updatePattern(nextProps);\r\n }\r\n return;\r\n }\r\n\r\n componentDidUpdate(prevProps: MaskedInputProps) {\r\n if (!this.props.mask) return null;\r\n if (prevProps.mask !== this.props.mask && this.mask.selection.start) {\r\n this._updateInputSelection();\r\n }\r\n return;\r\n }\r\n\r\n _updatePattern(props: MaskedInputProps) {\r\n this.mask.setPattern(props.mask, {\r\n value: this.mask.getRawValue(),\r\n selection: getSelection(this.input)\r\n });\r\n }\r\n\r\n _updateMaskSelection() {\r\n this.mask.selection = getSelection(this.input);\r\n }\r\n\r\n _updateInputSelection() {\r\n setSelection(this.input, this.mask.selection);\r\n }\r\n\r\n _onChange = (e: TChangeEvent) => {\r\n let maskValue = this.mask.getValue();\r\n let incomingValue = e.target.value;\r\n if (incomingValue !== maskValue) {\r\n // only modify mask if form contents actually changed\r\n this._updateMaskSelection();\r\n this.mask.setValue(incomingValue); // write the whole updated value into the mask\r\n this.setInputValue(this._getDisplayValue()); // update the form with pattern applied to the value\r\n this._updateInputSelection();\r\n }\r\n\r\n if (this.props.onChange) {\r\n this.props.onChange(e);\r\n }\r\n };\r\n\r\n _onKeyDown = (e: TKeyboardEvent) => {\r\n setTimeout(() => {\r\n this.input.classList[this.input.value ? 'add' : 'remove']('has-value');\r\n }, 100);\r\n\r\n if (isUndo(e)) {\r\n e.preventDefault();\r\n if (this.mask.undo()) {\r\n this.setInputValue(this._getDisplayValue());\r\n this._updateInputSelection();\r\n if (this.props.onChange) {\r\n this.props.onChange(e as unknown as TChangeEvent);\r\n }\r\n }\r\n return;\r\n } else if (isRedo(e)) {\r\n e.preventDefault();\r\n if (this.mask.redo()) {\r\n this.setInputValue(this._getDisplayValue());\r\n this._updateInputSelection();\r\n if (this.props.onChange) {\r\n this.props.onChange(e as unknown as TChangeEvent);\r\n }\r\n }\r\n return;\r\n }\r\n\r\n if (e.key === 'Backspace') {\r\n e.preventDefault();\r\n this._updateMaskSelection();\r\n if (this.mask.backspace()) {\r\n let value = this._getDisplayValue();\r\n this.setInputValue(value);\r\n if (value) {\r\n this._updateInputSelection();\r\n }\r\n if (this.props.onChange) {\r\n this.props.onChange(e as unknown as TChangeEvent);\r\n }\r\n }\r\n }\r\n };\r\n\r\n _onKeyPress = (e: TKeyboardEvent) => {\r\n // Ignore modified key presses\r\n // Ignore enter key to allow form submission\r\n if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') {\r\n return;\r\n }\r\n\r\n e.preventDefault();\r\n this._updateMaskSelection();\r\n if (this.mask.input(e.key || e.data as string)) {\r\n this.setInputValue(this.mask.getValue());\r\n this._updateInputSelection();\r\n if (this.props.onChange) {\r\n this.props.onChange(e as unknown as TChangeEvent);\r\n }\r\n }\r\n };\r\n\r\n _onPaste = (e: TClipboardEvent) => {\r\n e.preventDefault();\r\n this._updateMaskSelection();\r\n // getData value needed for IE also works in FF & Chrome\r\n if (this.mask.paste(e.clipboardData.getData('Text'))) {\r\n // @ts-ignore\r\n this.setInputValue(this.mask.getValue());\r\n // Timeout needed for IE\r\n setTimeout(() => this._updateInputSelection(), 0);\r\n if (this.props.onChange) {\r\n // @ts-ignore\r\n this.props.onChange(e);\r\n }\r\n }\r\n };\r\n\r\n _getDisplayValue() {\r\n let value = this.mask.getValue();\r\n return value === this.mask.emptyValue ? '' : value;\r\n }\r\n\r\n _keyPressPropName() {\r\n if (typeof navigator !== 'undefined') {\r\n return navigator.userAgent.match(/Android/i)\r\n ? 'onBeforeInput'\r\n : 'onKeyPress';\r\n }\r\n return 'onKeyPress';\r\n }\r\n\r\n _getEventHandlers(): {\r\n onChange: (e: TChangeEvent) => void;\r\n onKeyDown: (e: TKeyboardEvent) => void;\r\n onPaste: (e: TClipboardEvent) => void;\r\n onBeforeInput?: (e: TChangeEvent) => void;\r\n onKeyPress?: (e: TKeyboardEvent) => void;\r\n } {\r\n return {\r\n onChange: this._onChange,\r\n onKeyDown: this._onKeyDown,\r\n onPaste: this._onPaste,\r\n [this._keyPressPropName()]: this._onKeyPress\r\n };\r\n }\r\n\r\n focus() {\r\n this.input.focus();\r\n }\r\n\r\n blur() {\r\n this.input.blur();\r\n }\r\n\r\n getInputProps = () => {\r\n let maxLength = this.mask.pattern.length;\r\n let eventHandlers = this._getEventHandlers();\r\n let {placeholder = this.mask.emptyValue} = this.props;\r\n\r\n let {placeholderChar, formatCharacters, ...cleanedProps} = this.props;\r\n const props = {...cleanedProps, ...eventHandlers, maxLength, placeholder};\r\n delete props.value;\r\n return props;\r\n };\r\n\r\n _lastValue = null as any;\r\n setInputValue = (value: string) => {\r\n if (!this._Input) return;\r\n if (value === this._lastValue) return;\r\n\r\n this.setState({value: value});\r\n\r\n this._lastValue = value;\r\n if (this._Input.input) {\r\n this._Input.input.value = value;\r\n }\r\n };\r\n\r\n _Input: InputRef | null = null;\r\n handleInputRef = (ref: InputRef) => {\r\n if (!ref || !ref.input) return;\r\n this._Input = ref;\r\n this.input = ref.input;\r\n\r\n if (\r\n this._lastValue === null &&\r\n typeof this.props.defaultValue === 'string'\r\n ) {\r\n this.mask.setValue(this.props.defaultValue); // write the whole updated value into the mask\r\n this.setInputValue(this._getDisplayValue()); // update the form with pattern applied to the value\r\n }\r\n };\r\n\r\n render() {\r\n return <Input value={this.state.value} {...this.getInputProps()} ref={this.handleInputRef}/>;\r\n }\r\n}"]}
|
|
1
|
+
{"version":3,"file":"maskedInput.js","sourceRoot":"","sources":["../../../../components/input/maskedInput.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAA8B,SAAS,EAAgB,MAAM,OAAO,CAAC;AACnF,OAAO,EAAC,KAAK,EAAW,MAAM,MAAM,CAA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CAAC,KAAK,CAAC,UAAU,CAAC;gBACxC,CAAC,CAAC,eAAe;gBACjB,CAAC,CAAC,YAAY,CAAC;QACvB,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;IAED,+DAA+D;IAC/D,iBAAiB;QAOb,OAAO;YACH,QAAQ,EAAE,IAAI,CAAC,SAAS;YACxB,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,EAAE,IAAI,CAAC,WAAW;SAC/C,CAAC;IACN,CAAC;IAED,6CAA6C;IAC7C,KAAK;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED,iDAAiD;IACjD,IAAI;QACA,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC;IA8CD,MAAM;QACF,OAAO,oBAAC,KAAK,kBAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IAAM,IAAI,CAAC,aAAa,EAAE,IAAE,GAAG,EAAE,IAAI,CAAC,cAAc,IAAG,CAAC;IACjG,CAAC;CACJ","sourcesContent":["import React, {ChangeEvent, ClipboardEvent, Component, KeyboardEvent} from 'react';\r\nimport {Input, InputRef} from 'antd';\r\nimport InputMask from 'd2coreui/components/input/mask/inputMaskCore';\r\nimport {getSelection, isRedo, isUndo, setSelection} from 'd2coreui/components/input/mask/helpers';\r\nimport {InputProps} from 'antd/lib/input';\r\n\r\n/**\r\n * Props of {@link MaskedInput}: all antd `Input` props plus the mask settings. `maxLength` is always replaced by\r\n * the mask length and `placeholder` defaults to the empty mask (e.g. `__.__.____`).\r\n */\r\nexport type MaskedInputProps = InputProps & {\r\n /**\r\n * Mask pattern. Format characters mark editable positions: `1` digit, `a` letter, `A` letter (upper-cased),\r\n * `*` alphanumeric, `#` alphanumeric (upper-cased). Every other character is a literal that is inserted\r\n * automatically; prefix a format character with `\\` to make it literal. The pattern may change at any time,\r\n * the entered characters are kept.\r\n */\r\n mask: string;\r\n /**\r\n * Custom format characters (a `FormatCharacters` map from `mask/helpers`), merged over\r\n * `DEFAULT_FORMAT_CHARACTERS`; a `null` entry removes a default. Read only on construction.\r\n */\r\n formatCharacters?: object;\r\n /**\r\n * Single character shown in unfilled editable positions. Read only on construction.\r\n * @default \"_\"\r\n */\r\n placeholderChar?: string;\r\n /**\r\n * Controlled value; whenever it changes it is formatted into the mask (invalid characters become placeholders).\r\n * Without it the input is uncontrolled and a string `defaultValue` is applied once on mount.\r\n */\r\n value?: string;\r\n};\r\n\r\ntype TChangeEvent = ChangeEvent<HTMLInputElement>;\r\ntype TKeyboardEvent = KeyboardEvent<HTMLInputElement> & InputEvent; // on mobile devices InputEvent is called\r\ntype TClipboardEvent = ClipboardEvent<any>;\r\n\r\n/**\r\n * antd `Input` that restricts typing, Backspace and paste to a fixed pattern (see {@link MaskedInputProps.mask})\r\n * and supports undo/redo (Ctrl+Z, Ctrl+Y / Ctrl+Shift+Z). `onChange` fires after every accepted edit, but the\r\n * event may be a change, keyboard or clipboard event - read only `event.target.value`, which holds the formatted\r\n * text with placeholder characters in the unfilled positions.\r\n *\r\n * @example\r\n * // \"1\" is a format character, so the literal \"1\" of the prefix has to be escaped\r\n * <MaskedInput mask={\"+42\\\\1 111 111 111\"}\r\n * value={phone}\r\n * onChange={e => setPhone(e.target.value)}/>\r\n */\r\nexport default class MaskedInput extends Component<MaskedInputProps, {value?: string}> {\r\n /** The mask engine holding the current value, selection and undo history. */\r\n mask: InputMask;\r\n /** The underlying DOM input element; assigned on mount. */\r\n input!: HTMLInputElement;\r\n\r\n constructor(props: MaskedInputProps) {\r\n super(props);\r\n\r\n this.state = {\r\n value: this.props.value,\r\n }\r\n\r\n let options: any = {\r\n pattern: this.props.mask,\r\n value: this.props.value,\r\n formatCharacters: this.props.formatCharacters\r\n };\r\n\r\n if (this.props.placeholderChar) {\r\n options.placeholderChar = this.props.placeholderChar;\r\n }\r\n\r\n this.mask = new InputMask(options);\r\n }\r\n\r\n componentDidMount() {\r\n this.setInputValue(this._getDisplayValue());\r\n }\r\n\r\n UNSAFE_componentWillReceiveProps(nextProps: MaskedInputProps) {\r\n if (\r\n this.props.mask !== nextProps.mask &&\r\n this.props.value !== nextProps.mask\r\n ) {\r\n // if we get a new value and a new mask at the same time\r\n // check if the mask.value is still the initial value\r\n // - if so use the nextProps value\r\n // - otherwise the `this.mask` has a value for us (most likely from paste action)\r\n if (this.mask.getValue() === this.mask.emptyValue) {\r\n this.mask.setPattern(nextProps.mask, {value: nextProps.value});\r\n } else {\r\n this.mask.setPattern(nextProps.mask, {\r\n value: this.mask.getRawValue()\r\n });\r\n }\r\n } else if (this.props.mask !== nextProps.mask) {\r\n this.mask.setPattern(nextProps.mask, {value: this.mask.getRawValue()});\r\n }\r\n\r\n if (this.props.value !== nextProps.value) {\r\n this.mask.setValue(nextProps.value);\r\n this.setInputValue(this._getDisplayValue());\r\n }\r\n }\r\n\r\n UNSAFE_componentWillUpdate(nextProps: MaskedInputProps) {\r\n if (!this.props.mask) return null;\r\n if (nextProps.mask !== this.props.mask) {\r\n this._updatePattern(nextProps);\r\n }\r\n return;\r\n }\r\n\r\n componentDidUpdate(prevProps: MaskedInputProps) {\r\n if (!this.props.mask) return null;\r\n if (prevProps.mask !== this.props.mask && this.mask.selection.start) {\r\n this._updateInputSelection();\r\n }\r\n return;\r\n }\r\n\r\n /** Internal: applies the mask of `props`, keeping the raw value and the input selection. */\r\n _updatePattern(props: MaskedInputProps) {\r\n this.mask.setPattern(props.mask, {\r\n value: this.mask.getRawValue(),\r\n selection: getSelection(this.input)\r\n });\r\n }\r\n\r\n /** Internal: copies the input selection into the mask. */\r\n _updateMaskSelection() {\r\n this.mask.selection = getSelection(this.input);\r\n }\r\n\r\n /** Internal: applies the mask selection to the input. */\r\n _updateInputSelection() {\r\n setSelection(this.input, this.mask.selection);\r\n }\r\n\r\n /** Internal `change` handler: reformats changed text through the mask, then calls `onChange`. */\r\n _onChange = (e: TChangeEvent) => {\r\n let maskValue = this.mask.getValue();\r\n let incomingValue = e.target.value;\r\n if (incomingValue !== maskValue) {\r\n // only modify mask if form contents actually changed\r\n this._updateMaskSelection();\r\n this.mask.setValue(incomingValue); // write the whole updated value into the mask\r\n this.setInputValue(this._getDisplayValue()); // update the form with pattern applied to the value\r\n this._updateInputSelection();\r\n }\r\n\r\n if (this.props.onChange) {\r\n this.props.onChange(e);\r\n }\r\n };\r\n\r\n /** Internal `keydown` handler: undo/redo and Backspace. */\r\n _onKeyDown = (e: TKeyboardEvent) => {\r\n setTimeout(() => {\r\n this.input.classList[this.input.value ? 'add' : 'remove']('has-value');\r\n }, 100);\r\n\r\n if (isUndo(e)) {\r\n e.preventDefault();\r\n if (this.mask.undo()) {\r\n this.setInputValue(this._getDisplayValue());\r\n this._updateInputSelection();\r\n if (this.props.onChange) {\r\n this.props.onChange(e as unknown as TChangeEvent);\r\n }\r\n }\r\n return;\r\n } else if (isRedo(e)) {\r\n e.preventDefault();\r\n if (this.mask.redo()) {\r\n this.setInputValue(this._getDisplayValue());\r\n this._updateInputSelection();\r\n if (this.props.onChange) {\r\n this.props.onChange(e as unknown as TChangeEvent);\r\n }\r\n }\r\n return;\r\n }\r\n\r\n if (e.key === 'Backspace') {\r\n e.preventDefault();\r\n this._updateMaskSelection();\r\n if (this.mask.backspace()) {\r\n let value = this._getDisplayValue();\r\n this.setInputValue(value);\r\n if (value) {\r\n this._updateInputSelection();\r\n }\r\n if (this.props.onChange) {\r\n this.props.onChange(e as unknown as TChangeEvent);\r\n }\r\n }\r\n }\r\n };\r\n\r\n /** Internal `keypress` (`beforeinput` on Android) handler: feeds typed characters into the mask; modified keys and Enter pass through. */\r\n _onKeyPress = (e: TKeyboardEvent) => {\r\n // Ignore modified key presses\r\n // Ignore enter key to allow form submission\r\n if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') {\r\n return;\r\n }\r\n\r\n e.preventDefault();\r\n this._updateMaskSelection();\r\n if (this.mask.input(e.key || e.data as string)) {\r\n this.setInputValue(this.mask.getValue());\r\n this._updateInputSelection();\r\n if (this.props.onChange) {\r\n this.props.onChange(e as unknown as TChangeEvent);\r\n }\r\n }\r\n };\r\n\r\n /** Internal `paste` handler: pastes clipboard text through the mask; a paste with invalid content is rejected as a whole. */\r\n _onPaste = (e: TClipboardEvent) => {\r\n e.preventDefault();\r\n this._updateMaskSelection();\r\n // getData value needed for IE also works in FF & Chrome\r\n if (this.mask.paste(e.clipboardData.getData('Text'))) {\r\n // @ts-ignore\r\n this.setInputValue(this.mask.getValue());\r\n // Timeout needed for IE\r\n setTimeout(() => this._updateInputSelection(), 0);\r\n if (this.props.onChange) {\r\n // @ts-ignore\r\n this.props.onChange(e);\r\n }\r\n }\r\n };\r\n\r\n /** Internal: the formatted value, or an empty string when nothing has been entered. */\r\n _getDisplayValue() {\r\n let value = this.mask.getValue();\r\n return value === this.mask.emptyValue ? '' : value;\r\n }\r\n\r\n /** Internal: name of the event prop used for character input (`onBeforeInput` on Android, `onKeyPress` elsewhere). */\r\n _keyPressPropName() {\r\n if (typeof navigator !== 'undefined') {\r\n return navigator.userAgent.match(/Android/i)\r\n ? 'onBeforeInput'\r\n : 'onKeyPress';\r\n }\r\n return 'onKeyPress';\r\n }\r\n\r\n /** Internal: the event handlers passed to the antd `Input`. */\r\n _getEventHandlers(): {\r\n onChange: (e: TChangeEvent) => void;\r\n onKeyDown: (e: TKeyboardEvent) => void;\r\n onPaste: (e: TClipboardEvent) => void;\r\n onBeforeInput?: (e: TChangeEvent) => void;\r\n onKeyPress?: (e: TKeyboardEvent) => void;\r\n } {\r\n return {\r\n onChange: this._onChange,\r\n onKeyDown: this._onKeyDown,\r\n onPaste: this._onPaste,\r\n [this._keyPressPropName()]: this._onKeyPress\r\n };\r\n }\r\n\r\n /** Moves the keyboard focus to the input. */\r\n focus() {\r\n this.input.focus();\r\n }\r\n\r\n /** Removes the keyboard focus from the input. */\r\n blur() {\r\n this.input.blur();\r\n }\r\n\r\n /** Props passed to the antd `Input`: own props without the mask settings and `value`, plus the mask handlers, `maxLength` and `placeholder`. */\r\n getInputProps = () => {\r\n let maxLength = this.mask.pattern.length;\r\n let eventHandlers = this._getEventHandlers();\r\n let {placeholder = this.mask.emptyValue} = this.props;\r\n\r\n let {placeholderChar, formatCharacters, ...cleanedProps} = this.props;\r\n const props = {...cleanedProps, ...eventHandlers, maxLength, placeholder};\r\n delete props.value;\r\n return props;\r\n };\r\n\r\n /** Internal: last value written to the input, `null` before the first write. */\r\n _lastValue = null as any;\r\n /** Writes `value` directly to the DOM input and to the component state; ignored before mount and when unchanged. */\r\n setInputValue = (value: string) => {\r\n if (!this._Input) return;\r\n if (value === this._lastValue) return;\r\n\r\n this.setState({value: value});\r\n\r\n this._lastValue = value;\r\n if (this._Input.input) {\r\n this._Input.input.value = value;\r\n }\r\n };\r\n\r\n /** Internal: the antd `Input` ref. */\r\n _Input: InputRef | null = null;\r\n /** Ref callback of the antd `Input`; on first attach applies a string `defaultValue`. */\r\n handleInputRef = (ref: InputRef) => {\r\n if (!ref || !ref.input) return;\r\n this._Input = ref;\r\n this.input = ref.input;\r\n\r\n if (\r\n this._lastValue === null &&\r\n typeof this.props.defaultValue === 'string'\r\n ) {\r\n this.mask.setValue(this.props.defaultValue); // write the whole updated value into the mask\r\n this.setInputValue(this._getDisplayValue()); // update the form with pattern applied to the value\r\n }\r\n };\r\n\r\n render() {\r\n return <Input value={this.state.value} {...this.getInputProps()} ref={this.handleInputRef}/>;\r\n }\r\n}"]}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { PasswordProps } from "antd/lib/input/Password";
|
|
3
|
+
/**
|
|
4
|
+
* antd `Input.Password` whose eye icon reveals the password only while it is held down (mouse or touch); it is
|
|
5
|
+
* hidden again on release or when the pointer leaves the icon, keeping the caret position.
|
|
6
|
+
* The `iconRender` and `visibilityToggle` props are overridden.
|
|
7
|
+
*/
|
|
3
8
|
export default class PasswordInput extends React.Component<PasswordProps, unknown> {
|
|
4
9
|
private component;
|
|
5
10
|
constructor(props: Readonly<PasswordProps>);
|
|
11
|
+
/** Moves the keyboard focus to the input. */
|
|
6
12
|
focus(): void;
|
|
13
|
+
/** Renders the press-and-hold visibility icon; used as the `iconRender` of the password input. */
|
|
7
14
|
getIcon: (visible: boolean) => React.JSX.Element;
|
|
8
15
|
render(): React.JSX.Element;
|
|
9
16
|
}
|
|
@@ -11,6 +11,7 @@ const IconRendererClass = class IconRend extends React.Component {
|
|
|
11
11
|
const component = this.props.component;
|
|
12
12
|
this.start = component.input.selectionStart;
|
|
13
13
|
this.end = component.input.selectionEnd;
|
|
14
|
+
// Fix bug when cursor was moved to start
|
|
14
15
|
setTimeout(() => {
|
|
15
16
|
component.input.selectionStart = this.start;
|
|
16
17
|
component.input.selectionEnd = this.end;
|
|
@@ -48,15 +49,22 @@ const IconRendererClass = class IconRend extends React.Component {
|
|
|
48
49
|
}
|
|
49
50
|
;
|
|
50
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* antd `Input.Password` whose eye icon reveals the password only while it is held down (mouse or touch); it is
|
|
54
|
+
* hidden again on release or when the pointer leaves the icon, keeping the caret position.
|
|
55
|
+
* The `iconRender` and `visibilityToggle` props are overridden.
|
|
56
|
+
*/
|
|
51
57
|
export default class PasswordInput extends React.Component {
|
|
52
58
|
constructor(props) {
|
|
53
59
|
super(props);
|
|
54
60
|
this.component = null;
|
|
61
|
+
/** Renders the press-and-hold visibility icon; used as the `iconRender` of the password input. */
|
|
55
62
|
this.getIcon = (visible) => {
|
|
56
63
|
return React.createElement(IconRendererClass, { visible: visible, component: this.component });
|
|
57
64
|
};
|
|
58
65
|
this.getIcon = this.getIcon.bind(this);
|
|
59
66
|
}
|
|
67
|
+
/** Moves the keyboard focus to the input. */
|
|
60
68
|
focus() {
|
|
61
69
|
var _a, _b;
|
|
62
70
|
(_b = (_a = this.component) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passwordInput.js","sourceRoot":"","sources":["../../../../components/input/passwordInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAC,oBAAoB,EAAE,WAAW,EAAC,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAC,KAAK,EAAC,MAAM,MAAM,CAAC;AAE3B,MAAM,iBAAiB,GAAG,MAAM,QAAS,SAAQ,KAAK,CAAC,SAAmB;IAItE,YAAY,KAAU;QAClB,KAAK,CAAC,KAAK,CAAC,CAAC;QAJT,UAAK,GAAW,CAAC,CAAC;QAClB,QAAG,GAAW,CAAC,CAAC;IAIxB,CAAC;IAED,cAAc;QACV,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;QAEvC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC;QAC5C,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"passwordInput.js","sourceRoot":"","sources":["../../../../components/input/passwordInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAC,oBAAoB,EAAE,WAAW,EAAC,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAC,KAAK,EAAC,MAAM,MAAM,CAAC;AAE3B,MAAM,iBAAiB,GAAG,MAAM,QAAS,SAAQ,KAAK,CAAC,SAAmB;IAItE,YAAY,KAAU;QAClB,KAAK,CAAC,KAAK,CAAC,CAAC;QAJT,UAAK,GAAW,CAAC,CAAC;QAClB,QAAG,GAAW,CAAC,CAAC;IAIxB,CAAC;IAED,cAAc;QACV,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;QAEvC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,cAAc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C;gBAC1B,CAAC;YACL,CAAC,EACD,YAAY,EAAE,GAAG,EAAE;gBACf,IAAI,OAAO,EAAE,CAAC;oBACV,OAAO,aAAP,OAAO,uBAAP,OAAO,EAAI,CAAC;oBACZ,IAAI,CAAC,cAAc,EAAE,CAAC;gBAC1B,CAAC;YACL,CAAC,GACH,CAAC,CAAC;IACR,CAAC;IAAA,CAAC;CACL,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK,CAAC,SAAiC;IAG9E,YAAY,KAA8B;QACtC,KAAK,CAAC,KAAK,CAAC,CAAC;QAHT,cAAS,GAAe,IAAI,CAAC;QAYrC,kGAAkG;QAClG,YAAO,GAAG,CAAC,OAAgB,EAAE,EAAE;YAC3B,OAAO,oBAAC,iBAAiB,IAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,GAAI,CAAC;QAC9E,CAAC,CAAA;QAXG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,6CAA6C;IAC7C,KAAK;;QACD,MAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,KAAK,kDAAI,CAAC;IAC9B,CAAC;IAOD,MAAM;QACF,OAAO,oBAAC,KAAK,CAAC,QAAQ,oBAAK,IAAI,CAAC,KAAK,IAAE,UAAU,EAAE,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,EAAE;gBACxG,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC/B,CAAC,IAAG,CAAA;IACR,CAAC;CACJ","sourcesContent":["import React from \"react\"\r\nimport {PasswordProps} from \"antd/lib/input/Password\";\r\nimport {EyeInvisibleOutlined, EyeOutlined} from \"@ant-design/icons\";\r\nimport {Input} from \"antd\";\r\n\r\nconst IconRendererClass = class IconRend extends React.Component<any, any> {\r\n private start: number = 0;\r\n private end: number = 0;\r\n\r\n constructor(props: any) {\r\n super(props);\r\n }\r\n\r\n fixCursorReset() {\r\n const component = this.props.component;\r\n\r\n this.start = component.input.selectionStart;\r\n this.end = component.input.selectionEnd;\r\n\r\n // Fix bug when cursor was moved to start\r\n setTimeout(() => {\r\n component.input.selectionStart = this.start;\r\n component.input.selectionEnd = this.end;\r\n });\r\n }\r\n\r\n render() {\r\n const {visible, onClick} = this.props;\r\n const IconClass = visible ? EyeOutlined : EyeInvisibleOutlined;\r\n\r\n return (<IconClass\r\n key=\"password-icon\"\r\n className=\"ant-input-password-icon\"\r\n onTouchStart={(e) => {\r\n e.preventDefault();\r\n if (!visible) {\r\n onClick?.();\r\n }\r\n }}\r\n onTouchEnd={() => {\r\n if (visible) {\r\n onClick?.();\r\n this.fixCursorReset();\r\n }\r\n }}\r\n onMouseDown={(e) => {\r\n e.preventDefault();\r\n if (!visible) {\r\n onClick?.();\r\n }\r\n }}\r\n onMouseUp={() => {\r\n if (visible) {\r\n onClick?.();\r\n this.fixCursorReset();\r\n }\r\n }}\r\n onMouseLeave={() => {\r\n if (visible) {\r\n onClick?.();\r\n this.fixCursorReset();\r\n }\r\n }}\r\n />);\r\n };\r\n};\r\n\r\n/**\r\n * antd `Input.Password` whose eye icon reveals the password only while it is held down (mouse or touch); it is\r\n * hidden again on release or when the pointer leaves the icon, keeping the caret position.\r\n * The `iconRender` and `visibilityToggle` props are overridden.\r\n */\r\nexport default class PasswordInput extends React.Component<PasswordProps, unknown> {\r\n private component: any | null = null;\r\n\r\n constructor(props: Readonly<PasswordProps>) {\r\n super(props);\r\n this.getIcon = this.getIcon.bind(this);\r\n }\r\n\r\n /** Moves the keyboard focus to the input. */\r\n focus() {\r\n this.component?.focus?.();\r\n }\r\n\r\n /** Renders the press-and-hold visibility icon; used as the `iconRender` of the password input. */\r\n getIcon = (visible: boolean) => {\r\n return <IconRendererClass visible={visible} component={this.component} />;\r\n }\r\n\r\n render() {\r\n return <Input.Password {...this.props} iconRender={this.getIcon} visibilityToggle={true} ref={(component) => {\r\n this.component = component;\r\n }}/>\r\n }\r\n}\r\n"]}
|
|
@@ -3,9 +3,15 @@ import React from "react";
|
|
|
3
3
|
interface SimpleAutoCompleteState {
|
|
4
4
|
opened: boolean;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* antd `AutoComplete` with a clearable input whose options stay hidden until the user opens them with the
|
|
8
|
+
* dropdown arrow (shown when `options` is non-empty); selecting an option hides them again, unless an own
|
|
9
|
+
* `onSelect` is passed, which replaces that handler. Default width is 200 px; a `style` prop replaces it.
|
|
10
|
+
*/
|
|
6
11
|
export default class SimpleAutoComplete extends React.Component<AutoCompleteProps, SimpleAutoCompleteState> {
|
|
7
12
|
private autocomplete;
|
|
8
13
|
constructor(props: Readonly<AutoCompleteProps>);
|
|
14
|
+
/** Intended to focus the input; currently has no effect because the internal ref is never attached. */
|
|
9
15
|
focus(): void;
|
|
10
16
|
render(): React.JSX.Element;
|
|
11
17
|
}
|
|
@@ -12,6 +12,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import React from "react";
|
|
13
13
|
import { AutoComplete, Input } from "antd";
|
|
14
14
|
import DropdownArrow from "../icons/dropdownArrow";
|
|
15
|
+
/**
|
|
16
|
+
* antd `AutoComplete` with a clearable input whose options stay hidden until the user opens them with the
|
|
17
|
+
* dropdown arrow (shown when `options` is non-empty); selecting an option hides them again, unless an own
|
|
18
|
+
* `onSelect` is passed, which replaces that handler. Default width is 200 px; a `style` prop replaces it.
|
|
19
|
+
*/
|
|
15
20
|
export default class SimpleAutoComplete extends React.Component {
|
|
16
21
|
constructor(props) {
|
|
17
22
|
super(props);
|
|
@@ -21,6 +26,7 @@ export default class SimpleAutoComplete extends React.Component {
|
|
|
21
26
|
this.autocomplete = React.createRef();
|
|
22
27
|
this.focus = this.focus.bind(this);
|
|
23
28
|
}
|
|
29
|
+
/** Intended to focus the input; currently has no effect because the internal ref is never attached. */
|
|
24
30
|
focus() {
|
|
25
31
|
var _a;
|
|
26
32
|
(_a = this.autocomplete.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleAutoComplete.js","sourceRoot":"","sources":["../../../../components/input/simpleAutoComplete.tsx"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,YAAY,EAAE,KAAK,EAAC,MAAM,MAAM,CAAC;AAEzC,OAAO,aAAa,MAAM,wBAAwB,CAAC;AAMnD,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK,CAAC,SAAqD;IAIvG,YAAY,KAAkC;QAC1C,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG;YACT,MAAM,EAAE,KAAK;SAChB,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,KAAK;;QACD,MAAA,IAAI,CAAC,YAAY,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;IACvC,CAAC;IAED,MAAM;QACF,IAAI,KAAqC,IAAI,CAAC,KAAK,EAA/C,EAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,OAAuB,EAAlB,IAAI,cAAjC,+BAAkC,CAAa,CAAC;QACpD,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACjF,OAAO,CACH,oBAAC,YAAY,kBACT,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EACzC,KAAK,EAAE,EAAC,KAAK,EAAE,GAAG,EAAC,EACnB,WAAW,EAAE,KAAK,EAClB,wBAAwB,EAAE,KAAK,EAC/B,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,GAAG,EAAE;gBACX,IAAI,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC,CAAC;YACnC,CAAC,IACG,IAAI;YAER,oBAAC,KAAK,IACF,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,CAAC,QAAQ,EACrB,MAAM,EACF,oBAAoB;oBACpB,oBAAC,aAAa,IAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,OAAO,EAAE,GAAG,EAAE;4BACV,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gCACvB,IAAI,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAC,CAAC,CAAC;4BAChD,CAAC;wBACL,CAAC,GAAG,EAEvB,QAAQ,EAAE,QAAQ,GAAI,CACf,CAClB,CAAC;IACN,CAAC;CACJ","sourcesContent":["import {AutoCompleteProps} from \"antd/es/auto-complete\";\r\nimport React from \"react\";\r\nimport {AutoComplete, Input} from \"antd\";\r\nimport {RefSelectProps} from \"antd/es/select\";\r\nimport DropdownArrow from \"../icons/dropdownArrow\";\r\n\r\ninterface SimpleAutoCompleteState {\r\n opened: boolean\r\n}\r\n\r\nexport default class SimpleAutoComplete extends React.Component<AutoCompleteProps, SimpleAutoCompleteState> {\r\n\r\n private autocomplete: React.RefObject<RefSelectProps>;\r\n\r\n constructor(props: Readonly<AutoCompleteProps>) {\r\n super(props);\r\n this.state = {\r\n opened: false,\r\n };\r\n\r\n this.autocomplete = React.createRef();\r\n this.focus = this.focus.bind(this);\r\n }\r\n\r\n focus() {\r\n this.autocomplete.current?.focus();\r\n }\r\n\r\n render() {\r\n let {disabled, options, size, ...rest} = this.props;\r\n const searchHistoryPresent = this.props.options && this.props.options.length > 0;\r\n return (\r\n <AutoComplete\r\n options={this.state.opened ? options : []}\r\n style={{width: 200}}\r\n defaultOpen={false}\r\n defaultActiveFirstOption={false}\r\n disabled={disabled}\r\n onSelect={() => {\r\n this.setState({opened: false});\r\n }}\r\n {...rest}\r\n >\r\n <Input\r\n size={size}\r\n allowClear={!disabled}\r\n suffix={\r\n searchHistoryPresent &&\r\n <DropdownArrow opened={this.state.opened}\r\n onClick={() => {\r\n if (!this.props.disabled) {\r\n this.setState({opened: !this.state.opened});\r\n }\r\n }}/>\r\n }\r\n disabled={disabled} />\r\n </AutoComplete>\r\n );\r\n }\r\n}"]}
|
|
1
|
+
{"version":3,"file":"simpleAutoComplete.js","sourceRoot":"","sources":["../../../../components/input/simpleAutoComplete.tsx"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,YAAY,EAAE,KAAK,EAAC,MAAM,MAAM,CAAC;AAEzC,OAAO,aAAa,MAAM,wBAAwB,CAAC;AAMnD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK,CAAC,SAAqD;IAIvG,YAAY,KAAkC;QAC1C,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG;YACT,MAAM,EAAE,KAAK;SAChB,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,uGAAuG;IACvG,KAAK;;QACD,MAAA,IAAI,CAAC,YAAY,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;IACvC,CAAC;IAED,MAAM;QACF,IAAI,KAAqC,IAAI,CAAC,KAAK,EAA/C,EAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,OAAuB,EAAlB,IAAI,cAAjC,+BAAkC,CAAa,CAAC;QACpD,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACjF,OAAO,CACH,oBAAC,YAAY,kBACT,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EACzC,KAAK,EAAE,EAAC,KAAK,EAAE,GAAG,EAAC,EACnB,WAAW,EAAE,KAAK,EAClB,wBAAwB,EAAE,KAAK,EAC/B,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,GAAG,EAAE;gBACX,IAAI,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC,CAAC;YACnC,CAAC,IACG,IAAI;YAER,oBAAC,KAAK,IACF,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,CAAC,QAAQ,EACrB,MAAM,EACF,oBAAoB;oBACpB,oBAAC,aAAa,IAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,OAAO,EAAE,GAAG,EAAE;4BACV,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gCACvB,IAAI,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAC,CAAC,CAAC;4BAChD,CAAC;wBACL,CAAC,GAAG,EAEvB,QAAQ,EAAE,QAAQ,GAAI,CACf,CAClB,CAAC;IACN,CAAC;CACJ","sourcesContent":["import {AutoCompleteProps} from \"antd/es/auto-complete\";\r\nimport React from \"react\";\r\nimport {AutoComplete, Input} from \"antd\";\r\nimport {RefSelectProps} from \"antd/es/select\";\r\nimport DropdownArrow from \"../icons/dropdownArrow\";\r\n\r\ninterface SimpleAutoCompleteState {\r\n opened: boolean\r\n}\r\n\r\n/**\r\n * antd `AutoComplete` with a clearable input whose options stay hidden until the user opens them with the\r\n * dropdown arrow (shown when `options` is non-empty); selecting an option hides them again, unless an own\r\n * `onSelect` is passed, which replaces that handler. Default width is 200 px; a `style` prop replaces it.\r\n */\r\nexport default class SimpleAutoComplete extends React.Component<AutoCompleteProps, SimpleAutoCompleteState> {\r\n\r\n private autocomplete: React.RefObject<RefSelectProps>;\r\n\r\n constructor(props: Readonly<AutoCompleteProps>) {\r\n super(props);\r\n this.state = {\r\n opened: false,\r\n };\r\n\r\n this.autocomplete = React.createRef();\r\n this.focus = this.focus.bind(this);\r\n }\r\n\r\n /** Intended to focus the input; currently has no effect because the internal ref is never attached. */\r\n focus() {\r\n this.autocomplete.current?.focus();\r\n }\r\n\r\n render() {\r\n let {disabled, options, size, ...rest} = this.props;\r\n const searchHistoryPresent = this.props.options && this.props.options.length > 0;\r\n return (\r\n <AutoComplete\r\n options={this.state.opened ? options : []}\r\n style={{width: 200}}\r\n defaultOpen={false}\r\n defaultActiveFirstOption={false}\r\n disabled={disabled}\r\n onSelect={() => {\r\n this.setState({opened: false});\r\n }}\r\n {...rest}\r\n >\r\n <Input\r\n size={size}\r\n allowClear={!disabled}\r\n suffix={\r\n searchHistoryPresent &&\r\n <DropdownArrow opened={this.state.opened}\r\n onClick={() => {\r\n if (!this.props.disabled) {\r\n this.setState({opened: !this.state.opened});\r\n }\r\n }}/>\r\n }\r\n disabled={disabled} />\r\n </AutoComplete>\r\n );\r\n }\r\n}"]}
|