@salutejs/plasma-new-hope 0.146.0-canary.1436.10882554984.0 → 0.147.0-canary.1418.10899581491.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. package/cjs/components/Mask/Mask.js +209 -0
  2. package/cjs/components/Mask/Mask.js.map +1 -0
  3. package/cjs/components/Mask/utils/constants.js +33 -0
  4. package/cjs/components/Mask/utils/constants.js.map +1 -0
  5. package/cjs/components/Mask/utils/createMask.js +53 -0
  6. package/cjs/components/Mask/utils/createMask.js.map +1 -0
  7. package/cjs/components/Mask/utils/mask.js +244 -0
  8. package/cjs/components/Mask/utils/mask.js.map +1 -0
  9. package/cjs/components/Mask/utils/parseMask.js +38 -0
  10. package/cjs/components/Mask/utils/parseMask.js.map +1 -0
  11. package/cjs/components/Mask/utils/processInput.js +54 -0
  12. package/cjs/components/Mask/utils/processInput.js.map +1 -0
  13. package/cjs/components/Mask/utils/processMask.js +101 -0
  14. package/cjs/components/Mask/utils/processMask.js.map +1 -0
  15. package/cjs/components/Mask/utils/selection.js +50 -0
  16. package/cjs/components/Mask/utils/selection.js.map +1 -0
  17. package/cjs/components/TextField/TextField.js +3 -1
  18. package/cjs/components/TextField/TextField.js.map +1 -1
  19. package/cjs/index.js +2 -0
  20. package/cjs/index.js.map +1 -1
  21. package/emotion/cjs/components/Mask/Mask.js +220 -0
  22. package/emotion/cjs/components/Mask/Mask.template-doc.mdx +126 -0
  23. package/emotion/cjs/components/Mask/Mask.types.js +5 -0
  24. package/emotion/cjs/components/Mask/index.js +12 -0
  25. package/emotion/cjs/components/Mask/utils/constants.js +29 -0
  26. package/emotion/cjs/components/Mask/utils/createMask.js +50 -0
  27. package/emotion/cjs/components/Mask/utils/mask.js +247 -0
  28. package/emotion/cjs/components/Mask/utils/parseMask.js +36 -0
  29. package/emotion/cjs/components/Mask/utils/processInput.js +52 -0
  30. package/emotion/cjs/components/Mask/utils/processMask.js +99 -0
  31. package/emotion/cjs/components/Mask/utils/selection.js +48 -0
  32. package/emotion/cjs/components/TextField/TextField.js +4 -2
  33. package/emotion/cjs/examples/plasma_b2c/components/Mask/Mask.js +9 -0
  34. package/emotion/cjs/examples/plasma_b2c/components/Mask/Mask.stories.tsx +127 -0
  35. package/emotion/cjs/examples/plasma_web/components/Mask/Mask.js +9 -0
  36. package/emotion/cjs/examples/plasma_web/components/Mask/Mask.stories.tsx +125 -0
  37. package/emotion/cjs/index.js +11 -0
  38. package/emotion/es/components/Mask/Mask.js +212 -0
  39. package/emotion/es/components/Mask/Mask.template-doc.mdx +126 -0
  40. package/emotion/es/components/Mask/Mask.types.js +1 -0
  41. package/emotion/es/components/Mask/index.js +1 -0
  42. package/emotion/es/components/Mask/utils/constants.js +23 -0
  43. package/emotion/es/components/Mask/utils/createMask.js +44 -0
  44. package/emotion/es/components/Mask/utils/mask.js +243 -0
  45. package/emotion/es/components/Mask/utils/parseMask.js +30 -0
  46. package/emotion/es/components/Mask/utils/processInput.js +46 -0
  47. package/emotion/es/components/Mask/utils/processMask.js +93 -0
  48. package/emotion/es/components/Mask/utils/selection.js +42 -0
  49. package/emotion/es/components/TextField/TextField.js +4 -2
  50. package/emotion/es/examples/plasma_b2c/components/Mask/Mask.js +3 -0
  51. package/emotion/es/examples/plasma_b2c/components/Mask/Mask.stories.tsx +127 -0
  52. package/emotion/es/examples/plasma_web/components/Mask/Mask.js +3 -0
  53. package/emotion/es/examples/plasma_web/components/Mask/Mask.stories.tsx +125 -0
  54. package/emotion/es/index.js +2 -1
  55. package/es/components/Mask/Mask.js +205 -0
  56. package/es/components/Mask/Mask.js.map +1 -0
  57. package/es/components/Mask/utils/constants.js +26 -0
  58. package/es/components/Mask/utils/constants.js.map +1 -0
  59. package/es/components/Mask/utils/createMask.js +48 -0
  60. package/es/components/Mask/utils/createMask.js.map +1 -0
  61. package/es/components/Mask/utils/mask.js +240 -0
  62. package/es/components/Mask/utils/mask.js.map +1 -0
  63. package/es/components/Mask/utils/parseMask.js +34 -0
  64. package/es/components/Mask/utils/parseMask.js.map +1 -0
  65. package/es/components/Mask/utils/processInput.js +50 -0
  66. package/es/components/Mask/utils/processInput.js.map +1 -0
  67. package/es/components/Mask/utils/processMask.js +97 -0
  68. package/es/components/Mask/utils/processMask.js.map +1 -0
  69. package/es/components/Mask/utils/selection.js +46 -0
  70. package/es/components/Mask/utils/selection.js.map +1 -0
  71. package/es/components/TextField/TextField.js +3 -1
  72. package/es/components/TextField/TextField.js.map +1 -1
  73. package/es/index.js +1 -0
  74. package/es/index.js.map +1 -1
  75. package/package.json +2 -2
  76. package/styled-components/cjs/components/Mask/Mask.js +220 -0
  77. package/styled-components/cjs/components/Mask/Mask.template-doc.mdx +126 -0
  78. package/styled-components/cjs/components/Mask/Mask.types.js +5 -0
  79. package/styled-components/cjs/components/Mask/index.js +12 -0
  80. package/styled-components/cjs/components/Mask/utils/constants.js +29 -0
  81. package/styled-components/cjs/components/Mask/utils/createMask.js +50 -0
  82. package/styled-components/cjs/components/Mask/utils/mask.js +247 -0
  83. package/styled-components/cjs/components/Mask/utils/parseMask.js +36 -0
  84. package/styled-components/cjs/components/Mask/utils/processInput.js +52 -0
  85. package/styled-components/cjs/components/Mask/utils/processMask.js +99 -0
  86. package/styled-components/cjs/components/Mask/utils/selection.js +48 -0
  87. package/styled-components/cjs/components/TextField/TextField.js +3 -1
  88. package/styled-components/cjs/examples/plasma_b2c/components/Mask/Mask.js +9 -0
  89. package/styled-components/cjs/examples/plasma_b2c/components/Mask/Mask.stories.tsx +127 -0
  90. package/styled-components/cjs/examples/plasma_web/components/Mask/Mask.js +9 -0
  91. package/styled-components/cjs/examples/plasma_web/components/Mask/Mask.stories.tsx +125 -0
  92. package/styled-components/cjs/index.js +11 -0
  93. package/styled-components/es/components/Mask/Mask.js +212 -0
  94. package/styled-components/es/components/Mask/Mask.template-doc.mdx +126 -0
  95. package/styled-components/es/components/Mask/Mask.types.js +1 -0
  96. package/styled-components/es/components/Mask/index.js +1 -0
  97. package/styled-components/es/components/Mask/utils/constants.js +23 -0
  98. package/styled-components/es/components/Mask/utils/createMask.js +44 -0
  99. package/styled-components/es/components/Mask/utils/mask.js +243 -0
  100. package/styled-components/es/components/Mask/utils/parseMask.js +30 -0
  101. package/styled-components/es/components/Mask/utils/processInput.js +46 -0
  102. package/styled-components/es/components/Mask/utils/processMask.js +93 -0
  103. package/styled-components/es/components/Mask/utils/selection.js +42 -0
  104. package/styled-components/es/components/TextField/TextField.js +3 -1
  105. package/styled-components/es/examples/plasma_b2c/components/Mask/Mask.js +3 -0
  106. package/styled-components/es/examples/plasma_b2c/components/Mask/Mask.stories.tsx +127 -0
  107. package/styled-components/es/examples/plasma_web/components/Mask/Mask.js +3 -0
  108. package/styled-components/es/examples/plasma_web/components/Mask/Mask.stories.tsx +125 -0
  109. package/styled-components/es/index.js +2 -1
  110. package/types/components/Mask/Mask.d.ts +5 -0
  111. package/types/components/Mask/Mask.d.ts.map +1 -0
  112. package/types/components/Mask/Mask.types.d.ts +84 -0
  113. package/types/components/Mask/Mask.types.d.ts.map +1 -0
  114. package/types/components/Mask/index.d.ts +2 -0
  115. package/types/components/Mask/index.d.ts.map +1 -0
  116. package/types/components/Mask/utils/constants.d.ts +15 -0
  117. package/types/components/Mask/utils/constants.d.ts.map +1 -0
  118. package/types/components/Mask/utils/createMask.d.ts +19 -0
  119. package/types/components/Mask/utils/createMask.d.ts.map +1 -0
  120. package/types/components/Mask/utils/mask.d.ts +48 -0
  121. package/types/components/Mask/utils/mask.d.ts.map +1 -0
  122. package/types/components/Mask/utils/parseMask.d.ts +3 -0
  123. package/types/components/Mask/utils/parseMask.d.ts.map +1 -0
  124. package/types/components/Mask/utils/processInput.d.ts +13 -0
  125. package/types/components/Mask/utils/processInput.d.ts.map +1 -0
  126. package/types/components/Mask/utils/processMask.d.ts +7 -0
  127. package/types/components/Mask/utils/processMask.d.ts.map +1 -0
  128. package/types/components/Mask/utils/selection.d.ts +10 -0
  129. package/types/components/Mask/utils/selection.d.ts.map +1 -0
  130. package/types/components/TextField/TextField.d.ts.map +1 -1
  131. package/types/examples/plasma_b2c/components/Mask/Mask.d.ts +191 -0
  132. package/types/examples/plasma_b2c/components/Mask/Mask.d.ts.map +1 -0
  133. package/types/examples/plasma_web/components/Mask/Mask.d.ts +191 -0
  134. package/types/examples/plasma_web/components/Mask/Mask.d.ts.map +1 -0
  135. package/types/index.d.ts +1 -0
  136. package/types/index.d.ts.map +1 -1
