@salutejs/plasma-new-hope 0.139.0-canary.1417.10685487591.0 → 0.139.0-canary.1418.10685382771.0
Sign up to get free protection for your applications and to get access to all the features.
- package/emotion/cjs/components/Mask/Mask.js +233 -0
- package/emotion/cjs/components/Mask/Mask.types.js +5 -0
- package/emotion/cjs/components/Mask/index.js +12 -0
- package/emotion/cjs/components/Mask/utils/constants.js +30 -0
- package/emotion/cjs/components/Mask/utils/createMask.js +53 -0
- package/emotion/cjs/components/Mask/utils/maskUtils.js +256 -0
- package/emotion/cjs/components/Mask/utils/parseMask.js +36 -0
- package/emotion/cjs/components/Mask/utils/processInput.js +52 -0
- package/emotion/cjs/components/Mask/utils/processMask.js +99 -0
- package/emotion/cjs/components/Mask/utils/selection.js +48 -0
- package/emotion/cjs/components/Mask/utils/types/input.types.js +5 -0
- package/emotion/cjs/components/Mask/utils/types/mask.types.js +5 -0
- package/emotion/cjs/components/Mask/utils/types/selectRange.types.js +5 -0
- package/emotion/cjs/examples/plasma_b2c/components/Mask/Mask.js +9 -0
- package/emotion/cjs/examples/plasma_b2c/components/Mask/Mask.stories.tsx +131 -0
- package/emotion/es/components/Mask/Mask.js +225 -0
- package/emotion/es/components/Mask/Mask.types.js +1 -0
- package/emotion/es/components/Mask/index.js +1 -0
- package/emotion/es/components/Mask/utils/constants.js +24 -0
- package/emotion/es/components/Mask/utils/createMask.js +47 -0
- package/emotion/es/components/Mask/utils/maskUtils.js +250 -0
- package/emotion/es/components/Mask/utils/parseMask.js +30 -0
- package/emotion/es/components/Mask/utils/processInput.js +46 -0
- package/emotion/es/components/Mask/utils/processMask.js +93 -0
- package/emotion/es/components/Mask/utils/selection.js +42 -0
- package/emotion/es/components/Mask/utils/types/input.types.js +1 -0
- package/emotion/es/components/Mask/utils/types/mask.types.js +1 -0
- package/emotion/es/components/Mask/utils/types/selectRange.types.js +1 -0
- package/emotion/es/examples/plasma_b2c/components/Mask/Mask.js +3 -0
- package/emotion/es/examples/plasma_b2c/components/Mask/Mask.stories.tsx +131 -0
- package/package.json +4 -4
- package/styled-components/cjs/components/Mask/Mask.js +233 -0
- package/styled-components/cjs/components/Mask/Mask.types.js +5 -0
- package/styled-components/cjs/components/Mask/index.js +12 -0
- package/styled-components/cjs/components/Mask/utils/constants.js +30 -0
- package/styled-components/cjs/components/Mask/utils/createMask.js +53 -0
- package/styled-components/cjs/components/Mask/utils/maskUtils.js +256 -0
- package/styled-components/cjs/components/Mask/utils/parseMask.js +36 -0
- package/styled-components/cjs/components/Mask/utils/processInput.js +52 -0
- package/styled-components/cjs/components/Mask/utils/processMask.js +99 -0
- package/styled-components/cjs/components/Mask/utils/selection.js +48 -0
- package/styled-components/cjs/components/Mask/utils/types/input.types.js +5 -0
- package/styled-components/cjs/components/Mask/utils/types/mask.types.js +5 -0
- package/styled-components/cjs/components/Mask/utils/types/selectRange.types.js +5 -0
- package/styled-components/cjs/examples/plasma_b2c/components/Mask/Mask.js +9 -0
- package/styled-components/cjs/examples/plasma_b2c/components/Mask/Mask.stories.tsx +131 -0
- package/styled-components/es/components/Mask/Mask.js +225 -0
- package/styled-components/es/components/Mask/Mask.types.js +1 -0
- package/styled-components/es/components/Mask/index.js +1 -0
- package/styled-components/es/components/Mask/utils/constants.js +24 -0
- package/styled-components/es/components/Mask/utils/createMask.js +47 -0
- package/styled-components/es/components/Mask/utils/maskUtils.js +250 -0
- package/styled-components/es/components/Mask/utils/parseMask.js +30 -0
- package/styled-components/es/components/Mask/utils/processInput.js +46 -0
- package/styled-components/es/components/Mask/utils/processMask.js +93 -0
- package/styled-components/es/components/Mask/utils/selection.js +42 -0
- package/styled-components/es/components/Mask/utils/types/input.types.js +1 -0
- package/styled-components/es/components/Mask/utils/types/mask.types.js +1 -0
- package/styled-components/es/components/Mask/utils/types/selectRange.types.js +1 -0
- package/styled-components/es/examples/plasma_b2c/components/Mask/Mask.js +3 -0
- package/styled-components/es/examples/plasma_b2c/components/Mask/Mask.stories.tsx +131 -0
- package/types/components/Mask/Mask.d.ts +5 -0
- package/types/components/Mask/Mask.d.ts.map +1 -0
- package/types/components/Mask/Mask.types.d.ts +52 -0
- package/types/components/Mask/Mask.types.d.ts.map +1 -0
- package/types/components/Mask/index.d.ts +3 -0
- package/types/components/Mask/index.d.ts.map +1 -0
- package/types/components/Mask/utils/constants.d.ts +15 -0
- package/types/components/Mask/utils/constants.d.ts.map +1 -0
- package/types/components/Mask/utils/createMask.d.ts +12 -0
- package/types/components/Mask/utils/createMask.d.ts.map +1 -0
- package/types/components/Mask/utils/maskUtils.d.ts +45 -0
- package/types/components/Mask/utils/maskUtils.d.ts.map +1 -0
- package/types/components/Mask/utils/parseMask.d.ts +3 -0
- package/types/components/Mask/utils/parseMask.d.ts.map +1 -0
- package/types/components/Mask/utils/processInput.d.ts +15 -0
- package/types/components/Mask/utils/processInput.d.ts.map +1 -0
- package/types/components/Mask/utils/processMask.d.ts +9 -0
- package/types/components/Mask/utils/processMask.d.ts.map +1 -0
- package/types/components/Mask/utils/selection.d.ts +11 -0
- package/types/components/Mask/utils/selection.d.ts.map +1 -0
- package/types/components/Mask/utils/types/input.types.d.ts +52 -0
- package/types/components/Mask/utils/types/input.types.d.ts.map +1 -0
- package/types/components/Mask/utils/types/mask.types.d.ts +9 -0
- package/types/components/Mask/utils/types/mask.types.d.ts.map +1 -0
- package/types/components/Mask/utils/types/selectRange.types.d.ts +5 -0
- package/types/components/Mask/utils/types/selectRange.types.d.ts.map +1 -0
- package/types/examples/plasma_b2c/components/Mask/Mask.d.ts +87 -0
- package/types/examples/plasma_b2c/components/Mask/Mask.d.ts.map +1 -0
@@ -0,0 +1,250 @@
|
|
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 { CharTypes } from './constants';
|
9
|
+
import { parseMask } from './parseMask';
|
10
|
+
import { processInput } from './processInput';
|
11
|
+
import { removeSelectedRange } from './selection';
|
12
|
+
export var MaskUtils = /*#__PURE__*/function () {
|
13
|
+
function MaskUtils(showPrefix, maskChar, maskString, reformat) {
|
14
|
+
_classCallCheck(this, MaskUtils);
|
15
|
+
_defineProperty(this, "maskFormatMap", void 0);
|
16
|
+
_defineProperty(this, "selection", void 0);
|
17
|
+
_defineProperty(this, "value", void 0);
|
18
|
+
_defineProperty(this, "maskedValue", void 0);
|
19
|
+
_defineProperty(this, "visibleValue", void 0);
|
20
|
+
_defineProperty(this, "mask", void 0);
|
21
|
+
_defineProperty(this, "maskChar", void 0);
|
22
|
+
_defineProperty(this, "maskString", void 0);
|
23
|
+
_defineProperty(this, "showPrefix", void 0);
|
24
|
+
_defineProperty(this, "callbacks", void 0);
|
25
|
+
_defineProperty(this, "reformat", void 0);
|
26
|
+
this.maskFormatMap = {};
|
27
|
+
this.selection = {
|
28
|
+
start: 0,
|
29
|
+
end: 0
|
30
|
+
};
|
31
|
+
this.value = '';
|
32
|
+
this.maskedValue = '';
|
33
|
+
this.visibleValue = '';
|
34
|
+
this.mask = [];
|
35
|
+
this.showPrefix = showPrefix;
|
36
|
+
this.callbacks = [];
|
37
|
+
this.maskChar = maskChar;
|
38
|
+
this.maskString = maskString;
|
39
|
+
this.reformat = reformat;
|
40
|
+
}
|
41
|
+
return _createClass(MaskUtils, [{
|
42
|
+
key: "setShowStartChars",
|
43
|
+
set: function set(show) {
|
44
|
+
this.showPrefix = show;
|
45
|
+
}
|
46
|
+
}, {
|
47
|
+
key: "setMaskFormat",
|
48
|
+
set: function set(maskFormat) {
|
49
|
+
if (!maskFormat) {
|
50
|
+
return;
|
51
|
+
}
|
52
|
+
this.maskFormatMap = maskFormat.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: "setSelection",
|
70
|
+
set: function set(newSelection) {
|
71
|
+
this.selection = newSelection;
|
72
|
+
}
|
73
|
+
}, {
|
74
|
+
key: "setValue",
|
75
|
+
set: function set(data) {
|
76
|
+
var result;
|
77
|
+
if (this.reformat) {
|
78
|
+
result = this.reformat({
|
79
|
+
value: data,
|
80
|
+
selection: this.selection
|
81
|
+
});
|
82
|
+
} else {
|
83
|
+
var dataList;
|
84
|
+
if (Array.isArray(data)) {
|
85
|
+
dataList = data;
|
86
|
+
} else {
|
87
|
+
dataList = [];
|
88
|
+
for (var i = 0; i < data.length; i++) {
|
89
|
+
dataList.push({
|
90
|
+
"char": data[i],
|
91
|
+
type: CharTypes.USER
|
92
|
+
});
|
93
|
+
}
|
94
|
+
}
|
95
|
+
result = processInput({
|
96
|
+
data: dataList,
|
97
|
+
selection: this.selection,
|
98
|
+
mask: this.mask,
|
99
|
+
maskChar: this.maskChar,
|
100
|
+
maskString: this.maskString,
|
101
|
+
showPrefix: this.showPrefix
|
102
|
+
});
|
103
|
+
}
|
104
|
+
this.applyChanges(result);
|
105
|
+
}
|
106
|
+
}, {
|
107
|
+
key: "getState",
|
108
|
+
value: function getState() {
|
109
|
+
return {
|
110
|
+
value: this.value,
|
111
|
+
maskedValue: this.maskedValue,
|
112
|
+
visibleValue: this.visibleValue,
|
113
|
+
selection: this.selection
|
114
|
+
};
|
115
|
+
}
|
116
|
+
}, {
|
117
|
+
key: "setMask",
|
118
|
+
value: function setMask(newMask) {
|
119
|
+
this.mask = parseMask(newMask, this.maskFormatMap);
|
120
|
+
this.setValue = this.value;
|
121
|
+
}
|
122
|
+
}, {
|
123
|
+
key: "setMaskChar",
|
124
|
+
value: function setMaskChar(newMaskChar) {
|
125
|
+
if (this.maskChar.length > 1) {
|
126
|
+
throw new Error('maskChar must have only 1 char');
|
127
|
+
}
|
128
|
+
this.maskChar = newMaskChar;
|
129
|
+
this.setValue = this.value;
|
130
|
+
}
|
131
|
+
}, {
|
132
|
+
key: "setMaskString",
|
133
|
+
value: function setMaskString(newMaskString) {
|
134
|
+
if (newMaskString && newMaskString.length !== this.mask.length) {
|
135
|
+
throw new Error('maskString must have the same length as mask');
|
136
|
+
}
|
137
|
+
this.maskString = newMaskString;
|
138
|
+
this.setValue = this.value;
|
139
|
+
}
|
140
|
+
}, {
|
141
|
+
key: "setReformat",
|
142
|
+
value: function setReformat(newReformat) {
|
143
|
+
this.reformat = newReformat;
|
144
|
+
this.setValue = this.value;
|
145
|
+
}
|
146
|
+
}, {
|
147
|
+
key: "backspace",
|
148
|
+
value: function backspace() {
|
149
|
+
this.removePreviosOrSelected();
|
150
|
+
}
|
151
|
+
}, {
|
152
|
+
key: "removePreviosOrSelected",
|
153
|
+
value: function removePreviosOrSelected() {
|
154
|
+
var _this$selection2 = this.selection,
|
155
|
+
start = _this$selection2.start,
|
156
|
+
end = _this$selection2.end;
|
157
|
+
if (start === end) {
|
158
|
+
var newStart = end - 1 < 0 ? 0 : end - 1;
|
159
|
+
this.setSelection = {
|
160
|
+
start: newStart,
|
161
|
+
end: end
|
162
|
+
};
|
163
|
+
}
|
164
|
+
this.input('');
|
165
|
+
}
|
166
|
+
}, {
|
167
|
+
key: "removeNextOrSelected",
|
168
|
+
value: function removeNextOrSelected() {
|
169
|
+
var _this$selection3 = this.selection,
|
170
|
+
start = _this$selection3.start,
|
171
|
+
end = _this$selection3.end;
|
172
|
+
if (start === end) {
|
173
|
+
this.setSelection = {
|
174
|
+
start: start,
|
175
|
+
end: end + 1
|
176
|
+
};
|
177
|
+
}
|
178
|
+
this.input('');
|
179
|
+
}
|
180
|
+
}, {
|
181
|
+
key: "subscribe",
|
182
|
+
value: function subscribe(callback) {
|
183
|
+
this.callbacks.push(callback);
|
184
|
+
}
|
185
|
+
}, {
|
186
|
+
key: "unsubscribe",
|
187
|
+
value: function unsubscribe(callback) {
|
188
|
+
this.callbacks = this.callbacks.filter(function (item) {
|
189
|
+
return item !== callback;
|
190
|
+
});
|
191
|
+
}
|
192
|
+
}, {
|
193
|
+
key: "paste",
|
194
|
+
value: function paste(value) {
|
195
|
+
this.input(value);
|
196
|
+
}
|
197
|
+
}, {
|
198
|
+
key: "input",
|
199
|
+
value: function input(_input) {
|
200
|
+
var result;
|
201
|
+
if (this.reformat) {
|
202
|
+
result = this.reformat({
|
203
|
+
value: this.value,
|
204
|
+
input: _input,
|
205
|
+
selection: this.selection
|
206
|
+
});
|
207
|
+
} else {
|
208
|
+
var tmpValue = removeSelectedRange({
|
209
|
+
value: this.value,
|
210
|
+
selection: this.selection,
|
211
|
+
maskChar: this.maskChar,
|
212
|
+
maskString: String(this.maskString)
|
213
|
+
});
|
214
|
+
this.selection.end = this.selection.start;
|
215
|
+
result = processInput({
|
216
|
+
data: tmpValue,
|
217
|
+
input: _input,
|
218
|
+
selection: this.selection,
|
219
|
+
mask: this.mask,
|
220
|
+
maskChar: this.maskChar,
|
221
|
+
maskString: this.maskString,
|
222
|
+
showPrefix: this.showPrefix
|
223
|
+
});
|
224
|
+
}
|
225
|
+
this.applyChanges(result);
|
226
|
+
}
|
227
|
+
}, {
|
228
|
+
key: "applyChanges",
|
229
|
+
value: function applyChanges(result) {
|
230
|
+
var oldMaskedValue = this.maskedValue;
|
231
|
+
var oldVisibleValue = this.visibleValue;
|
232
|
+
var oldSelection = this.selection;
|
233
|
+
this.value = result.value;
|
234
|
+
this.maskedValue = result.maskedValue;
|
235
|
+
this.visibleValue = result.visibleValue;
|
236
|
+
this.setSelection = result.selection;
|
237
|
+
if (oldMaskedValue !== this.maskedValue || oldVisibleValue !== this.visibleValue || oldSelection.start !== this.selection.start || oldSelection.end !== this.selection.end) {
|
238
|
+
this.notify();
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}, {
|
242
|
+
key: "notify",
|
243
|
+
value: function notify() {
|
244
|
+
var state = this.getState();
|
245
|
+
this.callbacks.forEach(function (callback) {
|
246
|
+
callback(state);
|
247
|
+
});
|
248
|
+
}
|
249
|
+
}]);
|
250
|
+
}();
|
@@ -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 { CharTypes } 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 !== CharTypes.USER) {
|
22
|
+
if (value[bound].type === CharTypes.MASK) {
|
23
|
+
charsCount = 0;
|
24
|
+
}
|
25
|
+
if (value[bound].type === CharTypes.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 { CharTypes } 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
|
+
function processMaskPartAsChar(maskPart, pastedValuesStack, item) {
|
9
|
+
if (pastedValuesStack && pastedValuesStack[0] === maskPart["char"]) {
|
10
|
+
pastedIndex++;
|
11
|
+
} else if (item && (item["char"] === maskPart["char"] || item.type !== CharTypes.USER) || input) {
|
12
|
+
valueIndex++;
|
13
|
+
}
|
14
|
+
value.push({
|
15
|
+
"char": String(maskPart["char"]),
|
16
|
+
type: CharTypes.CHAR
|
17
|
+
});
|
18
|
+
if (pastedValuesStack) {
|
19
|
+
inputValuesApplied++;
|
20
|
+
}
|
21
|
+
maskedValue += maskPart["char"];
|
22
|
+
}
|
23
|
+
function processMaskPartAsRegExp(maskPart, maskIndex, pastedValuesStack, item) {
|
24
|
+
var _maskPart$regexp2;
|
25
|
+
var part = null;
|
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: CharTypes.USER
|
41
|
+
});
|
42
|
+
maskedValue += part;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
if (part) {
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
if (item && item.type === CharTypes.CHAR && data.length > valueIndex + 1) {
|
49
|
+
valueIndex++;
|
50
|
+
processMaskItem(maskPart, maskIndex);
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
if (item && item.type === CharTypes.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: CharTypes.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: CharTypes.MASK
|
66
|
+
});
|
67
|
+
if (data.length > maskIndex) {
|
68
|
+
valueIndex++;
|
69
|
+
}
|
70
|
+
maskedValue += part;
|
71
|
+
}
|
72
|
+
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 { CharTypes } 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: CharTypes.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: CharTypes.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
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,131 @@
|
|
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
|
+
const onValueChange = action('onValueChange');
|
12
|
+
|
13
|
+
const sizes = ['l', 'm', 's', 'xs'];
|
14
|
+
const views = ['default', 'positive', 'warning', 'negative'];
|
15
|
+
|
16
|
+
const meta: Meta<typeof Mask> = {
|
17
|
+
title: 'plasma_b2c/Mask',
|
18
|
+
component: Mask,
|
19
|
+
decorators: [WithTheme],
|
20
|
+
argTypes: {
|
21
|
+
view: {
|
22
|
+
options: views,
|
23
|
+
control: {
|
24
|
+
type: 'select',
|
25
|
+
},
|
26
|
+
},
|
27
|
+
size: {
|
28
|
+
options: sizes,
|
29
|
+
control: {
|
30
|
+
type: 'inline-radio',
|
31
|
+
},
|
32
|
+
},
|
33
|
+
},
|
34
|
+
};
|
35
|
+
|
36
|
+
export default meta;
|
37
|
+
|
38
|
+
type StoryPropsDefault = Omit<
|
39
|
+
ComponentProps<typeof Mask>,
|
40
|
+
| 'helperBlock'
|
41
|
+
| 'contentLeft'
|
42
|
+
| 'htmlSize'
|
43
|
+
| 'contentRight'
|
44
|
+
| 'type'
|
45
|
+
| 'name'
|
46
|
+
| 'onFocus'
|
47
|
+
| 'onBlur'
|
48
|
+
| 'onChange'
|
49
|
+
| 'value'
|
50
|
+
| 'checked'
|
51
|
+
| 'maxLength'
|
52
|
+
| 'minLength'
|
53
|
+
| 'required'
|
54
|
+
| 'enumerationType'
|
55
|
+
| 'chips'
|
56
|
+
| 'onChangeChips'
|
57
|
+
>;
|
58
|
+
|
59
|
+
const StoryDemo = ({ view, ...rest }: StoryPropsDefault) => {
|
60
|
+
return (
|
61
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '2rem', width: '50%' }}>
|
62
|
+
<Mask
|
63
|
+
label="Маска телефона"
|
64
|
+
mask="+7 (000) 000 - 0000"
|
65
|
+
maskChar="_"
|
66
|
+
showPrefix={false}
|
67
|
+
view={view}
|
68
|
+
onChange={onChange}
|
69
|
+
onValueChange={onValueChange}
|
70
|
+
{...rest}
|
71
|
+
/>
|
72
|
+
|
73
|
+
<Mask
|
74
|
+
label="Маска телефона: отображается всегда"
|
75
|
+
mask="+7 (000) 000 - 0000"
|
76
|
+
maskChar="_"
|
77
|
+
view={view}
|
78
|
+
alwaysShowMask
|
79
|
+
onChange={onChange}
|
80
|
+
onValueChange={onValueChange}
|
81
|
+
{...rest}
|
82
|
+
/>
|
83
|
+
|
84
|
+
<Mask
|
85
|
+
label="Маска даты"
|
86
|
+
mask="00/00/0000"
|
87
|
+
maskString="DD/MM/YYYY"
|
88
|
+
alwaysShowMask
|
89
|
+
view={view}
|
90
|
+
onChange={onChange}
|
91
|
+
onValueChange={onValueChange}
|
92
|
+
{...rest}
|
93
|
+
/>
|
94
|
+
|
95
|
+
<Mask
|
96
|
+
label="Маска даты: значения по умолчанию"
|
97
|
+
// eslint-disable-next-line no-octal-escape
|
98
|
+
mask="12.\04.0000"
|
99
|
+
maskChar="_"
|
100
|
+
alwaysShowMask
|
101
|
+
view={view}
|
102
|
+
onChange={onChange}
|
103
|
+
onValueChange={onValueChange}
|
104
|
+
{...rest}
|
105
|
+
/>
|
106
|
+
|
107
|
+
<Mask
|
108
|
+
label="Маска времени"
|
109
|
+
mask="00:00"
|
110
|
+
maskChar="_"
|
111
|
+
alwaysShowMask
|
112
|
+
view={view}
|
113
|
+
onChange={onChange}
|
114
|
+
onValueChange={onValueChange}
|
115
|
+
{...rest}
|
116
|
+
/>
|
117
|
+
</div>
|
118
|
+
);
|
119
|
+
};
|
120
|
+
|
121
|
+
export const Default: StoryObj<StoryPropsDefault> = {
|
122
|
+
args: {
|
123
|
+
size: 'l',
|
124
|
+
view: 'default',
|
125
|
+
labelPlacement: 'outer',
|
126
|
+
placeholder: 'Заполните поле',
|
127
|
+
disabled: false,
|
128
|
+
readOnly: false,
|
129
|
+
},
|
130
|
+
render: (args) => <StoryDemo {...args} />,
|
131
|
+
};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import type { FC } from 'react';
|
3
|
+
import type { MaskProps } from './Mask.types';
|
4
|
+
export declare const composeMask: <T extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">>(InputComponent: React.FC<T>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<T & MaskProps> & React.RefAttributes<HTMLInputElement>>;
|
5
|
+
//# sourceMappingURL=Mask.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Mask.d.ts","sourceRoot":"","sources":["../../../src/components/Mask/Mask.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwE,MAAM,OAAO,CAAC;AAC7F,OAAO,KAAK,EAAe,EAAE,EAAmC,MAAM,OAAO,CAAC;AAG9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAK9C,eAAO,MAAM,WAAW,qNA8OlB,CAAC"}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import type { ReformatFn } from './utils/types/input.types';
|
2
|
+
export declare type MaskProps = {
|
3
|
+
/**
|
4
|
+
* Маска.
|
5
|
+
* Поддерживаются следующие символы:
|
6
|
+
* 0 — любая цифра 0-9
|
7
|
+
* * — любой символ
|
8
|
+
* a — A-Z, a-z
|
9
|
+
* я — А-Я, а-я, ё, Ё
|
10
|
+
* q — буква "q"
|
11
|
+
* 2 — цифра "2"
|
12
|
+
* \a — "\" - символ экранирования; "a" - буква
|
13
|
+
*/
|
14
|
+
mask?: string;
|
15
|
+
/**
|
16
|
+
* Символ маскирования.
|
17
|
+
*/
|
18
|
+
maskChar?: string;
|
19
|
+
/**
|
20
|
+
* Строка, которая будет отображена в незаполненную часть маски.
|
21
|
+
* Если передать maskString, то maskChar игнорируется.
|
22
|
+
*/
|
23
|
+
maskString?: string;
|
24
|
+
/**
|
25
|
+
* Отображать ли маску во время ввода.
|
26
|
+
*/
|
27
|
+
showMask?: boolean;
|
28
|
+
/**
|
29
|
+
* Отображать ли маску всегда.
|
30
|
+
*/
|
31
|
+
alwaysShowMask?: boolean;
|
32
|
+
/**
|
33
|
+
* Отображать ли префикс маски. Например у маски телефона "+7"
|
34
|
+
*/
|
35
|
+
showPrefix?: boolean;
|
36
|
+
/**
|
37
|
+
*
|
38
|
+
*/
|
39
|
+
reformat?: ReformatFn;
|
40
|
+
/**
|
41
|
+
*
|
42
|
+
*/
|
43
|
+
onValueChange?: (params: {
|
44
|
+
maskedValue: string;
|
45
|
+
value: string;
|
46
|
+
}) => void;
|
47
|
+
/**
|
48
|
+
*
|
49
|
+
*/
|
50
|
+
getApplyValueCallback?: (fn: (value: string) => void) => void;
|
51
|
+
};
|
52
|
+
//# sourceMappingURL=Mask.types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Mask.types.d.ts","sourceRoot":"","sources":["../../../src/components/Mask/Mask.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,oBAAY,SAAS,GAAG;IACpB;;;;;;;;;;OAUG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACzE;;OAEG;IACH,qBAAqB,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC;CACjE,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Mask/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
|