1 line
10 KiB
JSON
1 line
10 KiB
JSON
|
{"ast":null,"code":"/**\n * Cut input selection into 2 part and return text before selection start\n */\nexport function getBeforeSelectionText(input) {\n var selectionStart = input.selectionStart;\n return input.value.slice(0, selectionStart);\n}\n/**\n * Find the last match prefix index\n */\nexport function getLastMeasureIndex(text, prefix) {\n return prefix.reduce(function (lastMatch, prefixStr) {\n var lastIndex = text.lastIndexOf(prefixStr);\n if (lastIndex > lastMatch.location) {\n return {\n location: lastIndex,\n prefix: prefixStr\n };\n }\n return lastMatch;\n }, {\n location: -1,\n prefix: ''\n });\n}\nfunction lower(char) {\n return (char || '').toLowerCase();\n}\nfunction reduceText(text, targetText, split) {\n var firstChar = text[0];\n if (!firstChar || firstChar === split) {\n return text;\n }\n\n // Reuse rest text as it can\n var restText = text;\n var targetTextLen = targetText.length;\n for (var i = 0; i < targetTextLen; i += 1) {\n if (lower(restText[i]) !== lower(targetText[i])) {\n restText = restText.slice(i);\n break;\n } else if (i === targetTextLen - 1) {\n restText = restText.slice(targetTextLen);\n }\n }\n return restText;\n}\n\n/**\n * Paint targetText into current text:\n * text: little@litest\n * targetText: light\n * => little @light test\n */\nexport function replaceWithMeasure(text, measureConfig) {\n var measureLocation = measureConfig.measureLocation,\n prefix = measureConfig.prefix,\n targetText = measureConfig.targetText,\n selectionStart = measureConfig.selectionStart,\n split = measureConfig.split;\n\n // Before text will append one space if have other text\n var beforeMeasureText = text.slice(0, measureLocation);\n if (beforeMeasureText[beforeMeasureText.length - split.length] === split) {\n beforeMeasureText = beforeMeasureText.slice(0, beforeMeasureText.length - split.length);\n }\n if (beforeMeasureText) {\n beforeMeasureText = \"\".concat(beforeMeasureText).concat(split);\n }\n\n // Cut duplicate string with current targetText\n var restText = reduceText(text.slice(selectionStart), targetText.slice(selectionStart - measureLocation - prefix.length), split);\n if (restText.slice(0, split.length) === split) {\n restText = restText.slice(split.length);\n }\n var connectedStartText = \"\".concat(beforeMeasureText).concat(prefix).concat(targetText).concat(split);\n return {\n text: \"\".concat(connectedStartText).concat(restText),\n selectionLocation: connectedStartText.length\n };\n}\nexport function setInputSelection(input, location) {\n input.setSelectionRange(location, location);\n\n /**\n * Reset caret into view.\n * Since this function always called by user control, it's safe to focus element.\n */\n input.blur();\n input.focus();\n}\nexport function validateSearch(text, split) {\n return !split || text.indexOf(split) === -1;\n}\nexport function filterOption(input, _ref) {\n var _ref$value = _ref.value,\n value = _ref$value === void 0 ? '' : _ref$value;\n var lowerCase = input.toLowerCase();\n return value.toLowerCase().indexOf(lowerCase) !== -1;\n}","map":{"version":3,"names":["getBeforeSelectionText","input","selectionStart","value","slice","getLastMeasureIndex","text","prefix","reduce","lastMatch","prefixStr","lastIndex","lastIndexOf","location","lower","char","toLowerCase","reduceText","targetText","split","firstChar","restText","targetTextLen","length","i","replaceWithMeasure","measureConfig","measureLocation","beforeMeasureText","concat","connectedStartText","selectionLocation","setInputSelection","setSelectionRange","blur","focus","validateSearch","indexOf","filterOption","_ref","_ref$value","lowerCase"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-mentions/es/util.js"],"sourcesContent":["/**\n * Cut input selection into 2 part and return text before selection start\n */\nexport function getBeforeSelectionText(input) {\n var selectionStart = input.selectionStart;\n return input.value.slice(0, selection
|