@@ -0,0 +1,243 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ import { charType, defaultFormatChars } from './constants';
9
+ import { parseMask } from './parseMask';
10
+ import { processInput } from './processInput';
11
+ import { removeSelectedRange } from './selection';
12
+
13
+ /**
14
+ * Copyright (c) 2018 Nikita Mostovoy.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ */
19
+
20
+ export var Mask = /*#__PURE__*/function () {
21
+ function Mask(showPrefix, maskChar, maskString, reformat) {
22
+ _classCallCheck(this, Mask);
23
+ _defineProperty(this, "selection", void 0);
24
+ _defineProperty(this, "value", void 0);
25
+ _defineProperty(this, "maskedValue", void 0);
26
+ _defineProperty(this, "visibleValue", void 0);
27
+ _defineProperty(this, "mask", void 0);
28
+ _defineProperty(this, "maskChar", void 0);
29
+ _defineProperty(this, "maskFormatMap", void 0);
30
+ _defineProperty(this, "showPrefix", void 0);
31
+ _defineProperty(this, "callbacks", void 0);
32
+ _defineProperty(this, "maskString", void 0);
33
+ _defineProperty(this, "reformat", void 0);
34
+ this.value = '';
35
+ this.mask = [];
36
+ this.maskedValue = '';
37
+ this.visibleValue = '';
38
+ this.selection = {
39
+ start: 0,
40
+ end: 0
41
+ };
42
+ this.callbacks = [];
43
+ this.maskFormatMap = this.parseMaskFormat;
44
+ this.showPrefix = showPrefix;
45
+ this.maskChar = maskChar;
46
+ this.maskString = maskString;
47
+ this.reformat = reformat;
48
+ }
49
+ return _createClass(Mask, [{
50
+ key: "parseMaskFormat",
51
+ get: function get() {
52
+ return defaultFormatChars.reduce(function (acc, current) {
53
+ acc[String(current.str)] = current;
54
+ return acc;
55
+ }, {});
56
+ }
57
+ }, {
58
+ key: "getSelection",
59
+ get: function get() {
60
+ var _this$selection = this.selection,
61
+ start = _this$selection.start,
62
+ end = _this$selection.end;
63
+ return {
64
+ start: start,
65
+ end: end
66
+ };
67
+ }
68
+ }, {
69
+ key: "getState",
70
+ get: function get() {
71
+ return {
72
+ value: this.value,
73
+ maskedValue: this.maskedValue,
74
+ visibleValue: this.visibleValue,
75
+ selection: this.selection
76
+ };
77
+ }
78
+ }, {
79
+ key: "setSelection",
80
+ set: function set(newSelection) {
81
+ this.selection = newSelection;
82
+ }
83
+ }, {
84
+ key: "setShowStartChars",
85
+ set: function set(show) {
86
+ this.showPrefix = show;
87
+ }
88
+ }, {
89
+ key: "updateMask",
90
+ value: function updateMask(newMask) {
91
+ this.mask = parseMask(newMask, this.maskFormatMap);
92
+ this.updateValue(this.value);
93
+ }
94
+ }, {
95
+ key: "updateMaskChar",
96
+ value: function updateMaskChar(newMaskChar) {
97
+ if (this.maskChar.length > 1) {
98
+ throw new Error('maskChar должен содержать только 1 символ');
99
+ }
100
+ this.maskChar = newMaskChar;
101
+ this.updateValue(this.value);
102
+ }
103
+ }, {
104
+ key: "updateMaskString",
105
+ value: function updateMaskString(newMaskString) {
106
+ if (newMaskString && newMaskString.length !== this.mask.length) {
107
+ throw new Error('maskString должна иметь такую же длину, как и mask');
108
+ }
109
+ this.maskString = newMaskString;
110
+ this.updateValue(this.value);
111
+ }
112
+ }, {
113
+ key: "updateReformat",
114
+ value: function updateReformat(newReformat) {
115
+ this.reformat = newReformat;
116
+ this.updateValue(this.value);
117
+ }
118
+ }, {
119
+ key: "updateValue",
120
+ value: function updateValue(data) {
121
+ if (this.reformat) {
122
+ var _result = this.reformat({
123
+ value: data,
124
+ selection: this.selection
125
+ });
126
+ return this.applyChanges(_result);
127
+ }
128
+ var dataList = Array.isArray(data) ? data : Array.from(data).reduce(function (acc, _char) {
129
+ acc.push({
130
+ "char": _char,
131
+ type: charType.User
132
+ });
133
+ return acc;
134
+ }, []);
135
+ var result = processInput({
136
+ data: dataList,
137
+ selection: this.selection,
138
+ mask: this.mask,
139
+ maskChar: this.maskChar,
140
+ maskString: this.maskString,
141
+ showPrefix: this.showPrefix
142
+ });
143
+ this.applyChanges(result);
144
+ }
145
+ }, {
146
+ key: "removePreviousOrSelected",
147
+ value: function removePreviousOrSelected() {
148
+ var _this$selection2 = this.selection,
149
+ start = _this$selection2.start,
150
+ end = _this$selection2.end;
151
+ if (start === end) {
152
+ var newStart = end - 1 < 0 ? 0 : end - 1;
153
+ this.setSelection = {
154
+ start: newStart,
155
+ end: end
156
+ };
157
+ }
158
+ this.input('');
159
+ }
160
+ }, {
161
+ key: "removeNextOrSelected",
162
+ value: function removeNextOrSelected() {
163
+ var _this$selection3 = this.selection,
164
+ start = _this$selection3.start,
165
+ end = _this$selection3.end;
166
+ if (start === end) {
167
+ this.setSelection = {
168
+ start: start,
169
+ end: end + 1
170
+ };
171
+ }
172
+ this.input('');
173
+ }
174
+ }, {
175
+ key: "paste",
176
+ value: function paste(value) {
177
+ this.input(value);
178
+ }
179
+ }, {
180
+ key: "input",
181
+ value: function input(_input) {
182
+ if (this.reformat) {
183
+ var _result2 = this.reformat({
184
+ value: this.value,
185
+ input: _input,
186
+ selection: this.selection
187
+ });
188
+ return this.applyChanges(_result2);
189
+ }
190
+ var tmpValue = removeSelectedRange({
191
+ value: this.value,
192
+ selection: this.selection,
193
+ maskChar: this.maskChar,
194
+ maskString: String(this.maskString)
195
+ });
196
+ this.selection.end = this.selection.start;
197
+ var result = processInput({
198
+ data: tmpValue,
199
+ input: _input,
200
+ selection: this.selection,
201
+ mask: this.mask,
202
+ maskChar: this.maskChar,
203
+ maskString: this.maskString,
204
+ showPrefix: this.showPrefix
205
+ });
206
+ this.applyChanges(result);
207
+ }
208
+ }, {
209
+ key: "applyChanges",
210
+ value: function applyChanges(result) {
211
+ var oldMaskedValue = this.maskedValue;
212
+ var oldVisibleValue = this.visibleValue;
213
+ var oldSelection = this.selection;
214
+ this.value = result.value;
215
+ this.maskedValue = result.maskedValue;
216
+ this.visibleValue = result.visibleValue;
217
+ this.setSelection = result.selection;
218
+ if (oldMaskedValue !== this.maskedValue || oldVisibleValue !== this.visibleValue || oldSelection.start !== this.selection.start || oldSelection.end !== this.selection.end) {
219
+ this.notify();
220
+ }
221
+ }
222
+ }, {
223
+ key: "subscribe",
224
+ value: function subscribe(callback) {
225
+ this.callbacks.push(callback);
226
+ }
227
+ }, {
228
+ key: "unsubscribe",
229
+ value: function unsubscribe(callback) {
230
+ this.callbacks = this.callbacks.filter(function (item) {
231
+ return item !== callback;
232
+ });
233
+ }
234
+ }, {
235
+ key: "notify",
236
+ value: function notify() {
237
+ var state = this.getState;
238
+ this.callbacks.forEach(function (callback) {
239
+ callback(state);
240
+ });
241
+ }
242
+ }]);
243
+ }();
@@ -0,0 +1,30 @@
1
+ import { escapeChar } from './constants';
2
+ export var parseMask = function parseMask(mask, format) {
3
+ if (!mask) {
4
+ return [];
5
+ }
6
+ var stack = [];
7
+ var escape = false;
8
+ mask.split('').forEach(function (maskChar) {
9
+ var item = format === null || format === void 0 ? void 0 : format[maskChar];
10
+ if (escape && item) {
11
+ item = undefined;
12
+ escape = false;
13
+ }
14
+ if (!item) {
15
+ if (!escape && maskChar === escapeChar) {
16
+ escape = true;
17
+ return;
18
+ }
19
+ escape = false;
20
+ stack.push({
21
+ "char": maskChar
22
+ });
23
+ return;
24
+ }
25
+ if (item.regexp) {
26
+ stack.push(item);
27
+ }
28
+ });
29
+ return stack;
30
+ };
@@ -0,0 +1,46 @@
1
+ import { charType } from './constants';
2
+ import { processMask } from './processMask';
3
+ export var processInput = function processInput(args) {
4
+ var data = args.data,
5
+ _args$input = args.input,
6
+ input = _args$input === void 0 ? '' : _args$input,
7
+ selection = args.selection,
8
+ mask = args.mask,
9
+ _args$maskChar = args.maskChar,
10
+ maskChar = _args$maskChar === void 0 ? '' : _args$maskChar,
11
+ _args$maskString = args.maskString,
12
+ maskString = _args$maskString === void 0 ? '' : _args$maskString,
13
+ showPrefix = args.showPrefix;
14
+ var _processMask = processMask(data, mask, input, maskChar, maskString, selection),
15
+ value = _processMask.value,
16
+ maskedValue = _processMask.maskedValue,
17
+ inputValuesApplied = _processMask.inputValuesApplied;
18
+ var selectionPosition = selection.start + inputValuesApplied;
19
+ var bound = value.length - 1;
20
+ var charsCount = 0;
21
+ while (bound >= 0 && value[bound].type !== charType.User) {
22
+ if (value[bound].type === charType.Mask) {
23
+ charsCount = 0;
24
+ }
25
+ if (value[bound].type === charType.Char) {
26
+ charsCount++;
27
+ }
28
+ bound--;
29
+ }
30
+ if (showPrefix || bound >= 0 || input && input.trim()) {
31
+ bound += charsCount;
32
+ }
33
+ var visibleValue = '';
34
+ for (var i = 0; i <= bound; i++) {
35
+ visibleValue += value[i]["char"];
36
+ }
37
+ return {
38
+ value: value,
39
+ visibleValue: visibleValue,
40
+ maskedValue: maskedValue,
41
+ selection: {
42
+ start: selectionPosition,
43
+ end: selectionPosition
44
+ }
45
+ };
46
+ };
@@ -0,0 +1,93 @@
1
+ import { charType } from './constants';
2
+ export var processMask = function processMask(data, mask, input, maskChar, maskString, selection) {
3
+ var value = [];
4
+ var valueIndex = 0;
5
+ var pastedIndex = 0;
6
+ var maskedValue = '';
7
+ var inputValuesApplied = 0;
8
+ var processMaskPartAsChar = function processMaskPartAsChar(maskPart, pastedValuesStack, item) {
9
+ if (pastedValuesStack && pastedValuesStack[0] === maskPart["char"]) {
10
+ pastedIndex++;
11
+ } else if (item && (item["char"] === maskPart["char"] || item.type !== charType.User) || input) {
12
+ valueIndex++;
13
+ }
14
+ value.push({
15
+ "char": String(maskPart["char"]),
16
+ type: charType.Char
17
+ });
18
+ if (pastedValuesStack) {
19
+ inputValuesApplied++;
20
+ }
21
+ maskedValue += maskPart["char"];
22
+ };
23
+ var processMaskPartAsRegExp = function processMaskPartAsRegExp(maskPart, maskIndex, pastedValuesStack, item) {
24
+ var _maskPart$regexp2;
25
+ var part;
26
+ if (pastedValuesStack) {
27
+ var i = 0;
28
+ while (!(maskPart !== null && maskPart !== void 0 && (_maskPart$regexp = maskPart.regexp) !== null && _maskPart$regexp !== void 0 && _maskPart$regexp.test(pastedValuesStack[i])) && pastedValuesStack.length > i) {
29
+ var _maskPart$regexp;
30
+ i++;
31
+ pastedIndex++;
32
+ }
33
+ if (pastedValuesStack.length > i) {
34
+ pastedIndex++;
35
+ inputValuesApplied++;
36
+ valueIndex++;
37
+ part = pastedValuesStack[i];
38
+ value.push({
39
+ "char": part,
40
+ type: charType.User
41
+ });
42
+ maskedValue += part;
43
+ }
44
+ }
45
+ if (part) {
46
+ return;
47
+ }
48
+ if (item && item.type === charType.Char && data.length > valueIndex + 1) {
49
+ valueIndex++;
50
+ processMaskItem(maskPart, maskIndex);
51
+ return;
52
+ }
53
+ if (item && item.type === charType.User && maskPart !== null && maskPart !== void 0 && (_maskPart$regexp2 = maskPart.regexp) !== null && _maskPart$regexp2 !== void 0 && _maskPart$regexp2.test(item["char"])) {
54
+ value.push({
55
+ "char": item["char"],
56
+ type: charType.User
57
+ });
58
+ maskedValue += item["char"];
59
+ valueIndex++;
60
+ return;
61
+ }
62
+ part = maskString ? maskString[maskIndex] : maskChar;
63
+ value.push({
64
+ "char": part,
65
+ type: charType.Mask
66
+ });
67
+ if (data.length > maskIndex) {
68
+ valueIndex++;
69
+ }
70
+ maskedValue += part;
71
+ };
72
+ var processMaskItem = function processMaskItem(maskPart, maskIndex) {
73
+ var item = data.length > valueIndex ? data[valueIndex] : null;
74
+ var pastedValuesStack = '';
75
+ if (selection.start <= maskIndex && pastedIndex < input.length) {
76
+ pastedValuesStack = input.slice(pastedIndex);
77
+ }
78
+ if (maskPart["char"]) {
79
+ return processMaskPartAsChar(maskPart, pastedValuesStack, item);
80
+ }
81
+ if (maskPart.regexp) {
82
+ return processMaskPartAsRegExp(maskPart, maskIndex, pastedValuesStack, item);
83
+ }
84
+ };
85
+ mask.forEach(function (maskPart, maskIndex) {
86
+ processMaskItem(maskPart, maskIndex);
87
+ });
88
+ return {
89
+ value: value,
90
+ maskedValue: maskedValue,
91
+ inputValuesApplied: inputValuesApplied
92
+ };
93
+ };
@@ -0,0 +1,42 @@
1
+ import { charType } from './constants';
2
+ var copyMaskChar = function copyMaskChar(count, maskChar) {
3
+ var res = [];
4
+ for (var i = 0; i < count; i++) {
5
+ res.push({
6
+ "char": maskChar,
7
+ type: charType.Mask
8
+ });
9
+ }
10
+ return res;
11
+ };
12
+ var pasteMaskSymbols = function pasteMaskSymbols(maskString, maskChar, selection) {
13
+ if (maskString) {
14
+ var res = [];
15
+ for (var i = selection.start; i < selection.end; i++) {
16
+ res.push({
17
+ "char": maskString[i],
18
+ type: charType.Mask
19
+ });
20
+ }
21
+ return res;
22
+ }
23
+ return copyMaskChar(selection.end - selection.start, maskChar);
24
+ };
25
+ export var removeSelectedRange = function removeSelectedRange(args) {
26
+ var value = args.value,
27
+ selection = args.selection,
28
+ maskChar = args.maskChar,
29
+ maskString = args.maskString;
30
+ if (selection.end < selection.start) {
31
+ var tmp = selection.end;
32
+ selection.end = selection.start;
33
+ selection.start = tmp;
34
+ }
35
+ if (selection.start === selection.end) {
36
+ return value;
37
+ }
38
+ if (value.length > selection.start) {
39
+ return value.slice(0, selection.start).concat(pasteMaskSymbols(maskString, maskChar, selection), value.slice(selection.end, value.length));
40
+ }
41
+ return value;
42
+ };
@@ -149,7 +149,9 @@ export var textFieldRoot = function textFieldRoot(Root) {
149
149
  };
