1 | import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
2 | export var omit = function omit(obj) {
|
3 | var clone = _objectSpread({}, obj);
|
4 |
|
5 | for (var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
6 | keys[_key - 1] = arguments[_key];
|
7 | }
|
8 |
|
9 | keys.forEach(function (key) {
|
10 | delete clone[key];
|
11 | });
|
12 | return clone;
|
13 | };
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export function getBeforeSelectionText(input) {
|
19 | var selectionStart = input.selectionStart;
|
20 | return input.value.slice(0, selectionStart);
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export function getLastMeasureIndex(text) {
|
27 | var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
28 | var prefixList = Array.isArray(prefix) ? prefix : [prefix];
|
29 | return prefixList.reduce(function (lastMatch, prefixStr) {
|
30 | var lastIndex = text.lastIndexOf(prefixStr);
|
31 |
|
32 | if (lastIndex > lastMatch.location) {
|
33 | return {
|
34 | location: lastIndex,
|
35 | prefix: prefixStr
|
36 | };
|
37 | }
|
38 |
|
39 | return lastMatch;
|
40 | }, {
|
41 | location: -1,
|
42 | prefix: ''
|
43 | });
|
44 | }
|
45 |
|
46 | function lower(char) {
|
47 | return (char || '').toLowerCase();
|
48 | }
|
49 |
|
50 | function reduceText(text, targetText, split) {
|
51 | var firstChar = text[0];
|
52 |
|
53 | if (!firstChar || firstChar === split) {
|
54 | return text;
|
55 | }
|
56 |
|
57 |
|
58 | var restText = text;
|
59 | var targetTextLen = targetText.length;
|
60 |
|
61 | for (var i = 0; i < targetTextLen; i += 1) {
|
62 | if (lower(restText[i]) !== lower(targetText[i])) {
|
63 | restText = restText.slice(i);
|
64 | break;
|
65 | } else if (i === targetTextLen - 1) {
|
66 | restText = restText.slice(targetTextLen);
|
67 | }
|
68 | }
|
69 |
|
70 | return restText;
|
71 | }
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | export function replaceWithMeasure(text, measureConfig) {
|
81 | var measureLocation = measureConfig.measureLocation,
|
82 | prefix = measureConfig.prefix,
|
83 | targetText = measureConfig.targetText,
|
84 | selectionStart = measureConfig.selectionStart,
|
85 | split = measureConfig.split;
|
86 |
|
87 | var beforeMeasureText = text.slice(0, measureLocation);
|
88 |
|
89 | if (beforeMeasureText[beforeMeasureText.length - split.length] === split) {
|
90 | beforeMeasureText = beforeMeasureText.slice(0, beforeMeasureText.length - split.length);
|
91 | }
|
92 |
|
93 | if (beforeMeasureText) {
|
94 | beforeMeasureText = "".concat(beforeMeasureText).concat(split);
|
95 | }
|
96 |
|
97 |
|
98 | var restText = reduceText(text.slice(selectionStart), targetText.slice(selectionStart - measureLocation - prefix.length), split);
|
99 |
|
100 | if (restText.slice(0, split.length) === split) {
|
101 | restText = restText.slice(split.length);
|
102 | }
|
103 |
|
104 | var connectedStartText = "".concat(beforeMeasureText).concat(prefix).concat(targetText).concat(split);
|
105 | return {
|
106 | text: "".concat(connectedStartText).concat(restText),
|
107 | selectionLocation: connectedStartText.length
|
108 | };
|
109 | }
|
110 | export function setInputSelection(input, location) {
|
111 | input.setSelectionRange(location, location);
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 | input.blur();
|
118 | input.focus();
|
119 | }
|
120 | export function validateSearch(text, props) {
|
121 | var split = props.split;
|
122 | return !split || text.indexOf(split) === -1;
|
123 | }
|
124 | export function filterOption(input, _ref) {
|
125 | var _ref$value = _ref.value,
|
126 | value = _ref$value === void 0 ? '' : _ref$value;
|
127 | var lowerCase = input.toLowerCase();
|
128 | return value.toLowerCase().indexOf(lowerCase) !== -1;
|
129 | } |
\ | No newline at end of file |