@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,247 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Mask = void 0;
7
+ var _constants = /*#__PURE__*/require("./constants");
8
+ var _parseMask = /*#__PURE__*/require("./parseMask");
9
+ var _processInput = /*#__PURE__*/require("./processInput");
10
+ var _selection = /*#__PURE__*/require("./selection");
11
+ 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); }
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+ 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); } }
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
+ 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; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
17
+ 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); }
18
+ /**
19
+ * Copyright (c) 2018 Nikita Mostovoy.
20
+ *
21
+ * This source code is licensed under the MIT license found in the
22
+ * LICENSE file in the root directory of this source tree.
23
+ */
24
+ var Mask = exports.Mask = /*#__PURE__*/function () {
25
+ function Mask(showPrefix, maskChar, maskString, reformat) {
26
+ _classCallCheck(this, Mask);
27
+ _defineProperty(this, "selection", void 0);
28
+ _defineProperty(this, "value", void 0);
29
+ _defineProperty(this, "maskedValue", void 0);
30
+ _defineProperty(this, "visibleValue", void 0);
31
+ _defineProperty(this, "mask", void 0);
32
+ _defineProperty(this, "maskChar", void 0);
33
+ _defineProperty(this, "maskFormatMap", void 0);
34
+ _defineProperty(this, "showPrefix", void 0);
35
+ _defineProperty(this, "callbacks", void 0);
36
+ _defineProperty(this, "maskString", void 0);
37
+ _defineProperty(this, "reformat", void 0);
38
+ this.value = '';
39
+ this.mask = [];
40
+ this.maskedValue = '';
41
+ this.visibleValue = '';
42
+ this.selection = {
43
+ start: 0,
44
+ end: 0
45
+ };
46
+ this.callbacks = [];
47
+ this.maskFormatMap = this.parseMaskFormat;
48
+ this.showPrefix = showPrefix;
49
+ this.maskChar = maskChar;
50
+ this.maskString = maskString;
51
+ this.reformat = reformat;
52
+ }
53
+ return _createClass(Mask, [{
54
+ key: "parseMaskFormat",
55
+ get: function get() {
56
+ return _constants.defaultFormatChars.reduce(function (acc, current) {
57
+ acc[String(current.str)] = current;
58
+ return acc;
59
+ }, {});
60
+ }
61
+ }, {
62
+ key: "getSelection",
63
+ get: function get() {
64
+ var _this$selection = this.selection,
65
+ start = _this$selection.start,
66
+ end = _this$selection.end;
67
+ return {
68
+ start: start,
69
+ end: end
70
+ };
71
+ }
72
+ }, {
73
+ key: "getState",
74
+ get: function get() {
75
+ return {
76
+ value: this.value,
77
+ maskedValue: this.maskedValue,
78
+ visibleValue: this.visibleValue,
79
+ selection: this.selection
80
+ };
81
+ }
82
+ }, {
83
+ key: "setSelection",
84
+ set: function set(newSelection) {
85
+ this.selection = newSelection;
86
+ }
87
+ }, {
88
+ key: "setShowStartChars",
89
+ set: function set(show) {
90
+ this.showPrefix = show;
91
+ }
92
+ }, {
93
+ key: "updateMask",
94
+ value: function updateMask(newMask) {
95
+ this.mask = (0, _parseMask.parseMask)(newMask, this.maskFormatMap);
96
+ this.updateValue(this.value);
97
+ }
98
+ }, {
99
+ key: "updateMaskChar",
100
+ value: function updateMaskChar(newMaskChar) {
101
+ if (this.maskChar.length > 1) {
102
+ throw new Error('maskChar должен содержать только 1 символ');
103
+ }
104
+ this.maskChar = newMaskChar;
105
+ this.updateValue(this.value);
106
+ }
107
+ }, {
108
+ key: "updateMaskString",
109
+ value: function updateMaskString(newMaskString) {
110
+ if (newMaskString && newMaskString.length !== this.mask.length) {
111
+ throw new Error('maskString должна иметь такую же длину, как и mask');
112
+ }
113
+ this.maskString = newMaskString;
114
+ this.updateValue(this.value);
115
+ }
116
+ }, {
117
+ key: "updateReformat",
118
+ value: function updateReformat(newReformat) {
119
+ this.reformat = newReformat;
120
+ this.updateValue(this.value);
121
+ }
122
+ }, {
123
+ key: "updateValue",
124
+ value: function updateValue(data) {
125
+ if (this.reformat) {
126
+ var _result = this.reformat({
127
+ value: data,
128
+ selection: this.selection
129
+ });
130
+ return this.applyChanges(_result);
131
+ }
132
+ var dataList = Array.isArray(data) ? data : Array.from(data).reduce(function (acc, _char) {
133
+ acc.push({
134
+ "char": _char,
135
+ type: _constants.charType.User
136
+ });
137
+ return acc;
138
+ }, []);
139
+ var result = (0, _processInput.processInput)({
140
+ data: dataList,
141
+ selection: this.selection,
142
+ mask: this.mask,
143
+ maskChar: this.maskChar,
144
+ maskString: this.maskString,
145
+ showPrefix: this.showPrefix
146
+ });
147
+ this.applyChanges(result);
148
+ }
149
+ }, {
150
+ key: "removePreviousOrSelected",
151
+ value: function removePreviousOrSelected() {
152
+ var _this$selection2 = this.selection,
153
+ start = _this$selection2.start,
154
+ end = _this$selection2.end;
155
+ if (start === end) {
156
+ var newStart = end - 1 < 0 ? 0 : end - 1;
157
+ this.setSelection = {
158
+ start: newStart,
159
+ end: end
160
+ };
161
+ }
162
+ this.input('');
163
+ }
164
+ }, {
165
+ key: "removeNextOrSelected",
166
+ value: function removeNextOrSelected() {
167
+ var _this$selection3 = this.selection,
168
+ start = _this$selection3.start,
169
+ end = _this$selection3.end;
170
+ if (start === end) {
171
+ this.setSelection = {
172
+ start: start,
173
+ end: end + 1
174
+ };
175
+ }
176
+ this.input('');
177
+ }
178
+ }, {
179
+ key: "paste",
180
+ value: function paste(value) {
181
+ this.input(value);
182
+ }
183
+ }, {
184
+ key: "input",
185
+ value: function input(_input) {
186
+ if (this.reformat) {
187
+ var _result2 = this.reformat({
188
+ value: this.value,
189
+ input: _input,
190
+ selection: this.selection
191
+ });
192
+ return this.applyChanges(_result2);
193
+ }
194
+ var tmpValue = (0, _selection.removeSelectedRange)({
195
+ value: this.value,
196
+ selection: this.selection,
197
+ maskChar: this.maskChar,
198
+ maskString: String(this.maskString)
199
+ });
200
+ this.selection.end = this.selection.start;
201
+ var result = (0, _processInput.processInput)({
202
+ data: tmpValue,
203
+ input: _input,
204
+ selection: this.selection,
205
+ mask: this.mask,
206
+ maskChar: this.maskChar,
207
+ maskString: this.maskString,
208
+ showPrefix: this.showPrefix
209
+ });
210
+ this.applyChanges(result);
211
+ }
212
+ }, {
213
+ key: "applyChanges",
214
+ value: function applyChanges(result) {
215
+ var oldMaskedValue = this.maskedValue;
216
+ var oldVisibleValue = this.visibleValue;
217
+ var oldSelection = this.selection;
218
+ this.value = result.value;
219
+ this.maskedValue = result.maskedValue;
220
+ this.visibleValue = result.visibleValue;
221
+ this.setSelection = result.selection;
222
+ if (oldMaskedValue !== this.maskedValue || oldVisibleValue !== this.visibleValue || oldSelection.start !== this.selection.start || oldSelection.end !== this.selection.end) {
223
+ this.notify();
224
+ }
225
+ }
226
+ }, {
227
+ key: "subscribe",
228
+ value: function subscribe(callback) {
229
+ this.callbacks.push(callback);
230
+ }
231
+ }, {
232
+ key: "unsubscribe",
233
+ value: function unsubscribe(callback) {
234
+ this.callbacks = this.callbacks.filter(function (item) {
235
+ return item !== callback;
236
+ });
237
+ }
238
+ }, {
239
+ key: "notify",
240
+ value: function notify() {
241
+ var state = this.getState;
242
+ this.callbacks.forEach(function (callback) {
243
+ callback(state);
244
+ });
245
+ }
246
+ }]);
247
+ }();
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseMask = void 0;
7
+ var _constants = /*#__PURE__*/require("./constants");
8
+ var parseMask = exports.parseMask = function parseMask(mask, format) {
9
+ if (!mask) {
10
+ return [];
11
+ }
12
+ var stack = [];
13
+ var escape = false;
14
+ mask.split('').forEach(function (maskChar) {
15
+ var item = format === null || format === void 0 ? void 0 : format[maskChar];
16
+ if (escape && item) {
17
+ item = undefined;
18
+ escape = false;
19
+ }
20
+ if (!item) {
21
+ if (!escape && maskChar === _constants.escapeChar) {
22
+ escape = true;
23
+ return;
24
+ }
25
+ escape = false;
26
+ stack.push({
27
+ "char": maskChar
28
+ });
29
+ return;
30
+ }
31
+ if (item.regexp) {
32
+ stack.push(item);
33
+ }
34
+ });
35
+ return stack;
36
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.processInput = void 0;
7
+ var _constants = /*#__PURE__*/require("./constants");
8
+ var _processMask2 = /*#__PURE__*/require("./processMask");
9
+ var processInput = exports.processInput = function processInput(args) {
10
+ var data = args.data,
11
+ _args$input = args.input,
12
+ input = _args$input === void 0 ? '' : _args$input,
13
+ selection = args.selection,
14
+ mask = args.mask,
15
+ _args$maskChar = args.maskChar,
16
+ maskChar = _args$maskChar === void 0 ? '' : _args$maskChar,
17
+ _args$maskString = args.maskString,
18
+ maskString = _args$maskString === void 0 ? '' : _args$maskString,
19
+ showPrefix = args.showPrefix;
20
+ var _processMask = (0, _processMask2.processMask)(data, mask, input, maskChar, maskString, selection),
21
+ value = _processMask.value,
22
+ maskedValue = _processMask.maskedValue,
23
+ inputValuesApplied = _processMask.inputValuesApplied;
24
+ var selectionPosition = selection.start + inputValuesApplied;
25
+ var bound = value.length - 1;
26
+ var charsCount = 0;
27
+ while (bound >= 0 && value[bound].type !== _constants.charType.User) {
28
+ if (value[bound].type === _constants.charType.Mask) {
29
+ charsCount = 0;
30
+ }
31
+ if (value[bound].type === _constants.charType.Char) {
32
+ charsCount++;
33
+ }
34
+ bound--;
35
+ }
36
+ if (showPrefix || bound >= 0 || input && input.trim()) {
37
+ bound += charsCount;
38
+ }
39
+ var visibleValue = '';
40
+ for (var i = 0; i <= bound; i++) {
41
+ visibleValue += value[i]["char"];
42
+ }
43
+ return {
44
+ value: value,
45
+ visibleValue: visibleValue,
46
+ maskedValue: maskedValue,
47
+ selection: {
48
+ start: selectionPosition,
49
+ end: selectionPosition
50
+ }
51
+ };
52
+ };
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.processMask = void 0;
7
+ var _constants = /*#__PURE__*/require("./constants");
8
+ var processMask = exports.processMask = function processMask(data, mask, input, maskChar, maskString, selection) {
9
+ var value = [];
10
+ var valueIndex = 0;
11
+ var pastedIndex = 0;
12
+ var maskedValue = '';
13
+ var inputValuesApplied = 0;
14
+ var processMaskPartAsChar = function processMaskPartAsChar(maskPart, pastedValuesStack, item) {
15
+ if (pastedValuesStack && pastedValuesStack[0] === maskPart["char"]) {
16
+ pastedIndex++;
17
+ } else if (item && (item["char"] === maskPart["char"] || item.type !== _constants.charType.User) || input) {
18
+ valueIndex++;
19
+ }
20
+ value.push({
21
+ "char": String(maskPart["char"]),
22
+ type: _constants.charType.Char
23
+ });
24
+ if (pastedValuesStack) {
25
+ inputValuesApplied++;
26
+ }
27
+ maskedValue += maskPart["char"];
28
+ };
29
+ var processMaskPartAsRegExp = function processMaskPartAsRegExp(maskPart, maskIndex, pastedValuesStack, item) {
30
+ var _maskPart$regexp2;
31
+ var part;
32
+ if (pastedValuesStack) {
33
+ var i = 0;
34
+ while (!(maskPart !== null && maskPart !== void 0 && (_maskPart$regexp = maskPart.regexp) !== null && _maskPart$regexp !== void 0 && _maskPart$regexp.test(pastedValuesStack[i])) && pastedValuesStack.length > i) {
35
+ var _maskPart$regexp;
36
+ i++;
37
+ pastedIndex++;
38
+ }
39
+ if (pastedValuesStack.length > i) {
40
+ pastedIndex++;
41
+ inputValuesApplied++;
42
+ valueIndex++;
43
+ part = pastedValuesStack[i];
44
+ value.push({
45
+ "char": part,
46
+ type: _constants.charType.User
47
+ });
48
+ maskedValue += part;
49
+ }
50
+ }
51
+ if (part) {
52
+ return;
53
+ }
54
+ if (item && item.type === _constants.charType.Char && data.length > valueIndex + 1) {
55
+ valueIndex++;
56
+ processMaskItem(maskPart, maskIndex);
57
+ return;
58
+ }
59
+ if (item && item.type === _constants.charType.User && maskPart !== null && maskPart !== void 0 && (_maskPart$regexp2 = maskPart.regexp) !== null && _maskPart$regexp2 !== void 0 && _maskPart$regexp2.test(item["char"])) {
60
+ value.push({
61
+ "char": item["char"],
62
+ type: _constants.charType.User
63
+ });
64
+ maskedValue += item["char"];
65
+ valueIndex++;
66
+ return;
67
+ }
68
+ part = maskString ? maskString[maskIndex] : maskChar;
69
+ value.push({
70
+ "char": part,
71
+ type: _constants.charType.Mask
72
+ });
73
+ if (data.length > maskIndex) {
74
+ valueIndex++;
75
+ }
76
+ maskedValue += part;
77
+ };
78
+ var processMaskItem = function processMaskItem(maskPart, maskIndex) {
79
+ var item = data.length > valueIndex ? data[valueIndex] : null;
80
+ var pastedValuesStack = '';
81
+ if (selection.start <= maskIndex && pastedIndex < input.length) {
82
+ pastedValuesStack = input.slice(pastedIndex);
83
+ }
84
+ if (maskPart["char"]) {
85
+ return processMaskPartAsChar(maskPart, pastedValuesStack, item);
86
+ }
87
+ if (maskPart.regexp) {
88
+ return processMaskPartAsRegExp(maskPart, maskIndex, pastedValuesStack, item);
89
+ }
90
+ };
91
+ mask.forEach(function (maskPart, maskIndex) {
92
+ processMaskItem(maskPart, maskIndex);
93
+ });
94
+ return {
95
+ value: value,
96
+ maskedValue: maskedValue,
97
+ inputValuesApplied: inputValuesApplied
98
+ };
99
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.removeSelectedRange = void 0;
7
+ var _constants = /*#__PURE__*/require("./constants");
8
+ var copyMaskChar = function copyMaskChar(count, maskChar) {
9
+ var res = [];
10
+ for (var i = 0; i < count; i++) {
11
+ res.push({
12
+ "char": maskChar,
13
+ type: _constants.charType.Mask
14
+ });
15
+ }
16
+ return res;
17
+ };
18
+ var pasteMaskSymbols = function pasteMaskSymbols(maskString, maskChar, selection) {
19
+ if (maskString) {
20
+ var res = [];
21
+ for (var i = selection.start; i < selection.end; i++) {
22
+ res.push({
23
+ "char": maskString[i],
24
+ type: _constants.charType.Mask
25
+ });
26
+ }
27
+ return res;
28
+ }
29
+ return copyMaskChar(selection.end - selection.start, maskChar);
30
+ };
31
+ var removeSelectedRange = exports.removeSelectedRange = function removeSelectedRange(args) {
32
+ var value = args.value,
33
+ selection = args.selection,
34
+ maskChar = args.maskChar,
35
+ maskString = args.maskString;
36
+ if (selection.end < selection.start) {
37
+ var tmp = selection.end;
38
+ selection.end = selection.start;
39
+ selection.start = tmp;
40
+ }
41
+ if (selection.start === selection.end) {
42
+ return value;
43
+ }
44
+ if (value.length > selection.start) {
45
+ return value.slice(0, selection.start).concat(pasteMaskSymbols(maskString, maskChar, selection), value.slice(selection.end, value.length));
46
+ }
47
+ return value;
48
+ };
@@ -158,7 +158,9 @@ var textFieldRoot = exports.textFieldRoot = function textFieldRoot(Root) {
158
158
  };
159
159
  var handleOnKeyDown = function handleOnKeyDown(event) {
160
160
  handleInputKeydown(event);
161
- onKeyDown && onKeyDown(event);
161
+ if (onKeyDown) {
162
+ onKeyDown(event);
163
+ }
162
164
  };
163
165
  (0, _react.useEffect)(function () {
164
166
  if (!isChipEnumeration && !(values !== null && values !== void 0 && values.length)) {
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Mask = void 0;
7
+ var _Mask = /*#__PURE__*/require("../../../../components/Mask");
8
+ var _TextField = /*#__PURE__*/require("../TextField/TextField");
9
+ var Mask = exports.Mask = /*#__PURE__*/(0, _Mask.composeMask)(_TextField.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,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Mask = void 0;
7
+ var _Mask = /*#__PURE__*/require("../../../../components/Mask");
8
+ var _TextField = /*#__PURE__*/require("../TextField/TextField");
9
+ var Mask = exports.Mask = /*#__PURE__*/(0, _Mask.composeMask)(_TextField.TextField);