150
150
  var handleOnKeyDown = function handleOnKeyDown(event) {
151
151
  handleInputKeydown(event);
152
- onKeyDown && onKeyDown(event);
152
+ if (onKeyDown) {
153
+ onKeyDown(event);
154
+ }
153
155
  };
154
156
  useEffect(function () {
155
157
  if (!isChipEnumeration && !(values !== null && values !== void 0 && values.length)) {
@@ -0,0 +1,3 @@
1
+ import { composeMask } from '../../../../components/Mask';
2
+ import { TextField } from '../TextField/TextField';
3
+ export var Mask = /*#__PURE__*/composeMask(TextField);
@@ -0,0 +1,127 @@
1
+ import React from 'react';
2
+ import type { ComponentProps } from 'react';
3
+ import type { StoryObj, Meta } from '@storybook/react';
4
+ import { action } from '@storybook/addon-actions';
5
+
6
+ import { WithTheme } from '../../../_helpers';
7
+
8
+ import { Mask } from './Mask';
9
+
10
+ const onChange = action('onChange');
11
+
12
+ const sizes = ['l', 'm', 's', 'xs'];
13
+ const views = ['default', 'positive', 'warning', 'negative'];
14
+
15
+ const meta: Meta<typeof Mask> = {
16
+ title: 'plasma_b2c/Mask',
17
+ component: Mask,
18
+ decorators: [WithTheme],
19
+ argTypes: {
20
+ view: {
21
+ options: views,
22
+ control: {
23
+ type: 'select',
24
+ },
25
+ },
26
+ size: {
27
+ options: sizes,
28
+ control: {
29
+ type: 'inline-radio',
30
+ },
31
+ },
32
+ },
33
+ };
34
+
35
+ export default meta;
36
+
37
+ type StoryPropsDefault = Omit<
38
+ ComponentProps<typeof Mask>,
39
+ | 'helperBlock'
40
+ | 'contentLeft'
41
+ | 'htmlSize'
42
+ | 'contentRight'
43
+ | 'type'
44
+ | 'name'
45
+ | 'onFocus'
46
+ | 'onBlur'
47
+ | 'onChange'
48
+ | 'value'
49
+ | 'checked'
50
+ | 'maxLength'
51
+ | 'minLength'
52
+ | 'required'
53
+ | 'enumerationType'
54
+ | 'chips'
55
+ | 'onChangeChips'
56
+ >;
57
+
58
+ const StoryDemo = ({ view, ...rest }: StoryPropsDefault) => {
59
+ return (
60
+ <div style={{ display: 'flex', flexDirection: 'column', gap: '2rem', width: '50%' }}>
61
+ <Mask
62
+ label="Маска телефона"
63
+ mask="+7 (000) 000 - 00 - 00"
64
+ maskChar="_"
65
+ showPrefix={false}
66
+ view={view}
67
+ onChange={onChange}
68
+ {...rest}
69
+ />
70
+
71
+ <Mask
72
+ label="Маска телефона: отображается всегда"
73
+ mask="+7 (000) 000 - 00 - 00"
74
+ maskChar="_"
75
+ view={view}
76
+ alwaysShowMask
77
+ onChange={onChange}
78
+ {...rest}
79
+ value="+79123"
80
+ name="example"
81
+ />
82
+
83
+ <Mask
84
+ label="Маска даты"
85
+ mask="00/00/0000"
86
+ maskString="DD/MM/YYYY"
87
+ alwaysShowMask
88
+ view={view}
89
+ onChange={onChange}
90
+ {...rest}
91
+ />
92
+
93
+ <Mask
94
+ label="Маска даты: значения по умолчанию"
95
+ // eslint-disable-next-line no-octal-escape
96
+ mask="12.\04.0000"
97
+ maskChar="_"
98
+ alwaysShowMask
99
+ view={view}
100
+ onChange={onChange}
101
+ {...rest}
102
+ />
103
+
104
+ <Mask
105
+ label="Маска времени"
106
+ mask="00:00"
107
+ maskChar="_"
108
+ alwaysShowMask
109
+ view={view}
110
+ onChange={onChange}
111
+ {...rest}
112
+ />
113
+ </div>
114
+ );
115
+ };
116
+
117
+ export const Default: StoryObj<StoryPropsDefault> = {
118
+ args: {
119
+ size: 'l',
120
+ view: 'default',
121
+ labelPlacement: 'outer',
122
+ placeholder: 'Заполните поле',
123
+ disabled: false,
124
+ readOnly: false,
125
+ },
126
+ render: (args) => <StoryDemo {...args} />,
127
+ };
@@ -0,0 +1,3 @@
1
+ import { composeMask } from '../../../../components/Mask';
2
+ import { TextField } from '../TextField/TextField';
3
+ export var Mask = /*#__PURE__*/composeMask(TextField);