From eaa07e42b991b73f234345a6ca024c80844b07db Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 15:51:54 -0400 Subject: [PATCH 01/10] adding onChangePartsData event --- package.json | 4 +++ src/components/mention-input.tsx | 62 ++++++++++++++++++++++++++++---- src/types/types.ts | 11 ++++-- 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 8025612..3c682a8 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,10 @@ "url": "git+https://github.com/dabakovich/react-native-controlled-mentions.git" }, "author": "David Tabaka ", + "contributors": [ + "David Tabaka", + "Denifer Santiago" + ], "license": "MIT", "devDependencies": { "@types/diff": "^4.0.2", diff --git a/src/components/mention-input.tsx b/src/components/mention-input.tsx index 5be83d4..69cfea9 100644 --- a/src/components/mention-input.tsx +++ b/src/components/mention-input.tsx @@ -4,10 +4,10 @@ import { Text, TextInput, TextInputSelectionChangeEventData, - View, + View } from 'react-native'; -import { MentionInputProps, MentionPartType, Suggestion } from '../types'; +import { MentionInputProps, MentionPartType, Suggestion, PartData, Part } from '../types'; import { defaultMentionTextStyle, generateValueFromPartsAndChangedText, @@ -16,7 +16,13 @@ import { isMentionPartType, parseValue, } from '../utils'; - +const AddOrEdit = (arr: S[], val: S, i: number) => { + if(i === -1) { + arr.push(val); + } else { + arr[i] = val; + } +} const MentionInput: FC = ( { value, @@ -29,13 +35,14 @@ const MentionInput: FC = ( containerStyle, onSelectionChange, - + onChangePartsData, ...textInputProps - }, + } : MentionInputProps, ) => { const textInput = useRef(null); const [selection, setSelection] = useState({start: 0, end: 0}); + const [partsData, setPartsData] = useState([]); const { plainText, @@ -54,9 +61,38 @@ const MentionInput: FC = ( * @param changedText */ const onChangeInput = (changedText: string) => { - onChange(generateValueFromPartsAndChangedText(parts, plainText, changedText)); + const newValue = generateValueFromPartsAndChangedText(parts, plainText, changedText); + const { parts: newParts } = parseValue(newValue, partTypes); + partDataHasChanged(newParts); + onChange(newValue); + }; + /** + * Determines when the onChangePartsData event should triggerred + * @param newParts + */ + const partDataHasChanged = (newParts: Part[]) => { + const partsWithData = newParts.filter(part => part.partType); + const newPartsData = partsWithData.reduce((acc, part) => { + const id = part.data?.id; + const name = part.data?.name; + const data = partsData.find(pd => pd.id === id); + const accI = acc.findIndex(ad => ad.id === id); + const lastValue = acc[accI]; + const val = { cant: (lastValue?.cant ?? 0) + 1, data, id, name } as PartData; + AddOrEdit(acc, val, accI); + return acc; + }, [] as PartData[]); + const eventMustBeTriggered = newPartsData.length !== partsData.length + || newPartsData.some(npd => partsData.find(pd => pd.id === npd.id)?.cant !== npd.cant); + if(eventMustBeTriggered) + ChangePartsData(newPartsData); + }; + const ChangePartsData = (newPartsData: PartData[]) => { + setPartsData(newPartsData); + if(typeof onChangePartsData === 'function'){ + onChangePartsData(newPartsData); + } }; - /** * We memoize the keyword to know should we show mention suggestions or not */ @@ -86,6 +122,18 @@ const MentionInput: FC = ( if (!newValue) { return; } + // + const copyPartsData = [...partsData]; + const i = copyPartsData.findIndex(ad => ad.id === suggestion.id); + const lastValue = copyPartsData[i]; + const val = { + cant: (lastValue?.cant ?? 0) + 1, + data: suggestion, + id: suggestion.id, + name: suggestion.name + } as PartData; + AddOrEdit(copyPartsData, val, i); + ChangePartsData(copyPartsData); onChange(newValue); diff --git a/src/types/types.ts b/src/types/types.ts index 5ec7d99..9f8e761 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -13,6 +13,12 @@ type MentionData = { name: string; id: string; }; +type PartData = { + name: string; + id: string; + cant: number; + data: any; +}; type CharactersDiffChange = Omit & { count: number }; @@ -93,8 +99,8 @@ type Part = { type MentionInputProps = Omit & { value: string; - onChange: (value: string) => any; - + onChange: (value: string) => void; + onChangePartsData: (partsData: PartData[]) => void; partTypes?: PartType[]; inputRef?: Ref; @@ -114,4 +120,5 @@ export type { PatternPartType, PartType, MentionInputProps, + PartData }; From a9fb467bf463332adbf9409053f07a060c720a11 Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 16:06:36 -0400 Subject: [PATCH 02/10] Adding dist to testing --- .gitignore | 1 - dist/components/index.d.ts | 1 + dist/components/index.js | 14 + dist/components/index.js.map | 1 + dist/components/mention-input.d.ts | 4 + dist/components/mention-input.js | 169 ++++++++++++ dist/components/mention-input.js.map | 1 + dist/index.d.ts | 3 + dist/index.js | 21 ++ dist/index.js.map | 1 + dist/types/index.d.ts | 1 + dist/types/index.js | 14 + dist/types/index.js.map | 1 + dist/types/types.d.ts | 68 +++++ dist/types/types.js | 3 + dist/types/types.js.map | 1 + dist/utils/index.d.ts | 1 + dist/utils/index.js | 14 + dist/utils/index.js.map | 1 + dist/utils/utils.d.ts | 104 +++++++ dist/utils/utils.js | 389 +++++++++++++++++++++++++++ dist/utils/utils.js.map | 1 + 22 files changed, 813 insertions(+), 1 deletion(-) create mode 100644 dist/components/index.d.ts create mode 100644 dist/components/index.js create mode 100644 dist/components/index.js.map create mode 100644 dist/components/mention-input.d.ts create mode 100644 dist/components/mention-input.js create mode 100644 dist/components/mention-input.js.map create mode 100644 dist/index.d.ts create mode 100644 dist/index.js create mode 100644 dist/index.js.map create mode 100644 dist/types/index.d.ts create mode 100644 dist/types/index.js create mode 100644 dist/types/index.js.map create mode 100644 dist/types/types.d.ts create mode 100644 dist/types/types.js create mode 100644 dist/types/types.js.map create mode 100644 dist/utils/index.d.ts create mode 100644 dist/utils/index.js create mode 100644 dist/utils/index.js.map create mode 100644 dist/utils/utils.d.ts create mode 100644 dist/utils/utils.js create mode 100644 dist/utils/utils.js.map diff --git a/.gitignore b/.gitignore index 6d5f090..d6f2790 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ # .idea node_modules/ -dist npm-debug.log yarn-error.log diff --git a/dist/components/index.d.ts b/dist/components/index.d.ts new file mode 100644 index 0000000..31174cf --- /dev/null +++ b/dist/components/index.d.ts @@ -0,0 +1 @@ +export * from './mention-input'; diff --git a/dist/components/index.js b/dist/components/index.js new file mode 100644 index 0000000..8dc1254 --- /dev/null +++ b/dist/components/index.js @@ -0,0 +1,14 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./mention-input"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/components/index.js.map b/dist/components/index.js.map new file mode 100644 index 0000000..473e91b --- /dev/null +++ b/dist/components/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC"} \ No newline at end of file diff --git a/dist/components/mention-input.d.ts b/dist/components/mention-input.d.ts new file mode 100644 index 0000000..a6fcb73 --- /dev/null +++ b/dist/components/mention-input.d.ts @@ -0,0 +1,4 @@ +import { FC } from 'react'; +import { MentionInputProps } from '../types'; +declare const MentionInput: FC; +export { MentionInput }; diff --git a/dist/components/mention-input.js b/dist/components/mention-input.js new file mode 100644 index 0000000..c924515 --- /dev/null +++ b/dist/components/mention-input.js @@ -0,0 +1,169 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.MentionInput = void 0; +const react_1 = __importStar(require("react")); +const react_native_1 = require("react-native"); +const utils_1 = require("../utils"); +const AddOrEdit = (arr, val, i) => { + if (i === -1) { + arr.push(val); + } + else { + arr[i] = val; + } +}; +const MentionInput = (_a) => { + var { value, onChange, partTypes = [], inputRef: propInputRef, containerStyle, onSelectionChange, onChangePartsData } = _a, textInputProps = __rest(_a, ["value", "onChange", "partTypes", "inputRef", "containerStyle", "onSelectionChange", "onChangePartsData"]); + const textInput = react_1.useRef(null); + const [selection, setSelection] = react_1.useState({ start: 0, end: 0 }); + const [partsData, setPartsData] = react_1.useState([]); + const { plainText, parts, } = react_1.useMemo(() => utils_1.parseValue(value, partTypes), [value, partTypes]); + const handleSelectionChange = (event) => { + setSelection(event.nativeEvent.selection); + onSelectionChange && onSelectionChange(event); + }; + /** + * Callback that trigger on TextInput text change + * + * @param changedText + */ + const onChangeInput = (changedText) => { + const newValue = utils_1.generateValueFromPartsAndChangedText(parts, plainText, changedText); + const { parts: newParts } = utils_1.parseValue(newValue, partTypes); + partDataHasChanged(newParts); + onChange(newValue); + }; + /** + * Determines when the onChangePartsData event should triggerred + * @param newParts + */ + const partDataHasChanged = (newParts) => { + const partsWithData = newParts.filter(part => part.partType); + const newPartsData = partsWithData.reduce((acc, part) => { + var _a, _b, _c; + const id = (_a = part.data) === null || _a === void 0 ? void 0 : _a.id; + const name = (_b = part.data) === null || _b === void 0 ? void 0 : _b.name; + const data = partsData.find(pd => pd.id === id); + const accI = acc.findIndex(ad => ad.id === id); + const lastValue = acc[accI]; + const val = { cant: ((_c = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _c !== void 0 ? _c : 0) + 1, data, id, name }; + AddOrEdit(acc, val, accI); + return acc; + }, []); + const eventMustBeTriggered = newPartsData.length !== partsData.length + || newPartsData.some(npd => { var _a; return ((_a = partsData.find(pd => pd.id === npd.id)) === null || _a === void 0 ? void 0 : _a.cant) !== npd.cant; }); + if (eventMustBeTriggered) + ChangePartsData(newPartsData); + }; + const ChangePartsData = (newPartsData) => { + setPartsData(newPartsData); + if (typeof onChangePartsData === 'function') { + onChangePartsData(newPartsData); + } + }; + /** + * We memoize the keyword to know should we show mention suggestions or not + */ + const keywordByTrigger = react_1.useMemo(() => { + return utils_1.getMentionPartSuggestionKeywords(parts, plainText, selection, partTypes); + }, [parts, plainText, selection, partTypes]); + /** + * Callback on mention suggestion press. We should: + * - Get updated value + * - Trigger onChange callback with new value + */ + const onSuggestionPress = (mentionType) => (suggestion) => { + var _a; + const newValue = utils_1.generateValueWithAddedSuggestion(parts, mentionType, plainText, selection, suggestion); + if (!newValue) { + return; + } + // + const copyPartsData = [...partsData]; + const i = copyPartsData.findIndex(ad => ad.id === suggestion.id); + const lastValue = copyPartsData[i]; + const val = { + cant: ((_a = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _a !== void 0 ? _a : 0) + 1, + data: suggestion, + id: suggestion.id, + name: suggestion.name + }; + AddOrEdit(copyPartsData, val, i); + ChangePartsData(copyPartsData); + onChange(newValue); + /** + * Move cursor to the end of just added mention starting from trigger string and including: + * - Length of trigger string + * - Length of mention name + * - Length of space after mention (1) + * + * Not working now due to the RN bug + */ + // const newCursorPosition = currentPart.position.start + triggerPartIndex + trigger.length + + // suggestion.name.length + 1; + // textInput.current?.setNativeProps({selection: {start: newCursorPosition, end: newCursorPosition}}); + }; + const handleTextInputRef = (ref) => { + textInput.current = ref; + if (propInputRef) { + if (typeof propInputRef === 'function') { + propInputRef(ref); + } + else { + propInputRef.current = ref; + } + } + }; + const renderMentionSuggestions = (mentionType) => (react_1.default.createElement(react_1.default.Fragment, { key: mentionType.trigger }, mentionType.renderSuggestions && mentionType.renderSuggestions({ + keyword: keywordByTrigger[mentionType.trigger], + onSuggestionPress: onSuggestionPress(mentionType), + }))); + return (react_1.default.createElement(react_native_1.View, { style: containerStyle }, + partTypes + .filter(one => (utils_1.isMentionPartType(one) + && one.renderSuggestions != null + && !one.isBottomMentionSuggestionsRender)) + .map(renderMentionSuggestions), + react_1.default.createElement(react_native_1.TextInput, Object.assign({ multiline: true }, textInputProps, { ref: handleTextInputRef, onChangeText: onChangeInput, onSelectionChange: handleSelectionChange }), + react_1.default.createElement(react_native_1.Text, null, parts.map(({ text, partType, data }, index) => { + var _a, _b; + return partType ? (react_1.default.createElement(react_native_1.Text, { key: `${index}-${(_a = data === null || data === void 0 ? void 0 : data.trigger) !== null && _a !== void 0 ? _a : 'pattern'}`, style: (_b = partType.textStyle) !== null && _b !== void 0 ? _b : utils_1.defaultMentionTextStyle }, text)) : (react_1.default.createElement(react_native_1.Text, { key: index }, text)); + }))), + partTypes + .filter(one => (utils_1.isMentionPartType(one) + && one.renderSuggestions != null + && one.isBottomMentionSuggestionsRender)) + .map(renderMentionSuggestions))); +}; +exports.MentionInput = MentionInput; +//# sourceMappingURL=mention-input.js.map \ No newline at end of file diff --git a/dist/components/mention-input.js.map b/dist/components/mention-input.js.map new file mode 100644 index 0000000..a81f630 --- /dev/null +++ b/dist/components/mention-input.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mention-input.js","sourceRoot":"","sources":["../../src/components/mention-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA+E;AAC/E,+CAMsB;AAGtB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CAAC,gCAAgC,CACzC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC;QAGhC,8BAAC,wBAAS,kBACR,SAAS,UAEL,cAAc,IAElB,GAAG,EAAE,kBAAkB,EAEvB,YAAY,EAAE,aAAa,EAC3B,iBAAiB,EAAE,qBAAqB;YAExC,8BAAC,mBAAI,QACF,KAAK,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,EAAE,KAAK,EAAE,EAAE;;gBAAC,OAAA,QAAQ,CAAC,CAAC,CAAC,CACvD,8BAAC,mBAAI,IACH,GAAG,EAAE,GAAG,KAAK,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,mCAAI,SAAS,EAAE,EAC7C,KAAK,EAAE,MAAA,QAAQ,CAAC,SAAS,mCAAI,+BAAuB,IAEnD,IAAI,CACA,CACR,CAAC,CAAC,CAAC,CACF,8BAAC,mBAAI,IAAC,GAAG,EAAE,KAAK,IAAG,IAAI,CAAQ,CAChC,CAAA;aAAA,CAAC,CACG,CACG;QAEV,SAAS;aACR,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,GAAG,CAAC,gCAAgC,CACxC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC,CAE3B,CACR,CAAC;AACJ,CAAC,CAAC;AAEO,oCAAY"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..d9a1101 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,3 @@ +export * from './components'; +export type { Suggestion, Part, MentionSuggestionsProps, PartType, } from './types'; +export { mentionRegEx, isMentionPartType, getMentionValue, parseValue, replaceMentionValues, } from './utils'; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..9ece04b --- /dev/null +++ b/dist/index.js @@ -0,0 +1,21 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.replaceMentionValues = exports.parseValue = exports.getMentionValue = exports.isMentionPartType = exports.mentionRegEx = void 0; +__exportStar(require("./components"), exports); +var utils_1 = require("./utils"); +Object.defineProperty(exports, "mentionRegEx", { enumerable: true, get: function () { return utils_1.mentionRegEx; } }); +Object.defineProperty(exports, "isMentionPartType", { enumerable: true, get: function () { return utils_1.isMentionPartType; } }); +Object.defineProperty(exports, "getMentionValue", { enumerable: true, get: function () { return utils_1.getMentionValue; } }); +Object.defineProperty(exports, "parseValue", { enumerable: true, get: function () { return utils_1.parseValue; } }); +Object.defineProperty(exports, "replaceMentionValues", { enumerable: true, get: function () { return utils_1.replaceMentionValues; } }); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000..681fe4b --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAA6B;AAM7B,iCAEiB;AADf,qGAAA,YAAY,OAAA;AAAE,0GAAA,iBAAiB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAAE,mGAAA,UAAU,OAAA;AAAE,6GAAA,oBAAoB,OAAA"} \ No newline at end of file diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts new file mode 100644 index 0000000..fcb073f --- /dev/null +++ b/dist/types/index.d.ts @@ -0,0 +1 @@ +export * from './types'; diff --git a/dist/types/index.js b/dist/types/index.js new file mode 100644 index 0000000..66b0c96 --- /dev/null +++ b/dist/types/index.js @@ -0,0 +1,14 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./types"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/types/index.js.map b/dist/types/index.js.map new file mode 100644 index 0000000..881fa19 --- /dev/null +++ b/dist/types/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB"} \ No newline at end of file diff --git a/dist/types/types.d.ts b/dist/types/types.d.ts new file mode 100644 index 0000000..979e622 --- /dev/null +++ b/dist/types/types.d.ts @@ -0,0 +1,68 @@ +import type { Change } from 'diff'; +import type { ReactNode, Ref } from 'react'; +import type { StyleProp, TextInput, TextInputProps, TextStyle, ViewStyle } from 'react-native'; +declare type Suggestion = { + id: string; + name: string; +}; +declare type MentionData = { + original: string; + trigger: string; + name: string; + id: string; +}; +declare type PartData = { + name: string; + id: string; + cant: number; + data: any; +}; +declare type CharactersDiffChange = Omit & { + count: number; +}; +declare type RegexMatchResult = string[] & { + 0: string; + 1: string; + 2: string; + 3: string; + 4: string; + index: number; + groups: MentionData; +}; +declare type Position = { + start: number; + end: number; +}; +declare type MentionSuggestionsProps = { + keyword: string | undefined; + onSuggestionPress: (suggestion: Suggestion) => void; +}; +declare type MentionPartType = { + trigger: string; + renderSuggestions?: (props: MentionSuggestionsProps) => ReactNode; + allowedSpacesCount?: number; + isInsertSpaceAfterMention?: boolean; + isBottomMentionSuggestionsRender?: boolean; + textStyle?: StyleProp; + getPlainString?: (mention: MentionData) => string; +}; +declare type PatternPartType = { + pattern: RegExp; + textStyle?: StyleProp; +}; +declare type PartType = MentionPartType | PatternPartType; +declare type Part = { + text: string; + position: Position; + partType?: PartType; + data?: MentionData; +}; +declare type MentionInputProps = Omit & { + value: string; + onChange: (value: string) => void; + onChangePartsData: (partsData: PartData[]) => void; + partTypes?: PartType[]; + inputRef?: Ref; + containerStyle?: StyleProp; +}; +export type { Suggestion, MentionData, CharactersDiffChange, RegexMatchResult, Position, Part, MentionSuggestionsProps, MentionPartType, PatternPartType, PartType, MentionInputProps, PartData }; diff --git a/dist/types/types.js b/dist/types/types.js new file mode 100644 index 0000000..11e638d --- /dev/null +++ b/dist/types/types.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/types/types.js.map b/dist/types/types.js.map new file mode 100644 index 0000000..67c6c9d --- /dev/null +++ b/dist/types/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/utils/index.d.ts b/dist/utils/index.d.ts new file mode 100644 index 0000000..04bca77 --- /dev/null +++ b/dist/utils/index.d.ts @@ -0,0 +1 @@ +export * from './utils'; diff --git a/dist/utils/index.js b/dist/utils/index.js new file mode 100644 index 0000000..e6f0868 --- /dev/null +++ b/dist/utils/index.js @@ -0,0 +1,14 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./utils"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/utils/index.js.map b/dist/utils/index.js.map new file mode 100644 index 0000000..b6566c7 --- /dev/null +++ b/dist/utils/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB"} \ No newline at end of file diff --git a/dist/utils/utils.d.ts b/dist/utils/utils.d.ts new file mode 100644 index 0000000..f1880b6 --- /dev/null +++ b/dist/utils/utils.d.ts @@ -0,0 +1,104 @@ +import { StyleProp, TextStyle } from 'react-native'; +import { MentionData, MentionPartType, Part, PartType, Position, Suggestion } from '../types'; +/** + * RegEx grouped results. Example - "@[Full Name](123abc)" + * We have 4 groups here: + * - The whole original string - "@[Full Name](123abc)" + * - Mention trigger - "@" + * - Name - "Full Name" + * - Id - "123abc" + */ +declare const mentionRegEx: RegExp; +declare const defaultMentionTextStyle: StyleProp; +declare const isMentionPartType: (partType: PartType) => partType is MentionPartType; +/** + * Function for getting object with keyword for each mention part type + * + * If keyword is undefined then we don't tracking mention typing and shouldn't show suggestions. + * If keyword is not undefined (even empty string '') then we are tracking mention typing. + * + * Examples where @name is just plain text yet, not mention: + * '|abc @name dfg' - keyword is undefined + * 'abc @| dfg' - keyword is '' + * 'abc @name| dfg' - keyword is 'name' + * 'abc @na|me dfg' - keyword is 'na' + * 'abc @|name dfg' - keyword is against '' + * 'abc @name |dfg' - keyword is 'name ' + * 'abc @name dfg|' - keyword is 'name dfg' + * 'abc @name dfg |' - keyword is undefined (we have more than one space) + * 'abc @name dfg he|' - keyword is undefined (we have more than one space) + */ +declare const getMentionPartSuggestionKeywords: (parts: Part[], plainText: string, selection: Position, partTypes: PartType[]) => { + [trigger: string]: string | undefined; +}; +/** + * Generates new value when we changing text. + * + * @param parts full parts list + * @param originalText original plain text + * @param changedText changed plain text + */ +declare const generateValueFromPartsAndChangedText: (parts: Part[], originalText: string, changedText: string) => string; +/** + * Method for adding suggestion to the parts and generating value. We should: + * - Find part with plain text where we were tracking mention typing using selection state + * - Split the part to next parts: + * -* Before new mention + * -* With new mention + * -* After mention with space at the beginning + * - Generate new parts array and convert it to value + * + * @param parts - full part list + * @param mentionType - actually the mention type + * @param plainText - current plain text + * @param selection - current selection + * @param suggestion - suggestion that should be added + */ +declare const generateValueWithAddedSuggestion: (parts: Part[], mentionType: MentionPartType, plainText: string, selection: Position, suggestion: Suggestion) => string | undefined; +/** + * Method for generating part for plain text + * + * @param text - plain text that will be added to the part + * @param positionOffset - position offset from the very beginning of text + */ +declare const generatePlainTextPart: (text: string, positionOffset?: number) => Part; +/** + * Method for generating part for mention + * + * @param mentionPartType + * @param mention - mention data + * @param positionOffset - position offset from the very beginning of text + */ +declare const generateMentionPart: (mentionPartType: MentionPartType, mention: MentionData, positionOffset?: number) => Part; +/** + * Method for generation mention value that accepts mention regex + * + * @param trigger + * @param suggestion + */ +declare const getMentionValue: (trigger: string, suggestion: Suggestion) => string; +/** + * Recursive function for deep parse MentionInput's value and get plainText with parts + * + * @param value - the MentionInput's value + * @param partTypes - All provided part types + * @param positionOffset - offset from the very beginning of plain text + */ +declare const parseValue: (value: string, partTypes: PartType[], positionOffset?: number) => { + plainText: string; + parts: Part[]; +}; +/** + * Function for generation value from parts array + * + * @param parts + */ +declare const getValueFromParts: (parts: Part[]) => string; +/** + * Replace all mention values in value to some specified format + * + * @param value - value that is generated by MentionInput component + * @param replacer - function that takes mention object as parameter and returns string + */ +declare const replaceMentionValues: (value: string, replacer: (mention: MentionData) => string) => string; +export { mentionRegEx, defaultMentionTextStyle, isMentionPartType, getMentionPartSuggestionKeywords, generateValueFromPartsAndChangedText, generateValueWithAddedSuggestion, generatePlainTextPart, generateMentionPart, getMentionValue, parseValue, getValueFromParts, replaceMentionValues, }; diff --git a/dist/utils/utils.js b/dist/utils/utils.js new file mode 100644 index 0000000..56c9eba --- /dev/null +++ b/dist/utils/utils.js @@ -0,0 +1,389 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.replaceMentionValues = exports.getValueFromParts = exports.parseValue = exports.getMentionValue = exports.generateMentionPart = exports.generatePlainTextPart = exports.generateValueWithAddedSuggestion = exports.generateValueFromPartsAndChangedText = exports.getMentionPartSuggestionKeywords = exports.isMentionPartType = exports.defaultMentionTextStyle = exports.mentionRegEx = void 0; +const diff_1 = require("diff"); +// @ts-ignore the lib do not have TS declarations yet +const string_prototype_matchall_1 = __importDefault(require("string.prototype.matchall")); +/** + * RegEx grouped results. Example - "@[Full Name](123abc)" + * We have 4 groups here: + * - The whole original string - "@[Full Name](123abc)" + * - Mention trigger - "@" + * - Name - "Full Name" + * - Id - "123abc" + */ +const mentionRegEx = /((.)\[([^[]*)]\(([^(^)]*)\))/gi; +exports.mentionRegEx = mentionRegEx; +const defaultMentionTextStyle = { fontWeight: 'bold', color: 'blue' }; +exports.defaultMentionTextStyle = defaultMentionTextStyle; +const defaultPlainStringGenerator = ({ trigger }, { name }) => `${trigger}${name}`; +const isMentionPartType = (partType) => { + return partType.trigger != null; +}; +exports.isMentionPartType = isMentionPartType; +const getPartIndexByCursor = (parts, cursor, isIncludeEnd) => { + return parts.findIndex(one => cursor >= one.position.start && isIncludeEnd ? cursor <= one.position.end : cursor < one.position.end); +}; +/** + * The method for getting parts between two cursor positions. + * ``` + * | part1 | part2 | part3 | + * a b c|d e f g h i j h k|l m n o + * ``` + * We will get 3 parts here: + * 1. Part included 'd' + * 2. Part included 'efghij' + * 3. Part included 'hk' + * Cursor will move to position after 'k' + * + * @param parts full part list + * @param cursor current cursor position + * @param count count of characters that didn't change + */ +const getPartsInterval = (parts, cursor, count) => { + const newCursor = cursor + count; + const currentPartIndex = getPartIndexByCursor(parts, cursor); + const currentPart = parts[currentPartIndex]; + const newPartIndex = getPartIndexByCursor(parts, newCursor, true); + const newPart = parts[newPartIndex]; + let partsInterval = []; + if (!currentPart || !newPart) { + return partsInterval; + } + // Push whole first affected part or sub-part of the first affected part + if (currentPart.position.start === cursor && currentPart.position.end <= newCursor) { + partsInterval.push(currentPart); + } + else { + partsInterval.push(generatePlainTextPart(currentPart.text.substr(cursor - currentPart.position.start, count))); + } + if (newPartIndex > currentPartIndex) { + // Concat fully included parts + partsInterval = partsInterval.concat(parts.slice(currentPartIndex + 1, newPartIndex)); + // Push whole last affected part or sub-part of the last affected part + if (newPart.position.end === newCursor && newPart.position.start >= cursor) { + partsInterval.push(newPart); + } + else { + partsInterval.push(generatePlainTextPart(newPart.text.substr(0, newCursor - newPart.position.start))); + } + } + return partsInterval; +}; +/** + * Function for getting object with keyword for each mention part type + * + * If keyword is undefined then we don't tracking mention typing and shouldn't show suggestions. + * If keyword is not undefined (even empty string '') then we are tracking mention typing. + * + * Examples where @name is just plain text yet, not mention: + * '|abc @name dfg' - keyword is undefined + * 'abc @| dfg' - keyword is '' + * 'abc @name| dfg' - keyword is 'name' + * 'abc @na|me dfg' - keyword is 'na' + * 'abc @|name dfg' - keyword is against '' + * 'abc @name |dfg' - keyword is 'name ' + * 'abc @name dfg|' - keyword is 'name dfg' + * 'abc @name dfg |' - keyword is undefined (we have more than one space) + * 'abc @name dfg he|' - keyword is undefined (we have more than one space) + */ +const getMentionPartSuggestionKeywords = (parts, plainText, selection, partTypes) => { + const keywordByTrigger = {}; + partTypes.filter(isMentionPartType).forEach(({ trigger, allowedSpacesCount = 1, }) => { + keywordByTrigger[trigger] = undefined; + // Check if we don't have selection range + if (selection.end != selection.start) { + return; + } + // Find the part with the cursor + const part = parts.find(one => selection.end > one.position.start && selection.end <= one.position.end); + // Check if the cursor is not in mention type part + if (part == null || part.data != null) { + return; + } + const triggerIndex = plainText.lastIndexOf(trigger, selection.end); + // Return undefined in case when: + if ( + // - the trigger index is not event found + triggerIndex == -1 + // - the trigger index is out of found part with selection cursor + || triggerIndex < part.position.start + // - the trigger is not at the beginning and we don't have space or new line before trigger + || (triggerIndex > 0 && !/[\s\n]/gi.test(plainText[triggerIndex - 1]))) { + return; + } + // Looking for break lines and spaces between the current cursor and trigger + let spacesCount = 0; + for (let cursor = selection.end - 1; cursor >= triggerIndex; cursor -= 1) { + // Mention cannot have new line + if (plainText[cursor] === '\n') { + return; + } + // Incrementing space counter if the next symbol is space + if (plainText[cursor] === ' ') { + spacesCount += 1; + // Check maximum allowed spaces in trigger word + if (spacesCount > allowedSpacesCount) { + return; + } + } + } + keywordByTrigger[trigger] = plainText.substring(triggerIndex + 1, selection.end); + }); + return keywordByTrigger; +}; +exports.getMentionPartSuggestionKeywords = getMentionPartSuggestionKeywords; +/** + * Generates new value when we changing text. + * + * @param parts full parts list + * @param originalText original plain text + * @param changedText changed plain text + */ +const generateValueFromPartsAndChangedText = (parts, originalText, changedText) => { + const changes = diff_1.diffChars(originalText, changedText); + let newParts = []; + let cursor = 0; + changes.forEach(change => { + switch (true) { + /** + * We should: + * - Move cursor forward on the changed text length + */ + case change.removed: { + cursor += change.count; + break; + } + /** + * We should: + * - Push new part to the parts with that new text + */ + case change.added: { + newParts.push(generatePlainTextPart(change.value)); + break; + } + /** + * We should concat parts that didn't change. + * - In case when we have only one affected part we should push only that one sub-part + * - In case we have two affected parts we should push first + */ + default: { + if (change.count !== 0) { + newParts = newParts.concat(getPartsInterval(parts, cursor, change.count)); + cursor += change.count; + } + break; + } + } + }); + return getValueFromParts(newParts); +}; +exports.generateValueFromPartsAndChangedText = generateValueFromPartsAndChangedText; +/** + * Method for adding suggestion to the parts and generating value. We should: + * - Find part with plain text where we were tracking mention typing using selection state + * - Split the part to next parts: + * -* Before new mention + * -* With new mention + * -* After mention with space at the beginning + * - Generate new parts array and convert it to value + * + * @param parts - full part list + * @param mentionType - actually the mention type + * @param plainText - current plain text + * @param selection - current selection + * @param suggestion - suggestion that should be added + */ +const generateValueWithAddedSuggestion = (parts, mentionType, plainText, selection, suggestion) => { + var _a; + const currentPartIndex = parts.findIndex(one => selection.end >= one.position.start && selection.end <= one.position.end); + const currentPart = parts[currentPartIndex]; + if (!currentPart) { + return; + } + const triggerPartIndex = currentPart.text.lastIndexOf(mentionType.trigger, selection.end - currentPart.position.start); + const newMentionPartPosition = { + start: triggerPartIndex, + end: selection.end - currentPart.position.start, + }; + const isInsertSpaceToNextPart = mentionType.isInsertSpaceAfterMention + // Cursor is at the very end of parts or text row + && (plainText.length === selection.end || ((_a = parts[currentPartIndex]) === null || _a === void 0 ? void 0 : _a.text.startsWith('\n', newMentionPartPosition.end))); + return getValueFromParts([ + ...parts.slice(0, currentPartIndex), + // Create part with string before mention + generatePlainTextPart(currentPart.text.substring(0, newMentionPartPosition.start)), + generateMentionPart(mentionType, Object.assign({ original: getMentionValue(mentionType.trigger, suggestion), trigger: mentionType.trigger }, suggestion)), + // Create part with rest of string after mention and add a space if needed + generatePlainTextPart(`${isInsertSpaceToNextPart ? ' ' : ''}${currentPart.text.substring(newMentionPartPosition.end)}`), + ...parts.slice(currentPartIndex + 1), + ]); +}; +exports.generateValueWithAddedSuggestion = generateValueWithAddedSuggestion; +/** + * Method for generating part for plain text + * + * @param text - plain text that will be added to the part + * @param positionOffset - position offset from the very beginning of text + */ +const generatePlainTextPart = (text, positionOffset = 0) => ({ + text, + position: { + start: positionOffset, + end: positionOffset + text.length, + }, +}); +exports.generatePlainTextPart = generatePlainTextPart; +/** + * Method for generating part for mention + * + * @param mentionPartType + * @param mention - mention data + * @param positionOffset - position offset from the very beginning of text + */ +const generateMentionPart = (mentionPartType, mention, positionOffset = 0) => { + const text = mentionPartType.getPlainString + ? mentionPartType.getPlainString(mention) + : defaultPlainStringGenerator(mentionPartType, mention); + return { + text, + position: { + start: positionOffset, + end: positionOffset + text.length, + }, + partType: mentionPartType, + data: mention, + }; +}; +exports.generateMentionPart = generateMentionPart; +/** + * Generates part for matched regex result + * + * @param partType - current part type (pattern or mention) + * @param result - matched regex result + * @param positionOffset - position offset from the very beginning of text + */ +const generateRegexResultPart = (partType, result, positionOffset = 0) => ({ + text: result[0], + position: { + start: positionOffset, + end: positionOffset + result[0].length, + }, + partType, +}); +/** + * Method for generation mention value that accepts mention regex + * + * @param trigger + * @param suggestion + */ +const getMentionValue = (trigger, suggestion) => `${trigger}[${suggestion.name}](${suggestion.id})`; +exports.getMentionValue = getMentionValue; +const getMentionDataFromRegExMatchResult = ([, original, trigger, name, id]) => ({ + original, + trigger, + name, + id, +}); +/** + * Recursive function for deep parse MentionInput's value and get plainText with parts + * + * @param value - the MentionInput's value + * @param partTypes - All provided part types + * @param positionOffset - offset from the very beginning of plain text + */ +const parseValue = (value, partTypes, positionOffset = 0) => { + if (value == null) { + value = ''; + } + let plainText = ''; + let parts = []; + // We don't have any part types so adding just plain text part + if (partTypes.length === 0) { + plainText += value; + parts.push(generatePlainTextPart(value, positionOffset)); + } + else { + const [partType, ...restPartTypes] = partTypes; + const regex = isMentionPartType(partType) ? mentionRegEx : partType.pattern; + const matches = Array.from(string_prototype_matchall_1.default(value !== null && value !== void 0 ? value : '', regex)); + // In case when we didn't get any matches continue parsing value with rest part types + if (matches.length === 0) { + return parseValue(value, restPartTypes, positionOffset); + } + // In case when we have some text before matched part parsing the text with rest part types + if (matches[0].index != 0) { + const text = value.substr(0, matches[0].index); + const plainTextAndParts = parseValue(text, restPartTypes, positionOffset); + parts = parts.concat(plainTextAndParts.parts); + plainText += plainTextAndParts.plainText; + } + // Iterating over all found pattern matches + for (let i = 0; i < matches.length; i++) { + const result = matches[i]; + if (isMentionPartType(partType)) { + const mentionData = getMentionDataFromRegExMatchResult(result); + // Matched pattern is a mention and the mention doesn't match current mention type + // We should parse the mention with rest part types + if (mentionData.trigger !== partType.trigger) { + const plainTextAndParts = parseValue(mentionData.original, restPartTypes, positionOffset + plainText.length); + parts = parts.concat(plainTextAndParts.parts); + plainText += plainTextAndParts.plainText; + } + else { + const part = generateMentionPart(partType, mentionData, positionOffset + plainText.length); + parts.push(part); + plainText += part.text; + } + } + else { + const part = generateRegexResultPart(partType, result, positionOffset + plainText.length); + parts.push(part); + plainText += part.text; + } + // Check if the result is not at the end of whole value so we have a text after matched part + // We should parse the text with rest part types + if ((result.index + result[0].length) !== value.length) { + // Check if it is the last result + const isLastResult = i === matches.length - 1; + // So we should to add the last substring of value after matched mention + const text = value.slice(result.index + result[0].length, isLastResult ? undefined : matches[i + 1].index); + const plainTextAndParts = parseValue(text, restPartTypes, positionOffset + plainText.length); + parts = parts.concat(plainTextAndParts.parts); + plainText += plainTextAndParts.plainText; + } + } + } + // Exiting from parseValue + return { + plainText, + parts, + }; +}; +exports.parseValue = parseValue; +/** + * Function for generation value from parts array + * + * @param parts + */ +const getValueFromParts = (parts) => parts + .map(item => (item.data ? item.data.original : item.text)) + .join(''); +exports.getValueFromParts = getValueFromParts; +/** + * Replace all mention values in value to some specified format + * + * @param value - value that is generated by MentionInput component + * @param replacer - function that takes mention object as parameter and returns string + */ +const replaceMentionValues = (value, replacer) => value.replace(mentionRegEx, (fullMatch, original, trigger, name, id) => replacer({ + original, + trigger, + name, + id, +})); +exports.replaceMentionValues = replaceMentionValues; +//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/dist/utils/utils.js.map b/dist/utils/utils.js.map new file mode 100644 index 0000000..3778172 --- /dev/null +++ b/dist/utils/utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAiC;AAEjC,qDAAqD;AACrD,0FAAiD;AAYjD;;;;;;;GAOG;AACH,MAAM,YAAY,GAAG,gCAAgC,CAAC;AA+cpD,oCAAY;AA7cd,MAAM,uBAAuB,GAAyB,EAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAC,CAAC;AA8cxF,0DAAuB;AA5czB,MAAM,2BAA2B,GAAG,CAAC,EAAC,OAAO,EAAkB,EAAE,EAAC,IAAI,EAAc,EAAE,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AAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACzD,IAAI,CAAC,EAAE,CAAC,CAAC;AA6BV,8CAAiB;AA3BnB;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,CAC3B,KAAa,EACb,QAA0C,EAC1C,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC;IACpF,QAAQ;IACR,OAAO;IACP,IAAI;IACJ,EAAE;CACH,CAAC,CAAC,CAAC;AAcF,oDAAoB"} \ No newline at end of file From 73360d4704b6814d1a5c6f90dd51bded57b8d945 Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 16:22:51 -0400 Subject: [PATCH 03/10] fixing bug, incorrect assignment of data property in partsData --- dist/components/mention-input.js | 4 ++-- dist/components/mention-input.js.map | 2 +- src/components/mention-input.tsx | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/components/mention-input.js b/dist/components/mention-input.js index c924515..9947691 100644 --- a/dist/components/mention-input.js +++ b/dist/components/mention-input.js @@ -73,10 +73,10 @@ const MentionInput = (_a) => { var _a, _b, _c; const id = (_a = part.data) === null || _a === void 0 ? void 0 : _a.id; const name = (_b = part.data) === null || _b === void 0 ? void 0 : _b.name; - const data = partsData.find(pd => pd.id === id); + const partData = partsData.find(pd => pd.id === id); const accI = acc.findIndex(ad => ad.id === id); const lastValue = acc[accI]; - const val = { cant: ((_c = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _c !== void 0 ? _c : 0) + 1, data, id, name }; + const val = { cant: ((_c = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _c !== void 0 ? _c : 0) + 1, data: partData === null || partData === void 0 ? void 0 : partData.data, id, name }; AddOrEdit(acc, val, accI); return acc; }, []); diff --git a/dist/components/mention-input.js.map b/dist/components/mention-input.js.map index a81f630..6117f47 100644 --- a/dist/components/mention-input.js.map +++ b/dist/components/mention-input.js.map @@ -1 +1 @@ -{"version":3,"file":"mention-input.js","sourceRoot":"","sources":["../../src/components/mention-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA+E;AAC/E,+CAMsB;AAGtB,oCAOkB;AAClB,MAAM,SAAS,GAAG,CAAoB,GAAQ,EAAE,GAAM,EAAE,CAAS,EAAE,EAAE;IACnE,IAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QACX,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACf;SAAM;QACL,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;KACd;AACH,CAAC,CAAA;AACD,MAAM,YAAY,GAA0B,CAC1C,EAaqB,EACrB,EAAE;QAdF,EACE,KAAK,EACL,QAAQ,EAER,SAAS,GAAG,EAAE,EAEd,QAAQ,EAAE,YAAY,EAEtB,cAAc,EAEd,iBAAiB,EACjB,iBAAiB,OAEE,EADhB,cAAc,cAZnB,0GAaC,CADkB;IAGnB,MAAM,SAAS,GAAG,cAAM,CAAmB,IAAI,CAAC,CAAC;IAEjD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,gBAAQ,CAAC,EAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC,CAAC;IAC/D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,gBAAQ,CAAa,EAAE,CAAC,CAAC;IAE3D,MAAM,EACJ,SAAS,EACT,KAAK,GACN,GAAG,eAAO,CAAC,GAAG,EAAE,CAAC,kBAAU,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;IAEpE,MAAM,qBAAqB,GAAG,CAAC,KAA8D,EAAE,EAAE;QAC/F,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAE1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,CAAC,CACa,CAClB,CAAC;IAEF,OAAO,CACL,8BAAC,mBAAI,IAAC,KAAK,EAAE,cAAc;QACvB,SAAS;aACR,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,CAAC,GAAG,CAAC,gCAAgC,CACzC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC;QAGhC,8BAAC,wBAAS,kBACR,SAAS,UAEL,cAAc,IAElB,GAAG,EAAE,kBAAkB,EAEvB,YAAY,EAAE,aAAa,EAC3B,iBAAiB,EAAE,qBAAqB;YAExC,8BAAC,mBAAI,QACF,KAAK,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,EAAE,KAAK,EAAE,EAAE;;gBAAC,OAAA,QAAQ,CAAC,CAAC,CAAC,CACvD,8BAAC,mBAAI,IACH,GAAG,EAAE,GAAG,KAAK,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,mCAAI,SAAS,EAAE,EAC7C,KAAK,EAAE,MAAA,QAAQ,CAAC,SAAS,mCAAI,+BAAuB,IAEnD,IAAI,CACA,CACR,CAAC,CAAC,CAAC,CACF,8BAAC,mBAAI,IAAC,GAAG,EAAE,KAAK,IAAG,IAAI,CAAQ,CAChC,CAAA;aAAA,CAAC,CACG,CACG;QAEV,SAAS;aACR,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,GAAG,CAAC,gCAAgC,CACxC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC,CAE3B,CACR,CAAC;AACJ,CAAC,CAAC;AAEO,oCAAY"} \ No newline at end of file +{"version":3,"file":"mention-input.js","sourceRoot":"","sources":["../../src/components/mention-input.tsx"],"names":[],"mappings":";;;;;;;;;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CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,CAAC,GAAG,CAAC,gCAAgC,CACzC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC;QAGhC,8BAAC,wBAAS,kBACR,SAAS,UAEL,cAAc,IAElB,GAAG,EAAE,kBAAkB,EAEvB,YAAY,EAAE,aAAa,EAC3B,iBAAiB,EAAE,qBAAqB;YAExC,8BAAC,mBAAI,QACF,KAAK,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,EAAE,KAAK,EAAE,EAAE;;gBAAC,OAAA,QAAQ,CAAC,CAAC,CAAC,CACvD,8BAAC,mBAAI,IACH,GAAG,EAAE,GAAG,KAAK,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,mCAAI,SAAS,EAAE,EAC7C,KAAK,EAAE,MAAA,QAAQ,CAAC,SAAS,mCAAI,+BAAuB,IAEnD,IAAI,CACA,CACR,CAAC,CAAC,CAAC,CACF,8BAAC,mBAAI,IAAC,GAAG,EAAE,KAAK,IAAG,IAAI,CAAQ,CAChC,CAAA;aAAA,CAAC,CACG,CACG;QAEV,SAAS;aACR,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,GAAG,CAAC,gCAAgC,CACxC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC,CAE3B,CACR,CAAC;AACJ,CAAC,CAAC;AAEO,oCAAY"} \ No newline at end of file diff --git a/src/components/mention-input.tsx b/src/components/mention-input.tsx index 69cfea9..ca55b61 100644 --- a/src/components/mention-input.tsx +++ b/src/components/mention-input.tsx @@ -75,10 +75,10 @@ const MentionInput: FC = ( const newPartsData = partsWithData.reduce((acc, part) => { const id = part.data?.id; const name = part.data?.name; - const data = partsData.find(pd => pd.id === id); + const partData = partsData.find(pd => pd.id === id); const accI = acc.findIndex(ad => ad.id === id); const lastValue = acc[accI]; - const val = { cant: (lastValue?.cant ?? 0) + 1, data, id, name } as PartData; + const val = { cant: (lastValue?.cant ?? 0) + 1, data: partData?.data, id, name } as PartData; AddOrEdit(acc, val, accI); return acc; }, [] as PartData[]); @@ -126,7 +126,7 @@ const MentionInput: FC = ( const copyPartsData = [...partsData]; const i = copyPartsData.findIndex(ad => ad.id === suggestion.id); const lastValue = copyPartsData[i]; - const val = { + const val = { cant: (lastValue?.cant ?? 0) + 1, data: suggestion, id: suggestion.id, From 8e2cbd7f763e83ad882723759bb0f95b1f449241 Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 16:35:52 -0400 Subject: [PATCH 04/10] only working with MentionPartType --- dist/components/mention-input.js | 2 +- dist/components/mention-input.js.map | 2 +- src/components/mention-input.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/components/mention-input.js b/dist/components/mention-input.js index 9947691..344cb25 100644 --- a/dist/components/mention-input.js +++ b/dist/components/mention-input.js @@ -68,7 +68,7 @@ const MentionInput = (_a) => { * @param newParts */ const partDataHasChanged = (newParts) => { - const partsWithData = newParts.filter(part => part.partType); + const partsWithData = newParts.filter(part => part.partType && utils_1.isMentionPartType(part.partType)); const newPartsData = partsWithData.reduce((acc, part) => { var _a, _b, _c; const id = (_a = part.data) === null || _a === void 0 ? void 0 : _a.id; diff --git a/dist/components/mention-input.js.map b/dist/components/mention-input.js.map index 6117f47..87816e6 100644 --- a/dist/components/mention-input.js.map +++ b/dist/components/mention-input.js.map @@ -1 +1 @@ -{"version":3,"file":"mention-input.js","sourceRoot":"","sources":["../../src/components/mention-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA+E;AAC/E,+CAMsB;AAGtB,oCAOkB;AAClB,MAAM,SAAS,GAAG,CAAo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7B,CAAC,GAAG,CAAC,gCAAgC,CACzC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC;QAGhC,8BAAC,wBAAS,kBACR,SAAS,UAEL,cAAc,IAElB,GAAG,EAAE,kBAAkB,EAEvB,YAAY,EAAE,aAAa,EAC3B,iBAAiB,EAAE,qBAAqB;YAExC,8BAAC,mBAAI,QACF,KAAK,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,EAAE,KAAK,EAAE,EAAE;;gBAAC,OAAA,QAAQ,CAAC,CAAC,CAAC,CACvD,8BAAC,mBAAI,IACH,GAAG,EAAE,GAAG,KAAK,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,mCAAI,SAAS,EAAE,EAC7C,KAAK,EAAE,MAAA,QAAQ,CAAC,SAAS,mCAAI,+BAAuB,IAEnD,IAAI,CACA,CACR,CAAC,CAAC,CAAC,CACF,8BAAC,mBAAI,IAAC,GAAG,EAAE,KAAK,IAAG,IAAI,CAAQ,CAChC,CAAA;aAAA,CAAC,CACG,CACG;QAEV,SAAS;aACR,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,GAAG,CAAC,gCAAgC,CACxC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC,CAE3B,CACR,CAAC;AACJ,CAAC,CAAC;AAEO,oCAAY"} \ No newline at end of file +{"version":3,"file":"mention-input.js","sourceRoot":"","sources":["../../src/components/mention-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA+E;AAC/E,+CAMsB;AAGtB,oCAOkB;AAClB,MAAM,SAAS,GAAG,CAAoB,GAAQ,EAAE,GAAM,EAAE,CAAS,EAAE,EAAE;IACnE,IAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QACX,GAAG,CAA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AC,wBAAwB,CAAC;QAGhC,8BAAC,wBAAS,kBACR,SAAS,UAEL,cAAc,IAElB,GAAG,EAAE,kBAAkB,EAEvB,YAAY,EAAE,aAAa,EAC3B,iBAAiB,EAAE,qBAAqB;YAExC,8BAAC,mBAAI,QACF,KAAK,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,EAAE,KAAK,EAAE,EAAE;;gBAAC,OAAA,QAAQ,CAAC,CAAC,CAAC,CACvD,8BAAC,mBAAI,IACH,GAAG,EAAE,GAAG,KAAK,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,mCAAI,SAAS,EAAE,EAC7C,KAAK,EAAE,MAAA,QAAQ,CAAC,SAAS,mCAAI,+BAAuB,IAEnD,IAAI,CACA,CACR,CAAC,CAAC,CAAC,CACF,8BAAC,mBAAI,IAAC,GAAG,EAAE,KAAK,IAAG,IAAI,CAAQ,CAChC,CAAA;aAAA,CAAC,CACG,CACG;QAEV,SAAS;aACR,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,GAAG,CAAC,gCAAgC,CACxC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC,CAE3B,CACR,CAAC;AACJ,CAAC,CAAC;AAEO,oCAAY"} \ No newline at end of file diff --git a/src/components/mention-input.tsx b/src/components/mention-input.tsx index ca55b61..2a440ea 100644 --- a/src/components/mention-input.tsx +++ b/src/components/mention-input.tsx @@ -71,7 +71,7 @@ const MentionInput: FC = ( * @param newParts */ const partDataHasChanged = (newParts: Part[]) => { - const partsWithData = newParts.filter(part => part.partType); + const partsWithData = newParts.filter(part => part.partType && isMentionPartType(part.partType)); const newPartsData = partsWithData.reduce((acc, part) => { const id = part.data?.id; const name = part.data?.name; From 3c016ab13eb047cdcba64df52f80d8f4f41b2a61 Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 16:42:23 -0400 Subject: [PATCH 05/10] removing dist from repository --- .gitignore | 1 + dist/components/index.d.ts | 1 - dist/components/index.js | 14 - dist/components/index.js.map | 1 - dist/components/mention-input.d.ts | 4 - dist/components/mention-input.js | 169 ------------ dist/components/mention-input.js.map | 1 - dist/index.d.ts | 3 - dist/index.js | 21 -- dist/index.js.map | 1 - dist/types/index.d.ts | 1 - dist/types/index.js | 14 - dist/types/index.js.map | 1 - dist/types/types.d.ts | 68 ----- dist/types/types.js | 3 - dist/types/types.js.map | 1 - dist/utils/index.d.ts | 1 - dist/utils/index.js | 14 - dist/utils/index.js.map | 1 - dist/utils/utils.d.ts | 104 ------- dist/utils/utils.js | 389 --------------------------- dist/utils/utils.js.map | 1 - 22 files changed, 1 insertion(+), 813 deletions(-) delete mode 100644 dist/components/index.d.ts delete mode 100644 dist/components/index.js delete mode 100644 dist/components/index.js.map delete mode 100644 dist/components/mention-input.d.ts delete mode 100644 dist/components/mention-input.js delete mode 100644 dist/components/mention-input.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 dist/types/index.d.ts delete mode 100644 dist/types/index.js delete mode 100644 dist/types/index.js.map delete mode 100644 dist/types/types.d.ts delete mode 100644 dist/types/types.js delete mode 100644 dist/types/types.js.map delete mode 100644 dist/utils/index.d.ts delete mode 100644 dist/utils/index.js delete mode 100644 dist/utils/index.js.map delete mode 100644 dist/utils/utils.d.ts delete mode 100644 dist/utils/utils.js delete mode 100644 dist/utils/utils.js.map diff --git a/.gitignore b/.gitignore index d6f2790..6d5f090 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ # .idea node_modules/ +dist npm-debug.log yarn-error.log diff --git a/dist/components/index.d.ts b/dist/components/index.d.ts deleted file mode 100644 index 31174cf..0000000 --- a/dist/components/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './mention-input'; diff --git a/dist/components/index.js b/dist/components/index.js deleted file mode 100644 index 8dc1254..0000000 --- a/dist/components/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./mention-input"), exports); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/components/index.js.map b/dist/components/index.js.map deleted file mode 100644 index 473e91b..0000000 --- a/dist/components/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC"} \ No newline at end of file diff --git a/dist/components/mention-input.d.ts b/dist/components/mention-input.d.ts deleted file mode 100644 index a6fcb73..0000000 --- a/dist/components/mention-input.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { FC } from 'react'; -import { MentionInputProps } from '../types'; -declare const MentionInput: FC; -export { MentionInput }; diff --git a/dist/components/mention-input.js b/dist/components/mention-input.js deleted file mode 100644 index 344cb25..0000000 --- a/dist/components/mention-input.js +++ /dev/null @@ -1,169 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __rest = (this && this.__rest) || function (s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.MentionInput = void 0; -const react_1 = __importStar(require("react")); -const react_native_1 = require("react-native"); -const utils_1 = require("../utils"); -const AddOrEdit = (arr, val, i) => { - if (i === -1) { - arr.push(val); - } - else { - arr[i] = val; - } -}; -const MentionInput = (_a) => { - var { value, onChange, partTypes = [], inputRef: propInputRef, containerStyle, onSelectionChange, onChangePartsData } = _a, textInputProps = __rest(_a, ["value", "onChange", "partTypes", "inputRef", "containerStyle", "onSelectionChange", "onChangePartsData"]); - const textInput = react_1.useRef(null); - const [selection, setSelection] = react_1.useState({ start: 0, end: 0 }); - const [partsData, setPartsData] = react_1.useState([]); - const { plainText, parts, } = react_1.useMemo(() => utils_1.parseValue(value, partTypes), [value, partTypes]); - const handleSelectionChange = (event) => { - setSelection(event.nativeEvent.selection); - onSelectionChange && onSelectionChange(event); - }; - /** - * Callback that trigger on TextInput text change - * - * @param changedText - */ - const onChangeInput = (changedText) => { - const newValue = utils_1.generateValueFromPartsAndChangedText(parts, plainText, changedText); - const { parts: newParts } = utils_1.parseValue(newValue, partTypes); - partDataHasChanged(newParts); - onChange(newValue); - }; - /** - * Determines when the onChangePartsData event should triggerred - * @param newParts - */ - const partDataHasChanged = (newParts) => { - const partsWithData = newParts.filter(part => part.partType && utils_1.isMentionPartType(part.partType)); - const newPartsData = partsWithData.reduce((acc, part) => { - var _a, _b, _c; - const id = (_a = part.data) === null || _a === void 0 ? void 0 : _a.id; - const name = (_b = part.data) === null || _b === void 0 ? void 0 : _b.name; - const partData = partsData.find(pd => pd.id === id); - const accI = acc.findIndex(ad => ad.id === id); - const lastValue = acc[accI]; - const val = { cant: ((_c = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _c !== void 0 ? _c : 0) + 1, data: partData === null || partData === void 0 ? void 0 : partData.data, id, name }; - AddOrEdit(acc, val, accI); - return acc; - }, []); - const eventMustBeTriggered = newPartsData.length !== partsData.length - || newPartsData.some(npd => { var _a; return ((_a = partsData.find(pd => pd.id === npd.id)) === null || _a === void 0 ? void 0 : _a.cant) !== npd.cant; }); - if (eventMustBeTriggered) - ChangePartsData(newPartsData); - }; - const ChangePartsData = (newPartsData) => { - setPartsData(newPartsData); - if (typeof onChangePartsData === 'function') { - onChangePartsData(newPartsData); - } - }; - /** - * We memoize the keyword to know should we show mention suggestions or not - */ - const keywordByTrigger = react_1.useMemo(() => { - return utils_1.getMentionPartSuggestionKeywords(parts, plainText, selection, partTypes); - }, [parts, plainText, selection, partTypes]); - /** - * Callback on mention suggestion press. We should: - * - Get updated value - * - Trigger onChange callback with new value - */ - const onSuggestionPress = (mentionType) => (suggestion) => { - var _a; - const newValue = utils_1.generateValueWithAddedSuggestion(parts, mentionType, plainText, selection, suggestion); - if (!newValue) { - return; - } - // - const copyPartsData = [...partsData]; - const i = copyPartsData.findIndex(ad => ad.id === suggestion.id); - const lastValue = copyPartsData[i]; - const val = { - cant: ((_a = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _a !== void 0 ? _a : 0) + 1, - data: suggestion, - id: suggestion.id, - name: suggestion.name - }; - AddOrEdit(copyPartsData, val, i); - ChangePartsData(copyPartsData); - onChange(newValue); - /** - * Move cursor to the end of just added mention starting from trigger string and including: - * - Length of trigger string - * - Length of mention name - * - Length of space after mention (1) - * - * Not working now due to the RN bug - */ - // const newCursorPosition = currentPart.position.start + triggerPartIndex + trigger.length + - // suggestion.name.length + 1; - // textInput.current?.setNativeProps({selection: {start: newCursorPosition, end: newCursorPosition}}); - }; - const handleTextInputRef = (ref) => { - textInput.current = ref; - if (propInputRef) { - if (typeof propInputRef === 'function') { - propInputRef(ref); - } - else { - propInputRef.current = ref; - } - } - }; - const renderMentionSuggestions = (mentionType) => (react_1.default.createElement(react_1.default.Fragment, { key: mentionType.trigger }, mentionType.renderSuggestions && mentionType.renderSuggestions({ - keyword: keywordByTrigger[mentionType.trigger], - onSuggestionPress: onSuggestionPress(mentionType), - }))); - return (react_1.default.createElement(react_native_1.View, { style: containerStyle }, - partTypes - .filter(one => (utils_1.isMentionPartType(one) - && one.renderSuggestions != null - && !one.isBottomMentionSuggestionsRender)) - .map(renderMentionSuggestions), - react_1.default.createElement(react_native_1.TextInput, Object.assign({ multiline: true }, textInputProps, { ref: handleTextInputRef, onChangeText: onChangeInput, onSelectionChange: handleSelectionChange }), - react_1.default.createElement(react_native_1.Text, null, parts.map(({ text, partType, data }, index) => { - var _a, _b; - return partType ? (react_1.default.createElement(react_native_1.Text, { key: `${index}-${(_a = data === null || data === void 0 ? void 0 : data.trigger) !== null && _a !== void 0 ? _a : 'pattern'}`, style: (_b = partType.textStyle) !== null && _b !== void 0 ? _b : utils_1.defaultMentionTextStyle }, text)) : (react_1.default.createElement(react_native_1.Text, { key: index }, text)); - }))), - partTypes - .filter(one => (utils_1.isMentionPartType(one) - && one.renderSuggestions != null - && one.isBottomMentionSuggestionsRender)) - .map(renderMentionSuggestions))); -}; -exports.MentionInput = MentionInput; -//# sourceMappingURL=mention-input.js.map \ No newline at end of file diff --git a/dist/components/mention-input.js.map b/dist/components/mention-input.js.map deleted file mode 100644 index 87816e6..0000000 --- a/dist/components/mention-input.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"mention-input.js","sourceRoot":"","sources":["../../src/components/mention-input.tsx"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O,CACL,8BAAC,mBAAI,IAAC,KAAK,EAAE,cAAc;QACvB,SAAS;aACR,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,CAAC,GAAG,CAAC,gCAAgC,CACzC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC;QAGhC,8BAAC,wBAAS,kBACR,SAAS,UAEL,cAAc,IAElB,GAAG,EAAE,kBAAkB,EAEvB,YAAY,EAAE,aAAa,EAC3B,iBAAiB,EAAE,qBAAqB;YAExC,8BAAC,mBAAI,QACF,KAAK,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,EAAE,KAAK,EAAE,EAAE;;gBAAC,OAAA,QAAQ,CAAC,CAAC,CAAC,CACvD,8BAAC,mBAAI,IACH,GAAG,EAAE,GAAG,KAAK,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,mCAAI,SAAS,EAAE,EAC7C,KAAK,EAAE,MAAA,QAAQ,CAAC,SAAS,mCAAI,+BAAuB,IAEnD,IAAI,CACA,CACR,CAAC,CAAC,CAAC,CACF,8BAAC,mBAAI,IAAC,GAAG,EAAE,KAAK,IAAG,IAAI,CAAQ,CAChC,CAAA;aAAA,CAAC,CACG,CACG;QAEV,SAAS;aACR,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,GAAG,CAAC,gCAAgC,CACxC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC,CAE3B,CACR,CAAC;AACJ,CAAC,CAAC;AAEO,oCAAY"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index d9a1101..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './components'; -export type { Suggestion, Part, MentionSuggestionsProps, PartType, } from './types'; -export { mentionRegEx, isMentionPartType, getMentionValue, parseValue, replaceMentionValues, } from './utils'; diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9ece04b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.replaceMentionValues = exports.parseValue = exports.getMentionValue = exports.isMentionPartType = exports.mentionRegEx = void 0; -__exportStar(require("./components"), exports); -var utils_1 = require("./utils"); -Object.defineProperty(exports, "mentionRegEx", { enumerable: true, get: function () { return utils_1.mentionRegEx; } }); -Object.defineProperty(exports, "isMentionPartType", { enumerable: true, get: function () { return utils_1.isMentionPartType; } }); -Object.defineProperty(exports, "getMentionValue", { enumerable: true, get: function () { return utils_1.getMentionValue; } }); -Object.defineProperty(exports, "parseValue", { enumerable: true, get: function () { return utils_1.parseValue; } }); -Object.defineProperty(exports, "replaceMentionValues", { enumerable: true, get: function () { return utils_1.replaceMentionValues; } }); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 681fe4b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAA6B;AAM7B,iCAEiB;AADf,qGAAA,YAAY,OAAA;AAAE,0GAAA,iBAAiB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAAE,mGAAA,UAAU,OAAA;AAAE,6GAAA,oBAAoB,OAAA"} \ No newline at end of file diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts deleted file mode 100644 index fcb073f..0000000 --- a/dist/types/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types'; diff --git a/dist/types/index.js b/dist/types/index.js deleted file mode 100644 index 66b0c96..0000000 --- a/dist/types/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./types"), exports); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/types/index.js.map b/dist/types/index.js.map deleted file mode 100644 index 881fa19..0000000 --- a/dist/types/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB"} \ No newline at end of file diff --git a/dist/types/types.d.ts b/dist/types/types.d.ts deleted file mode 100644 index 979e622..0000000 --- a/dist/types/types.d.ts +++ /dev/null @@ -1,68 +0,0 @@ -import type { Change } from 'diff'; -import type { ReactNode, Ref } from 'react'; -import type { StyleProp, TextInput, TextInputProps, TextStyle, ViewStyle } from 'react-native'; -declare type Suggestion = { - id: string; - name: string; -}; -declare type MentionData = { - original: string; - trigger: string; - name: string; - id: string; -}; -declare type PartData = { - name: string; - id: string; - cant: number; - data: any; -}; -declare type CharactersDiffChange = Omit & { - count: number; -}; -declare type RegexMatchResult = string[] & { - 0: string; - 1: string; - 2: string; - 3: string; - 4: string; - index: number; - groups: MentionData; -}; -declare type Position = { - start: number; - end: number; -}; -declare type MentionSuggestionsProps = { - keyword: string | undefined; - onSuggestionPress: (suggestion: Suggestion) => void; -}; -declare type MentionPartType = { - trigger: string; - renderSuggestions?: (props: MentionSuggestionsProps) => ReactNode; - allowedSpacesCount?: number; - isInsertSpaceAfterMention?: boolean; - isBottomMentionSuggestionsRender?: boolean; - textStyle?: StyleProp; - getPlainString?: (mention: MentionData) => string; -}; -declare type PatternPartType = { - pattern: RegExp; - textStyle?: StyleProp; -}; -declare type PartType = MentionPartType | PatternPartType; -declare type Part = { - text: string; - position: Position; - partType?: PartType; - data?: MentionData; -}; -declare type MentionInputProps = Omit & { - value: string; - onChange: (value: string) => void; - onChangePartsData: (partsData: PartData[]) => void; - partTypes?: PartType[]; - inputRef?: Ref; - containerStyle?: StyleProp; -}; -export type { Suggestion, MentionData, CharactersDiffChange, RegexMatchResult, Position, Part, MentionSuggestionsProps, MentionPartType, PatternPartType, PartType, MentionInputProps, PartData }; diff --git a/dist/types/types.js b/dist/types/types.js deleted file mode 100644 index 11e638d..0000000 --- a/dist/types/types.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/types/types.js.map b/dist/types/types.js.map deleted file mode 100644 index 67c6c9d..0000000 --- a/dist/types/types.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/utils/index.d.ts b/dist/utils/index.d.ts deleted file mode 100644 index 04bca77..0000000 --- a/dist/utils/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils'; diff --git a/dist/utils/index.js b/dist/utils/index.js deleted file mode 100644 index e6f0868..0000000 --- a/dist/utils/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./utils"), exports); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/utils/index.js.map b/dist/utils/index.js.map deleted file mode 100644 index b6566c7..0000000 --- a/dist/utils/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB"} \ No newline at end of file diff --git a/dist/utils/utils.d.ts b/dist/utils/utils.d.ts deleted file mode 100644 index f1880b6..0000000 --- a/dist/utils/utils.d.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { StyleProp, TextStyle } from 'react-native'; -import { MentionData, MentionPartType, Part, PartType, Position, Suggestion } from '../types'; -/** - * RegEx grouped results. Example - "@[Full Name](123abc)" - * We have 4 groups here: - * - The whole original string - "@[Full Name](123abc)" - * - Mention trigger - "@" - * - Name - "Full Name" - * - Id - "123abc" - */ -declare const mentionRegEx: RegExp; -declare const defaultMentionTextStyle: StyleProp; -declare const isMentionPartType: (partType: PartType) => partType is MentionPartType; -/** - * Function for getting object with keyword for each mention part type - * - * If keyword is undefined then we don't tracking mention typing and shouldn't show suggestions. - * If keyword is not undefined (even empty string '') then we are tracking mention typing. - * - * Examples where @name is just plain text yet, not mention: - * '|abc @name dfg' - keyword is undefined - * 'abc @| dfg' - keyword is '' - * 'abc @name| dfg' - keyword is 'name' - * 'abc @na|me dfg' - keyword is 'na' - * 'abc @|name dfg' - keyword is against '' - * 'abc @name |dfg' - keyword is 'name ' - * 'abc @name dfg|' - keyword is 'name dfg' - * 'abc @name dfg |' - keyword is undefined (we have more than one space) - * 'abc @name dfg he|' - keyword is undefined (we have more than one space) - */ -declare const getMentionPartSuggestionKeywords: (parts: Part[], plainText: string, selection: Position, partTypes: PartType[]) => { - [trigger: string]: string | undefined; -}; -/** - * Generates new value when we changing text. - * - * @param parts full parts list - * @param originalText original plain text - * @param changedText changed plain text - */ -declare const generateValueFromPartsAndChangedText: (parts: Part[], originalText: string, changedText: string) => string; -/** - * Method for adding suggestion to the parts and generating value. We should: - * - Find part with plain text where we were tracking mention typing using selection state - * - Split the part to next parts: - * -* Before new mention - * -* With new mention - * -* After mention with space at the beginning - * - Generate new parts array and convert it to value - * - * @param parts - full part list - * @param mentionType - actually the mention type - * @param plainText - current plain text - * @param selection - current selection - * @param suggestion - suggestion that should be added - */ -declare const generateValueWithAddedSuggestion: (parts: Part[], mentionType: MentionPartType, plainText: string, selection: Position, suggestion: Suggestion) => string | undefined; -/** - * Method for generating part for plain text - * - * @param text - plain text that will be added to the part - * @param positionOffset - position offset from the very beginning of text - */ -declare const generatePlainTextPart: (text: string, positionOffset?: number) => Part; -/** - * Method for generating part for mention - * - * @param mentionPartType - * @param mention - mention data - * @param positionOffset - position offset from the very beginning of text - */ -declare const generateMentionPart: (mentionPartType: MentionPartType, mention: MentionData, positionOffset?: number) => Part; -/** - * Method for generation mention value that accepts mention regex - * - * @param trigger - * @param suggestion - */ -declare const getMentionValue: (trigger: string, suggestion: Suggestion) => string; -/** - * Recursive function for deep parse MentionInput's value and get plainText with parts - * - * @param value - the MentionInput's value - * @param partTypes - All provided part types - * @param positionOffset - offset from the very beginning of plain text - */ -declare const parseValue: (value: string, partTypes: PartType[], positionOffset?: number) => { - plainText: string; - parts: Part[]; -}; -/** - * Function for generation value from parts array - * - * @param parts - */ -declare const getValueFromParts: (parts: Part[]) => string; -/** - * Replace all mention values in value to some specified format - * - * @param value - value that is generated by MentionInput component - * @param replacer - function that takes mention object as parameter and returns string - */ -declare const replaceMentionValues: (value: string, replacer: (mention: MentionData) => string) => string; -export { mentionRegEx, defaultMentionTextStyle, isMentionPartType, getMentionPartSuggestionKeywords, generateValueFromPartsAndChangedText, generateValueWithAddedSuggestion, generatePlainTextPart, generateMentionPart, getMentionValue, parseValue, getValueFromParts, replaceMentionValues, }; diff --git a/dist/utils/utils.js b/dist/utils/utils.js deleted file mode 100644 index 56c9eba..0000000 --- a/dist/utils/utils.js +++ /dev/null @@ -1,389 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.replaceMentionValues = exports.getValueFromParts = exports.parseValue = exports.getMentionValue = exports.generateMentionPart = exports.generatePlainTextPart = exports.generateValueWithAddedSuggestion = exports.generateValueFromPartsAndChangedText = exports.getMentionPartSuggestionKeywords = exports.isMentionPartType = exports.defaultMentionTextStyle = exports.mentionRegEx = void 0; -const diff_1 = require("diff"); -// @ts-ignore the lib do not have TS declarations yet -const string_prototype_matchall_1 = __importDefault(require("string.prototype.matchall")); -/** - * RegEx grouped results. Example - "@[Full Name](123abc)" - * We have 4 groups here: - * - The whole original string - "@[Full Name](123abc)" - * - Mention trigger - "@" - * - Name - "Full Name" - * - Id - "123abc" - */ -const mentionRegEx = /((.)\[([^[]*)]\(([^(^)]*)\))/gi; -exports.mentionRegEx = mentionRegEx; -const defaultMentionTextStyle = { fontWeight: 'bold', color: 'blue' }; -exports.defaultMentionTextStyle = defaultMentionTextStyle; -const defaultPlainStringGenerator = ({ trigger }, { name }) => `${trigger}${name}`; -const isMentionPartType = (partType) => { - return partType.trigger != null; -}; -exports.isMentionPartType = isMentionPartType; -const getPartIndexByCursor = (parts, cursor, isIncludeEnd) => { - return parts.findIndex(one => cursor >= one.position.start && isIncludeEnd ? cursor <= one.position.end : cursor < one.position.end); -}; -/** - * The method for getting parts between two cursor positions. - * ``` - * | part1 | part2 | part3 | - * a b c|d e f g h i j h k|l m n o - * ``` - * We will get 3 parts here: - * 1. Part included 'd' - * 2. Part included 'efghij' - * 3. Part included 'hk' - * Cursor will move to position after 'k' - * - * @param parts full part list - * @param cursor current cursor position - * @param count count of characters that didn't change - */ -const getPartsInterval = (parts, cursor, count) => { - const newCursor = cursor + count; - const currentPartIndex = getPartIndexByCursor(parts, cursor); - const currentPart = parts[currentPartIndex]; - const newPartIndex = getPartIndexByCursor(parts, newCursor, true); - const newPart = parts[newPartIndex]; - let partsInterval = []; - if (!currentPart || !newPart) { - return partsInterval; - } - // Push whole first affected part or sub-part of the first affected part - if (currentPart.position.start === cursor && currentPart.position.end <= newCursor) { - partsInterval.push(currentPart); - } - else { - partsInterval.push(generatePlainTextPart(currentPart.text.substr(cursor - currentPart.position.start, count))); - } - if (newPartIndex > currentPartIndex) { - // Concat fully included parts - partsInterval = partsInterval.concat(parts.slice(currentPartIndex + 1, newPartIndex)); - // Push whole last affected part or sub-part of the last affected part - if (newPart.position.end === newCursor && newPart.position.start >= cursor) { - partsInterval.push(newPart); - } - else { - partsInterval.push(generatePlainTextPart(newPart.text.substr(0, newCursor - newPart.position.start))); - } - } - return partsInterval; -}; -/** - * Function for getting object with keyword for each mention part type - * - * If keyword is undefined then we don't tracking mention typing and shouldn't show suggestions. - * If keyword is not undefined (even empty string '') then we are tracking mention typing. - * - * Examples where @name is just plain text yet, not mention: - * '|abc @name dfg' - keyword is undefined - * 'abc @| dfg' - keyword is '' - * 'abc @name| dfg' - keyword is 'name' - * 'abc @na|me dfg' - keyword is 'na' - * 'abc @|name dfg' - keyword is against '' - * 'abc @name |dfg' - keyword is 'name ' - * 'abc @name dfg|' - keyword is 'name dfg' - * 'abc @name dfg |' - keyword is undefined (we have more than one space) - * 'abc @name dfg he|' - keyword is undefined (we have more than one space) - */ -const getMentionPartSuggestionKeywords = (parts, plainText, selection, partTypes) => { - const keywordByTrigger = {}; - partTypes.filter(isMentionPartType).forEach(({ trigger, allowedSpacesCount = 1, }) => { - keywordByTrigger[trigger] = undefined; - // Check if we don't have selection range - if (selection.end != selection.start) { - return; - } - // Find the part with the cursor - const part = parts.find(one => selection.end > one.position.start && selection.end <= one.position.end); - // Check if the cursor is not in mention type part - if (part == null || part.data != null) { - return; - } - const triggerIndex = plainText.lastIndexOf(trigger, selection.end); - // Return undefined in case when: - if ( - // - the trigger index is not event found - triggerIndex == -1 - // - the trigger index is out of found part with selection cursor - || triggerIndex < part.position.start - // - the trigger is not at the beginning and we don't have space or new line before trigger - || (triggerIndex > 0 && !/[\s\n]/gi.test(plainText[triggerIndex - 1]))) { - return; - } - // Looking for break lines and spaces between the current cursor and trigger - let spacesCount = 0; - for (let cursor = selection.end - 1; cursor >= triggerIndex; cursor -= 1) { - // Mention cannot have new line - if (plainText[cursor] === '\n') { - return; - } - // Incrementing space counter if the next symbol is space - if (plainText[cursor] === ' ') { - spacesCount += 1; - // Check maximum allowed spaces in trigger word - if (spacesCount > allowedSpacesCount) { - return; - } - } - } - keywordByTrigger[trigger] = plainText.substring(triggerIndex + 1, selection.end); - }); - return keywordByTrigger; -}; -exports.getMentionPartSuggestionKeywords = getMentionPartSuggestionKeywords; -/** - * Generates new value when we changing text. - * - * @param parts full parts list - * @param originalText original plain text - * @param changedText changed plain text - */ -const generateValueFromPartsAndChangedText = (parts, originalText, changedText) => { - const changes = diff_1.diffChars(originalText, changedText); - let newParts = []; - let cursor = 0; - changes.forEach(change => { - switch (true) { - /** - * We should: - * - Move cursor forward on the changed text length - */ - case change.removed: { - cursor += change.count; - break; - } - /** - * We should: - * - Push new part to the parts with that new text - */ - case change.added: { - newParts.push(generatePlainTextPart(change.value)); - break; - } - /** - * We should concat parts that didn't change. - * - In case when we have only one affected part we should push only that one sub-part - * - In case we have two affected parts we should push first - */ - default: { - if (change.count !== 0) { - newParts = newParts.concat(getPartsInterval(parts, cursor, change.count)); - cursor += change.count; - } - break; - } - } - }); - return getValueFromParts(newParts); -}; -exports.generateValueFromPartsAndChangedText = generateValueFromPartsAndChangedText; -/** - * Method for adding suggestion to the parts and generating value. We should: - * - Find part with plain text where we were tracking mention typing using selection state - * - Split the part to next parts: - * -* Before new mention - * -* With new mention - * -* After mention with space at the beginning - * - Generate new parts array and convert it to value - * - * @param parts - full part list - * @param mentionType - actually the mention type - * @param plainText - current plain text - * @param selection - current selection - * @param suggestion - suggestion that should be added - */ -const generateValueWithAddedSuggestion = (parts, mentionType, plainText, selection, suggestion) => { - var _a; - const currentPartIndex = parts.findIndex(one => selection.end >= one.position.start && selection.end <= one.position.end); - const currentPart = parts[currentPartIndex]; - if (!currentPart) { - return; - } - const triggerPartIndex = currentPart.text.lastIndexOf(mentionType.trigger, selection.end - currentPart.position.start); - const newMentionPartPosition = { - start: triggerPartIndex, - end: selection.end - currentPart.position.start, - }; - const isInsertSpaceToNextPart = mentionType.isInsertSpaceAfterMention - // Cursor is at the very end of parts or text row - && (plainText.length === selection.end || ((_a = parts[currentPartIndex]) === null || _a === void 0 ? void 0 : _a.text.startsWith('\n', newMentionPartPosition.end))); - return getValueFromParts([ - ...parts.slice(0, currentPartIndex), - // Create part with string before mention - generatePlainTextPart(currentPart.text.substring(0, newMentionPartPosition.start)), - generateMentionPart(mentionType, Object.assign({ original: getMentionValue(mentionType.trigger, suggestion), trigger: mentionType.trigger }, suggestion)), - // Create part with rest of string after mention and add a space if needed - generatePlainTextPart(`${isInsertSpaceToNextPart ? ' ' : ''}${currentPart.text.substring(newMentionPartPosition.end)}`), - ...parts.slice(currentPartIndex + 1), - ]); -}; -exports.generateValueWithAddedSuggestion = generateValueWithAddedSuggestion; -/** - * Method for generating part for plain text - * - * @param text - plain text that will be added to the part - * @param positionOffset - position offset from the very beginning of text - */ -const generatePlainTextPart = (text, positionOffset = 0) => ({ - text, - position: { - start: positionOffset, - end: positionOffset + text.length, - }, -}); -exports.generatePlainTextPart = generatePlainTextPart; -/** - * Method for generating part for mention - * - * @param mentionPartType - * @param mention - mention data - * @param positionOffset - position offset from the very beginning of text - */ -const generateMentionPart = (mentionPartType, mention, positionOffset = 0) => { - const text = mentionPartType.getPlainString - ? mentionPartType.getPlainString(mention) - : defaultPlainStringGenerator(mentionPartType, mention); - return { - text, - position: { - start: positionOffset, - end: positionOffset + text.length, - }, - partType: mentionPartType, - data: mention, - }; -}; -exports.generateMentionPart = generateMentionPart; -/** - * Generates part for matched regex result - * - * @param partType - current part type (pattern or mention) - * @param result - matched regex result - * @param positionOffset - position offset from the very beginning of text - */ -const generateRegexResultPart = (partType, result, positionOffset = 0) => ({ - text: result[0], - position: { - start: positionOffset, - end: positionOffset + result[0].length, - }, - partType, -}); -/** - * Method for generation mention value that accepts mention regex - * - * @param trigger - * @param suggestion - */ -const getMentionValue = (trigger, suggestion) => `${trigger}[${suggestion.name}](${suggestion.id})`; -exports.getMentionValue = getMentionValue; -const getMentionDataFromRegExMatchResult = ([, original, trigger, name, id]) => ({ - original, - trigger, - name, - id, -}); -/** - * Recursive function for deep parse MentionInput's value and get plainText with parts - * - * @param value - the MentionInput's value - * @param partTypes - All provided part types - * @param positionOffset - offset from the very beginning of plain text - */ -const parseValue = (value, partTypes, positionOffset = 0) => { - if (value == null) { - value = ''; - } - let plainText = ''; - let parts = []; - // We don't have any part types so adding just plain text part - if (partTypes.length === 0) { - plainText += value; - parts.push(generatePlainTextPart(value, positionOffset)); - } - else { - const [partType, ...restPartTypes] = partTypes; - const regex = isMentionPartType(partType) ? mentionRegEx : partType.pattern; - const matches = Array.from(string_prototype_matchall_1.default(value !== null && value !== void 0 ? value : '', regex)); - // In case when we didn't get any matches continue parsing value with rest part types - if (matches.length === 0) { - return parseValue(value, restPartTypes, positionOffset); - } - // In case when we have some text before matched part parsing the text with rest part types - if (matches[0].index != 0) { - const text = value.substr(0, matches[0].index); - const plainTextAndParts = parseValue(text, restPartTypes, positionOffset); - parts = parts.concat(plainTextAndParts.parts); - plainText += plainTextAndParts.plainText; - } - // Iterating over all found pattern matches - for (let i = 0; i < matches.length; i++) { - const result = matches[i]; - if (isMentionPartType(partType)) { - const mentionData = getMentionDataFromRegExMatchResult(result); - // Matched pattern is a mention and the mention doesn't match current mention type - // We should parse the mention with rest part types - if (mentionData.trigger !== partType.trigger) { - const plainTextAndParts = parseValue(mentionData.original, restPartTypes, positionOffset + plainText.length); - parts = parts.concat(plainTextAndParts.parts); - plainText += plainTextAndParts.plainText; - } - else { - const part = generateMentionPart(partType, mentionData, positionOffset + plainText.length); - parts.push(part); - plainText += part.text; - } - } - else { - const part = generateRegexResultPart(partType, result, positionOffset + plainText.length); - parts.push(part); - plainText += part.text; - } - // Check if the result is not at the end of whole value so we have a text after matched part - // We should parse the text with rest part types - if ((result.index + result[0].length) !== value.length) { - // Check if it is the last result - const isLastResult = i === matches.length - 1; - // So we should to add the last substring of value after matched mention - const text = value.slice(result.index + result[0].length, isLastResult ? undefined : matches[i + 1].index); - const plainTextAndParts = parseValue(text, restPartTypes, positionOffset + plainText.length); - parts = parts.concat(plainTextAndParts.parts); - plainText += plainTextAndParts.plainText; - } - } - } - // Exiting from parseValue - return { - plainText, - parts, - }; -}; -exports.parseValue = parseValue; -/** - * Function for generation value from parts array - * - * @param parts - */ -const getValueFromParts = (parts) => parts - .map(item => (item.data ? item.data.original : item.text)) - .join(''); -exports.getValueFromParts = getValueFromParts; -/** - * Replace all mention values in value to some specified format - * - * @param value - value that is generated by MentionInput component - * @param replacer - function that takes mention object as parameter and returns string - */ -const replaceMentionValues = (value, replacer) => value.replace(mentionRegEx, (fullMatch, original, trigger, name, id) => replacer({ - original, - trigger, - name, - id, -})); -exports.replaceMentionValues = replaceMentionValues; -//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/dist/utils/utils.js.map b/dist/utils/utils.js.map deleted file mode 100644 index 3778172..0000000 --- a/dist/utils/utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAiC;AAEjC,qDAAqD;AACrD,0FAAiD;AAYjD;;;;;;;GAOG;AACH,MAAM,YAAY,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,CAAC;AAqCA,gCAAU;AAnCZ;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK;KAC/C,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACzD,IAAI,CAAC,EAAE,CAAC,CAAC;AA6BV,8CAAiB;AA3BnB;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,CAC3B,KAAa,EACb,QAA0C,EAC1C,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC;IACpF,QAAQ;IACR,OAAO;IACP,IAAI;IACJ,EAAE;CACH,CAAC,CAAC,CAAC;AAcF,oDAAoB"} \ No newline at end of file From e5f690bee8c8ee1e92ad394a8164a918d620eb50 Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 16:43:26 -0400 Subject: [PATCH 06/10] adding dist to .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6d5f090..487bd12 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ # .idea node_modules/ -dist +dist/ npm-debug.log yarn-error.log From 76fac8b7c90b6f6854d788bb68eb291ba1936b1b Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 17:08:43 -0400 Subject: [PATCH 07/10] allowing to pass an initial value for partsData --- src/components/mention-input.tsx | 5 +++-- src/types/types.ts | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/mention-input.tsx b/src/components/mention-input.tsx index 2a440ea..4777e03 100644 --- a/src/components/mention-input.tsx +++ b/src/components/mention-input.tsx @@ -23,6 +23,7 @@ const AddOrEdit = (arr: S[], val: S, i: number) => { arr[i] = val; } } + const MentionInput: FC = ( { value, @@ -33,7 +34,7 @@ const MentionInput: FC = ( inputRef: propInputRef, containerStyle, - + defaultPartsData = [], onSelectionChange, onChangePartsData, ...textInputProps @@ -42,7 +43,7 @@ const MentionInput: FC = ( const textInput = useRef(null); const [selection, setSelection] = useState({start: 0, end: 0}); - const [partsData, setPartsData] = useState([]); + const [partsData, setPartsData] = useState(defaultPartsData); const { plainText, diff --git a/src/types/types.ts b/src/types/types.ts index 9f8e761..33e3a55 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -100,7 +100,10 @@ type Part = { type MentionInputProps = Omit & { value: string; onChange: (value: string) => void; + // returns an array with the data passed in the onSuggestionPress method in renderSuggestion. It allows you to overload with data in case you need more than the name and the id onChangePartsData: (partsData: PartData[]) => void; + // Default value for partsData, useful when MentionInput is passed a value by the 'value' or 'defaultValue' property that the user has not entered. This property is only used as an initial value. + defaultPartsData: PartData[]; partTypes?: PartType[]; inputRef?: Ref; From 8ff9b979e0afcfa4cb4c7a65fc21ca742ccc4952 Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 17:10:45 -0400 Subject: [PATCH 08/10] removing dist from .gitignore for testing --- .gitignore | 1 - dist/components/index.d.ts | 1 + dist/components/index.js | 14 + dist/components/index.js.map | 1 + dist/components/mention-input.d.ts | 4 + dist/components/mention-input.js | 169 ++++++++++++ dist/components/mention-input.js.map | 1 + dist/index.d.ts | 3 + dist/index.js | 21 ++ dist/index.js.map | 1 + dist/types/index.d.ts | 1 + dist/types/index.js | 14 + dist/types/index.js.map | 1 + dist/types/types.d.ts | 69 +++++ dist/types/types.js | 3 + dist/types/types.js.map | 1 + dist/utils/index.d.ts | 1 + dist/utils/index.js | 14 + dist/utils/index.js.map | 1 + dist/utils/utils.d.ts | 104 +++++++ dist/utils/utils.js | 389 +++++++++++++++++++++++++++ dist/utils/utils.js.map | 1 + 22 files changed, 814 insertions(+), 1 deletion(-) create mode 100644 dist/components/index.d.ts create mode 100644 dist/components/index.js create mode 100644 dist/components/index.js.map create mode 100644 dist/components/mention-input.d.ts create mode 100644 dist/components/mention-input.js create mode 100644 dist/components/mention-input.js.map create mode 100644 dist/index.d.ts create mode 100644 dist/index.js create mode 100644 dist/index.js.map create mode 100644 dist/types/index.d.ts create mode 100644 dist/types/index.js create mode 100644 dist/types/index.js.map create mode 100644 dist/types/types.d.ts create mode 100644 dist/types/types.js create mode 100644 dist/types/types.js.map create mode 100644 dist/utils/index.d.ts create mode 100644 dist/utils/index.js create mode 100644 dist/utils/index.js.map create mode 100644 dist/utils/utils.d.ts create mode 100644 dist/utils/utils.js create mode 100644 dist/utils/utils.js.map diff --git a/.gitignore b/.gitignore index 487bd12..d6f2790 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ # .idea node_modules/ -dist/ npm-debug.log yarn-error.log diff --git a/dist/components/index.d.ts b/dist/components/index.d.ts new file mode 100644 index 0000000..31174cf --- /dev/null +++ b/dist/components/index.d.ts @@ -0,0 +1 @@ +export * from './mention-input'; diff --git a/dist/components/index.js b/dist/components/index.js new file mode 100644 index 0000000..8dc1254 --- /dev/null +++ b/dist/components/index.js @@ -0,0 +1,14 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./mention-input"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/components/index.js.map b/dist/components/index.js.map new file mode 100644 index 0000000..473e91b --- /dev/null +++ b/dist/components/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC"} \ No newline at end of file diff --git a/dist/components/mention-input.d.ts b/dist/components/mention-input.d.ts new file mode 100644 index 0000000..a6fcb73 --- /dev/null +++ b/dist/components/mention-input.d.ts @@ -0,0 +1,4 @@ +import { FC } from 'react'; +import { MentionInputProps } from '../types'; +declare const MentionInput: FC; +export { MentionInput }; diff --git a/dist/components/mention-input.js b/dist/components/mention-input.js new file mode 100644 index 0000000..5d48abc --- /dev/null +++ b/dist/components/mention-input.js @@ -0,0 +1,169 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.MentionInput = void 0; +const react_1 = __importStar(require("react")); +const react_native_1 = require("react-native"); +const utils_1 = require("../utils"); +const AddOrEdit = (arr, val, i) => { + if (i === -1) { + arr.push(val); + } + else { + arr[i] = val; + } +}; +const MentionInput = (_a) => { + var { value, onChange, partTypes = [], inputRef: propInputRef, containerStyle, defaultPartsData = [], onSelectionChange, onChangePartsData } = _a, textInputProps = __rest(_a, ["value", "onChange", "partTypes", "inputRef", "containerStyle", "defaultPartsData", "onSelectionChange", "onChangePartsData"]); + const textInput = react_1.useRef(null); + const [selection, setSelection] = react_1.useState({ start: 0, end: 0 }); + const [partsData, setPartsData] = react_1.useState(defaultPartsData); + const { plainText, parts, } = react_1.useMemo(() => utils_1.parseValue(value, partTypes), [value, partTypes]); + const handleSelectionChange = (event) => { + setSelection(event.nativeEvent.selection); + onSelectionChange && onSelectionChange(event); + }; + /** + * Callback that trigger on TextInput text change + * + * @param changedText + */ + const onChangeInput = (changedText) => { + const newValue = utils_1.generateValueFromPartsAndChangedText(parts, plainText, changedText); + const { parts: newParts } = utils_1.parseValue(newValue, partTypes); + partDataHasChanged(newParts); + onChange(newValue); + }; + /** + * Determines when the onChangePartsData event should triggerred + * @param newParts + */ + const partDataHasChanged = (newParts) => { + const partsWithData = newParts.filter(part => part.partType && utils_1.isMentionPartType(part.partType)); + const newPartsData = partsWithData.reduce((acc, part) => { + var _a, _b, _c; + const id = (_a = part.data) === null || _a === void 0 ? void 0 : _a.id; + const name = (_b = part.data) === null || _b === void 0 ? void 0 : _b.name; + const partData = partsData.find(pd => pd.id === id); + const accI = acc.findIndex(ad => ad.id === id); + const lastValue = acc[accI]; + const val = { cant: ((_c = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _c !== void 0 ? _c : 0) + 1, data: partData === null || partData === void 0 ? void 0 : partData.data, id, name }; + AddOrEdit(acc, val, accI); + return acc; + }, []); + const eventMustBeTriggered = newPartsData.length !== partsData.length + || newPartsData.some(npd => { var _a; return ((_a = partsData.find(pd => pd.id === npd.id)) === null || _a === void 0 ? void 0 : _a.cant) !== npd.cant; }); + if (eventMustBeTriggered) + ChangePartsData(newPartsData); + }; + const ChangePartsData = (newPartsData) => { + setPartsData(newPartsData); + if (typeof onChangePartsData === 'function') { + onChangePartsData(newPartsData); + } + }; + /** + * We memoize the keyword to know should we show mention suggestions or not + */ + const keywordByTrigger = react_1.useMemo(() => { + return utils_1.getMentionPartSuggestionKeywords(parts, plainText, selection, partTypes); + }, [parts, plainText, selection, partTypes]); + /** + * Callback on mention suggestion press. We should: + * - Get updated value + * - Trigger onChange callback with new value + */ + const onSuggestionPress = (mentionType) => (suggestion) => { + var _a; + const newValue = utils_1.generateValueWithAddedSuggestion(parts, mentionType, plainText, selection, suggestion); + if (!newValue) { + return; + } + // + const copyPartsData = [...partsData]; + const i = copyPartsData.findIndex(ad => ad.id === suggestion.id); + const lastValue = copyPartsData[i]; + const val = { + cant: ((_a = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _a !== void 0 ? _a : 0) + 1, + data: suggestion, + id: suggestion.id, + name: suggestion.name + }; + AddOrEdit(copyPartsData, val, i); + ChangePartsData(copyPartsData); + onChange(newValue); + /** + * Move cursor to the end of just added mention starting from trigger string and including: + * - Length of trigger string + * - Length of mention name + * - Length of space after mention (1) + * + * Not working now due to the RN bug + */ + // const newCursorPosition = currentPart.position.start + triggerPartIndex + trigger.length + + // suggestion.name.length + 1; + // textInput.current?.setNativeProps({selection: {start: newCursorPosition, end: newCursorPosition}}); + }; + const handleTextInputRef = (ref) => { + textInput.current = ref; + if (propInputRef) { + if (typeof propInputRef === 'function') { + propInputRef(ref); + } + else { + propInputRef.current = ref; + } + } + }; + const renderMentionSuggestions = (mentionType) => (react_1.default.createElement(react_1.default.Fragment, { key: mentionType.trigger }, mentionType.renderSuggestions && mentionType.renderSuggestions({ + keyword: keywordByTrigger[mentionType.trigger], + onSuggestionPress: onSuggestionPress(mentionType), + }))); + return (react_1.default.createElement(react_native_1.View, { style: containerStyle }, + partTypes + .filter(one => (utils_1.isMentionPartType(one) + && one.renderSuggestions != null + && !one.isBottomMentionSuggestionsRender)) + .map(renderMentionSuggestions), + react_1.default.createElement(react_native_1.TextInput, Object.assign({ multiline: true }, textInputProps, { ref: handleTextInputRef, onChangeText: onChangeInput, onSelectionChange: handleSelectionChange }), + react_1.default.createElement(react_native_1.Text, null, parts.map(({ text, partType, data }, index) => { + var _a, _b; + return partType ? (react_1.default.createElement(react_native_1.Text, { key: `${index}-${(_a = data === null || data === void 0 ? void 0 : data.trigger) !== null && _a !== void 0 ? _a : 'pattern'}`, style: (_b = partType.textStyle) !== null && _b !== void 0 ? _b : utils_1.defaultMentionTextStyle }, text)) : (react_1.default.createElement(react_native_1.Text, { key: index }, text)); + }))), + partTypes + .filter(one => (utils_1.isMentionPartType(one) + && one.renderSuggestions != null + && one.isBottomMentionSuggestionsRender)) + .map(renderMentionSuggestions))); +}; +exports.MentionInput = MentionInput; +//# sourceMappingURL=mention-input.js.map \ No newline at end of file diff --git a/dist/components/mention-input.js.map b/dist/components/mention-input.js.map new file mode 100644 index 0000000..97d188d --- /dev/null +++ b/dist/components/mention-input.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mention-input.js","sourceRoot":"","sources":["../../src/components/mention-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA+E;AAC/E,+CAMsB;AAGtB,oCAOkB;AAClB,MAAM,SAAS,GAAG,CAAoB,GAAQ,EAAE,GAAM,EAAE,CAAS,EAAE,EAAE;IACnE,IAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QACX,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACf;SAAM;QACL,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;KACd;AACH,CAAC,CAAA;AAED,MAAM,YAAY,GAA0B,CAC1C,EAaqB,EACrB,EAAE;QAdF,EACE,KAAK,EACL,QAAQ,EAER,SAAS,GAAG,EAAE,EAEd,QAAQ,EAAE,YAAY,EAEtB,cAAc,EACd,gBAAgB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,EAAC,EAAE,KAAK,EAAE,EAAE;;gBAAC,OAAA,QAAQ,CAAC,CAAC,CAAC,CACvD,8BAAC,mBAAI,IACH,GAAG,EAAE,GAAG,KAAK,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,mCAAI,SAAS,EAAE,EAC7C,KAAK,EAAE,MAAA,QAAQ,CAAC,SAAS,mCAAI,+BAAuB,IAEnD,IAAI,CACA,CACR,CAAC,CAAC,CAAC,CACF,8BAAC,mBAAI,IAAC,GAAG,EAAE,KAAK,IAAG,IAAI,CAAQ,CAChC,CAAA;aAAA,CAAC,CACG,CACG;QAEV,SAAS;aACR,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CACb,yBAAiB,CAAC,GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,GAAG,CAAC,gCAAgC,CACxC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC,CAE3B,CACR,CAAC;AACJ,CAAC,CAAC;AAEO,oCAAY"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..d9a1101 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,3 @@ +export * from './components'; +export type { Suggestion, Part, MentionSuggestionsProps, PartType, } from './types'; +export { mentionRegEx, isMentionPartType, getMentionValue, parseValue, replaceMentionValues, } from './utils'; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..9ece04b --- /dev/null +++ b/dist/index.js @@ -0,0 +1,21 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.replaceMentionValues = exports.parseValue = exports.getMentionValue = exports.isMentionPartType = exports.mentionRegEx = void 0; +__exportStar(require("./components"), exports); +var utils_1 = require("./utils"); +Object.defineProperty(exports, "mentionRegEx", { enumerable: true, get: function () { return utils_1.mentionRegEx; } }); +Object.defineProperty(exports, "isMentionPartType", { enumerable: true, get: function () { return utils_1.isMentionPartType; } }); +Object.defineProperty(exports, "getMentionValue", { enumerable: true, get: function () { return utils_1.getMentionValue; } }); +Object.defineProperty(exports, "parseValue", { enumerable: true, get: function () { return utils_1.parseValue; } }); +Object.defineProperty(exports, "replaceMentionValues", { enumerable: true, get: function () { return utils_1.replaceMentionValues; } }); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000..681fe4b --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAA6B;AAM7B,iCAEiB;AADf,qGAAA,YAAY,OAAA;AAAE,0GAAA,iBAAiB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAAE,mGAAA,UAAU,OAAA;AAAE,6GAAA,oBAAoB,OAAA"} \ No newline at end of file diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts new file mode 100644 index 0000000..fcb073f --- /dev/null +++ b/dist/types/index.d.ts @@ -0,0 +1 @@ +export * from './types'; diff --git a/dist/types/index.js b/dist/types/index.js new file mode 100644 index 0000000..66b0c96 --- /dev/null +++ b/dist/types/index.js @@ -0,0 +1,14 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./types"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/types/index.js.map b/dist/types/index.js.map new file mode 100644 index 0000000..881fa19 --- /dev/null +++ b/dist/types/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB"} \ No newline at end of file diff --git a/dist/types/types.d.ts b/dist/types/types.d.ts new file mode 100644 index 0000000..e3da739 --- /dev/null +++ b/dist/types/types.d.ts @@ -0,0 +1,69 @@ +import type { Change } from 'diff'; +import type { ReactNode, Ref } from 'react'; +import type { StyleProp, TextInput, TextInputProps, TextStyle, ViewStyle } from 'react-native'; +declare type Suggestion = { + id: string; + name: string; +}; +declare type MentionData = { + original: string; + trigger: string; + name: string; + id: string; +}; +declare type PartData = { + name: string; + id: string; + cant: number; + data: any; +}; +declare type CharactersDiffChange = Omit & { + count: number; +}; +declare type RegexMatchResult = string[] & { + 0: string; + 1: string; + 2: string; + 3: string; + 4: string; + index: number; + groups: MentionData; +}; +declare type Position = { + start: number; + end: number; +}; +declare type MentionSuggestionsProps = { + keyword: string | undefined; + onSuggestionPress: (suggestion: Suggestion) => void; +}; +declare type MentionPartType = { + trigger: string; + renderSuggestions?: (props: MentionSuggestionsProps) => ReactNode; + allowedSpacesCount?: number; + isInsertSpaceAfterMention?: boolean; + isBottomMentionSuggestionsRender?: boolean; + textStyle?: StyleProp; + getPlainString?: (mention: MentionData) => string; +}; +declare type PatternPartType = { + pattern: RegExp; + textStyle?: StyleProp; +}; +declare type PartType = MentionPartType | PatternPartType; +declare type Part = { + text: string; + position: Position; + partType?: PartType; + data?: MentionData; +}; +declare type MentionInputProps = Omit & { + value: string; + onChange: (value: string) => void; + onChangePartsData: (partsData: PartData[]) => void; + defaultPartsData: PartData[]; + partTypes?: PartType[]; + inputRef?: Ref; + containerStyle?: StyleProp; +}; +export type { Suggestion, MentionData, CharactersDiffChange, RegexMatchResult, Position, Part, MentionSuggestionsProps, MentionPartType, PatternPartType, PartType, MentionInputProps, PartData }; diff --git a/dist/types/types.js b/dist/types/types.js new file mode 100644 index 0000000..11e638d --- /dev/null +++ b/dist/types/types.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/types/types.js.map b/dist/types/types.js.map new file mode 100644 index 0000000..67c6c9d --- /dev/null +++ b/dist/types/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/utils/index.d.ts b/dist/utils/index.d.ts new file mode 100644 index 0000000..04bca77 --- /dev/null +++ b/dist/utils/index.d.ts @@ -0,0 +1 @@ +export * from './utils'; diff --git a/dist/utils/index.js b/dist/utils/index.js new file mode 100644 index 0000000..e6f0868 --- /dev/null +++ b/dist/utils/index.js @@ -0,0 +1,14 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./utils"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/utils/index.js.map b/dist/utils/index.js.map new file mode 100644 index 0000000..b6566c7 --- /dev/null +++ b/dist/utils/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB"} \ No newline at end of file diff --git a/dist/utils/utils.d.ts b/dist/utils/utils.d.ts new file mode 100644 index 0000000..f1880b6 --- /dev/null +++ b/dist/utils/utils.d.ts @@ -0,0 +1,104 @@ +import { StyleProp, TextStyle } from 'react-native'; +import { MentionData, MentionPartType, Part, PartType, Position, Suggestion } from '../types'; +/** + * RegEx grouped results. Example - "@[Full Name](123abc)" + * We have 4 groups here: + * - The whole original string - "@[Full Name](123abc)" + * - Mention trigger - "@" + * - Name - "Full Name" + * - Id - "123abc" + */ +declare const mentionRegEx: RegExp; +declare const defaultMentionTextStyle: StyleProp; +declare const isMentionPartType: (partType: PartType) => partType is MentionPartType; +/** + * Function for getting object with keyword for each mention part type + * + * If keyword is undefined then we don't tracking mention typing and shouldn't show suggestions. + * If keyword is not undefined (even empty string '') then we are tracking mention typing. + * + * Examples where @name is just plain text yet, not mention: + * '|abc @name dfg' - keyword is undefined + * 'abc @| dfg' - keyword is '' + * 'abc @name| dfg' - keyword is 'name' + * 'abc @na|me dfg' - keyword is 'na' + * 'abc @|name dfg' - keyword is against '' + * 'abc @name |dfg' - keyword is 'name ' + * 'abc @name dfg|' - keyword is 'name dfg' + * 'abc @name dfg |' - keyword is undefined (we have more than one space) + * 'abc @name dfg he|' - keyword is undefined (we have more than one space) + */ +declare const getMentionPartSuggestionKeywords: (parts: Part[], plainText: string, selection: Position, partTypes: PartType[]) => { + [trigger: string]: string | undefined; +}; +/** + * Generates new value when we changing text. + * + * @param parts full parts list + * @param originalText original plain text + * @param changedText changed plain text + */ +declare const generateValueFromPartsAndChangedText: (parts: Part[], originalText: string, changedText: string) => string; +/** + * Method for adding suggestion to the parts and generating value. We should: + * - Find part with plain text where we were tracking mention typing using selection state + * - Split the part to next parts: + * -* Before new mention + * -* With new mention + * -* After mention with space at the beginning + * - Generate new parts array and convert it to value + * + * @param parts - full part list + * @param mentionType - actually the mention type + * @param plainText - current plain text + * @param selection - current selection + * @param suggestion - suggestion that should be added + */ +declare const generateValueWithAddedSuggestion: (parts: Part[], mentionType: MentionPartType, plainText: string, selection: Position, suggestion: Suggestion) => string | undefined; +/** + * Method for generating part for plain text + * + * @param text - plain text that will be added to the part + * @param positionOffset - position offset from the very beginning of text + */ +declare const generatePlainTextPart: (text: string, positionOffset?: number) => Part; +/** + * Method for generating part for mention + * + * @param mentionPartType + * @param mention - mention data + * @param positionOffset - position offset from the very beginning of text + */ +declare const generateMentionPart: (mentionPartType: MentionPartType, mention: MentionData, positionOffset?: number) => Part; +/** + * Method for generation mention value that accepts mention regex + * + * @param trigger + * @param suggestion + */ +declare const getMentionValue: (trigger: string, suggestion: Suggestion) => string; +/** + * Recursive function for deep parse MentionInput's value and get plainText with parts + * + * @param value - the MentionInput's value + * @param partTypes - All provided part types + * @param positionOffset - offset from the very beginning of plain text + */ +declare const parseValue: (value: string, partTypes: PartType[], positionOffset?: number) => { + plainText: string; + parts: Part[]; +}; +/** + * Function for generation value from parts array + * + * @param parts + */ +declare const getValueFromParts: (parts: Part[]) => string; +/** + * Replace all mention values in value to some specified format + * + * @param value - value that is generated by MentionInput component + * @param replacer - function that takes mention object as parameter and returns string + */ +declare const replaceMentionValues: (value: string, replacer: (mention: MentionData) => string) => string; +export { mentionRegEx, defaultMentionTextStyle, isMentionPartType, getMentionPartSuggestionKeywords, generateValueFromPartsAndChangedText, generateValueWithAddedSuggestion, generatePlainTextPart, generateMentionPart, getMentionValue, parseValue, getValueFromParts, replaceMentionValues, }; diff --git a/dist/utils/utils.js b/dist/utils/utils.js new file mode 100644 index 0000000..56c9eba --- /dev/null +++ b/dist/utils/utils.js @@ -0,0 +1,389 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.replaceMentionValues = exports.getValueFromParts = exports.parseValue = exports.getMentionValue = exports.generateMentionPart = exports.generatePlainTextPart = exports.generateValueWithAddedSuggestion = exports.generateValueFromPartsAndChangedText = exports.getMentionPartSuggestionKeywords = exports.isMentionPartType = exports.defaultMentionTextStyle = exports.mentionRegEx = void 0; +const diff_1 = require("diff"); +// @ts-ignore the lib do not have TS declarations yet +const string_prototype_matchall_1 = __importDefault(require("string.prototype.matchall")); +/** + * RegEx grouped results. Example - "@[Full Name](123abc)" + * We have 4 groups here: + * - The whole original string - "@[Full Name](123abc)" + * - Mention trigger - "@" + * - Name - "Full Name" + * - Id - "123abc" + */ +const mentionRegEx = /((.)\[([^[]*)]\(([^(^)]*)\))/gi; +exports.mentionRegEx = mentionRegEx; +const defaultMentionTextStyle = { fontWeight: 'bold', color: 'blue' }; +exports.defaultMentionTextStyle = defaultMentionTextStyle; +const defaultPlainStringGenerator = ({ trigger }, { name }) => `${trigger}${name}`; +const isMentionPartType = (partType) => { + return partType.trigger != null; +}; +exports.isMentionPartType = isMentionPartType; +const getPartIndexByCursor = (parts, cursor, isIncludeEnd) => { + return parts.findIndex(one => cursor >= one.position.start && isIncludeEnd ? cursor <= one.position.end : cursor < one.position.end); +}; +/** + * The method for getting parts between two cursor positions. + * ``` + * | part1 | part2 | part3 | + * a b c|d e f g h i j h k|l m n o + * ``` + * We will get 3 parts here: + * 1. Part included 'd' + * 2. Part included 'efghij' + * 3. Part included 'hk' + * Cursor will move to position after 'k' + * + * @param parts full part list + * @param cursor current cursor position + * @param count count of characters that didn't change + */ +const getPartsInterval = (parts, cursor, count) => { + const newCursor = cursor + count; + const currentPartIndex = getPartIndexByCursor(parts, cursor); + const currentPart = parts[currentPartIndex]; + const newPartIndex = getPartIndexByCursor(parts, newCursor, true); + const newPart = parts[newPartIndex]; + let partsInterval = []; + if (!currentPart || !newPart) { + return partsInterval; + } + // Push whole first affected part or sub-part of the first affected part + if (currentPart.position.start === cursor && currentPart.position.end <= newCursor) { + partsInterval.push(currentPart); + } + else { + partsInterval.push(generatePlainTextPart(currentPart.text.substr(cursor - currentPart.position.start, count))); + } + if (newPartIndex > currentPartIndex) { + // Concat fully included parts + partsInterval = partsInterval.concat(parts.slice(currentPartIndex + 1, newPartIndex)); + // Push whole last affected part or sub-part of the last affected part + if (newPart.position.end === newCursor && newPart.position.start >= cursor) { + partsInterval.push(newPart); + } + else { + partsInterval.push(generatePlainTextPart(newPart.text.substr(0, newCursor - newPart.position.start))); + } + } + return partsInterval; +}; +/** + * Function for getting object with keyword for each mention part type + * + * If keyword is undefined then we don't tracking mention typing and shouldn't show suggestions. + * If keyword is not undefined (even empty string '') then we are tracking mention typing. + * + * Examples where @name is just plain text yet, not mention: + * '|abc @name dfg' - keyword is undefined + * 'abc @| dfg' - keyword is '' + * 'abc @name| dfg' - keyword is 'name' + * 'abc @na|me dfg' - keyword is 'na' + * 'abc @|name dfg' - keyword is against '' + * 'abc @name |dfg' - keyword is 'name ' + * 'abc @name dfg|' - keyword is 'name dfg' + * 'abc @name dfg |' - keyword is undefined (we have more than one space) + * 'abc @name dfg he|' - keyword is undefined (we have more than one space) + */ +const getMentionPartSuggestionKeywords = (parts, plainText, selection, partTypes) => { + const keywordByTrigger = {}; + partTypes.filter(isMentionPartType).forEach(({ trigger, allowedSpacesCount = 1, }) => { + keywordByTrigger[trigger] = undefined; + // Check if we don't have selection range + if (selection.end != selection.start) { + return; + } + // Find the part with the cursor + const part = parts.find(one => selection.end > one.position.start && selection.end <= one.position.end); + // Check if the cursor is not in mention type part + if (part == null || part.data != null) { + return; + } + const triggerIndex = plainText.lastIndexOf(trigger, selection.end); + // Return undefined in case when: + if ( + // - the trigger index is not event found + triggerIndex == -1 + // - the trigger index is out of found part with selection cursor + || triggerIndex < part.position.start + // - the trigger is not at the beginning and we don't have space or new line before trigger + || (triggerIndex > 0 && !/[\s\n]/gi.test(plainText[triggerIndex - 1]))) { + return; + } + // Looking for break lines and spaces between the current cursor and trigger + let spacesCount = 0; + for (let cursor = selection.end - 1; cursor >= triggerIndex; cursor -= 1) { + // Mention cannot have new line + if (plainText[cursor] === '\n') { + return; + } + // Incrementing space counter if the next symbol is space + if (plainText[cursor] === ' ') { + spacesCount += 1; + // Check maximum allowed spaces in trigger word + if (spacesCount > allowedSpacesCount) { + return; + } + } + } + keywordByTrigger[trigger] = plainText.substring(triggerIndex + 1, selection.end); + }); + return keywordByTrigger; +}; +exports.getMentionPartSuggestionKeywords = getMentionPartSuggestionKeywords; +/** + * Generates new value when we changing text. + * + * @param parts full parts list + * @param originalText original plain text + * @param changedText changed plain text + */ +const generateValueFromPartsAndChangedText = (parts, originalText, changedText) => { + const changes = diff_1.diffChars(originalText, changedText); + let newParts = []; + let cursor = 0; + changes.forEach(change => { + switch (true) { + /** + * We should: + * - Move cursor forward on the changed text length + */ + case change.removed: { + cursor += change.count; + break; + } + /** + * We should: + * - Push new part to the parts with that new text + */ + case change.added: { + newParts.push(generatePlainTextPart(change.value)); + break; + } + /** + * We should concat parts that didn't change. + * - In case when we have only one affected part we should push only that one sub-part + * - In case we have two affected parts we should push first + */ + default: { + if (change.count !== 0) { + newParts = newParts.concat(getPartsInterval(parts, cursor, change.count)); + cursor += change.count; + } + break; + } + } + }); + return getValueFromParts(newParts); +}; +exports.generateValueFromPartsAndChangedText = generateValueFromPartsAndChangedText; +/** + * Method for adding suggestion to the parts and generating value. We should: + * - Find part with plain text where we were tracking mention typing using selection state + * - Split the part to next parts: + * -* Before new mention + * -* With new mention + * -* After mention with space at the beginning + * - Generate new parts array and convert it to value + * + * @param parts - full part list + * @param mentionType - actually the mention type + * @param plainText - current plain text + * @param selection - current selection + * @param suggestion - suggestion that should be added + */ +const generateValueWithAddedSuggestion = (parts, mentionType, plainText, selection, suggestion) => { + var _a; + const currentPartIndex = parts.findIndex(one => selection.end >= one.position.start && selection.end <= one.position.end); + const currentPart = parts[currentPartIndex]; + if (!currentPart) { + return; + } + const triggerPartIndex = currentPart.text.lastIndexOf(mentionType.trigger, selection.end - currentPart.position.start); + const newMentionPartPosition = { + start: triggerPartIndex, + end: selection.end - currentPart.position.start, + }; + const isInsertSpaceToNextPart = mentionType.isInsertSpaceAfterMention + // Cursor is at the very end of parts or text row + && (plainText.length === selection.end || ((_a = parts[currentPartIndex]) === null || _a === void 0 ? void 0 : _a.text.startsWith('\n', newMentionPartPosition.end))); + return getValueFromParts([ + ...parts.slice(0, currentPartIndex), + // Create part with string before mention + generatePlainTextPart(currentPart.text.substring(0, newMentionPartPosition.start)), + generateMentionPart(mentionType, Object.assign({ original: getMentionValue(mentionType.trigger, suggestion), trigger: mentionType.trigger }, suggestion)), + // Create part with rest of string after mention and add a space if needed + generatePlainTextPart(`${isInsertSpaceToNextPart ? ' ' : ''}${currentPart.text.substring(newMentionPartPosition.end)}`), + ...parts.slice(currentPartIndex + 1), + ]); +}; +exports.generateValueWithAddedSuggestion = generateValueWithAddedSuggestion; +/** + * Method for generating part for plain text + * + * @param text - plain text that will be added to the part + * @param positionOffset - position offset from the very beginning of text + */ +const generatePlainTextPart = (text, positionOffset = 0) => ({ + text, + position: { + start: positionOffset, + end: positionOffset + text.length, + }, +}); +exports.generatePlainTextPart = generatePlainTextPart; +/** + * Method for generating part for mention + * + * @param mentionPartType + * @param mention - mention data + * @param positionOffset - position offset from the very beginning of text + */ +const generateMentionPart = (mentionPartType, mention, positionOffset = 0) => { + const text = mentionPartType.getPlainString + ? mentionPartType.getPlainString(mention) + : defaultPlainStringGenerator(mentionPartType, mention); + return { + text, + position: { + start: positionOffset, + end: positionOffset + text.length, + }, + partType: mentionPartType, + data: mention, + }; +}; +exports.generateMentionPart = generateMentionPart; +/** + * Generates part for matched regex result + * + * @param partType - current part type (pattern or mention) + * @param result - matched regex result + * @param positionOffset - position offset from the very beginning of text + */ +const generateRegexResultPart = (partType, result, positionOffset = 0) => ({ + text: result[0], + position: { + start: positionOffset, + end: positionOffset + result[0].length, + }, + partType, +}); +/** + * Method for generation mention value that accepts mention regex + * + * @param trigger + * @param suggestion + */ +const getMentionValue = (trigger, suggestion) => `${trigger}[${suggestion.name}](${suggestion.id})`; +exports.getMentionValue = getMentionValue; +const getMentionDataFromRegExMatchResult = ([, original, trigger, name, id]) => ({ + original, + trigger, + name, + id, +}); +/** + * Recursive function for deep parse MentionInput's value and get plainText with parts + * + * @param value - the MentionInput's value + * @param partTypes - All provided part types + * @param positionOffset - offset from the very beginning of plain text + */ +const parseValue = (value, partTypes, positionOffset = 0) => { + if (value == null) { + value = ''; + } + let plainText = ''; + let parts = []; + // We don't have any part types so adding just plain text part + if (partTypes.length === 0) { + plainText += value; + parts.push(generatePlainTextPart(value, positionOffset)); + } + else { + const [partType, ...restPartTypes] = partTypes; + const regex = isMentionPartType(partType) ? mentionRegEx : partType.pattern; + const matches = Array.from(string_prototype_matchall_1.default(value !== null && value !== void 0 ? value : '', regex)); + // In case when we didn't get any matches continue parsing value with rest part types + if (matches.length === 0) { + return parseValue(value, restPartTypes, positionOffset); + } + // In case when we have some text before matched part parsing the text with rest part types + if (matches[0].index != 0) { + const text = value.substr(0, matches[0].index); + const plainTextAndParts = parseValue(text, restPartTypes, positionOffset); + parts = parts.concat(plainTextAndParts.parts); + plainText += plainTextAndParts.plainText; + } + // Iterating over all found pattern matches + for (let i = 0; i < matches.length; i++) { + const result = matches[i]; + if (isMentionPartType(partType)) { + const mentionData = getMentionDataFromRegExMatchResult(result); + // Matched pattern is a mention and the mention doesn't match current mention type + // We should parse the mention with rest part types + if (mentionData.trigger !== partType.trigger) { + const plainTextAndParts = parseValue(mentionData.original, restPartTypes, positionOffset + plainText.length); + parts = parts.concat(plainTextAndParts.parts); + plainText += plainTextAndParts.plainText; + } + else { + const part = generateMentionPart(partType, mentionData, positionOffset + plainText.length); + parts.push(part); + plainText += part.text; + } + } + else { + const part = generateRegexResultPart(partType, result, positionOffset + plainText.length); + parts.push(part); + plainText += part.text; + } + // Check if the result is not at the end of whole value so we have a text after matched part + // We should parse the text with rest part types + if ((result.index + result[0].length) !== value.length) { + // Check if it is the last result + const isLastResult = i === matches.length - 1; + // So we should to add the last substring of value after matched mention + const text = value.slice(result.index + result[0].length, isLastResult ? undefined : matches[i + 1].index); + const plainTextAndParts = parseValue(text, restPartTypes, positionOffset + plainText.length); + parts = parts.concat(plainTextAndParts.parts); + plainText += plainTextAndParts.plainText; + } + } + } + // Exiting from parseValue + return { + plainText, + parts, + }; +}; +exports.parseValue = parseValue; +/** + * Function for generation value from parts array + * + * @param parts + */ +const getValueFromParts = (parts) => parts + .map(item => (item.data ? item.data.original : item.text)) + .join(''); +exports.getValueFromParts = getValueFromParts; +/** + * Replace all mention values in value to some specified format + * + * @param value - value that is generated by MentionInput component + * @param replacer - function that takes mention object as parameter and returns string + */ +const replaceMentionValues = (value, replacer) => value.replace(mentionRegEx, (fullMatch, original, trigger, name, id) => replacer({ + original, + trigger, + name, + id, +})); +exports.replaceMentionValues = replaceMentionValues; +//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/dist/utils/utils.js.map b/dist/utils/utils.js.map new file mode 100644 index 0000000..3778172 --- /dev/null +++ b/dist/utils/utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAiC;AAEjC,qDAAqD;AACrD,0FAAiD;AAYjD;;;;;;;GAOG;AACH,MAAM,YAAY,GAAG,gCAAgC,CAAC;AA+cpD,oCAAY;AA7cd,MAAM,uBAAuB,GAAyB,EAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAC,CAAC;AA8cxF,0DAAuB;AA5czB,MAAM,2BAA2B,GAAG,CAAC,EAAC,OAAO,EAAkB,EAAE,EAAC,IAAI,EAAc,EAAE,EAAE,CAAC,GAAG,OAAO,GAAG,IAAI,EAAE,CAAC;AAE7G,MAAM,iBAAiB,GAAG,CAAC,QAAkB,EAA+B,EAAE;IAC5E,OAAQ,QAA4B,CAAC,OAAO,IAAI,IAAI,CAAC;AACvD,CAAC,CAAC;AAycA,8CAAiB;AAvcnB,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAE,MAAc,EAAE,YAAsB,EAAE,E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,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC;IACpF,QAAQ;IACR,OAAO;IACP,IAAI;IACJ,EAAE;CACH,CAAC,CAAC,CAAC;AAcF,oDAAoB"} \ No newline at end of file From d1d1fe26d835a45187d940886de33a09d583dacc Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 17:23:09 -0400 Subject: [PATCH 09/10] removing dist folder and adding it to .gitignore, removing cant prop from defaultPartsData --- .gitignore | 1 + dist/components/index.d.ts | 1 - dist/components/index.js | 14 - dist/components/index.js.map | 1 - dist/components/mention-input.d.ts | 4 - dist/components/mention-input.js | 169 ------------ dist/components/mention-input.js.map | 1 - dist/index.d.ts | 3 - dist/index.js | 21 -- dist/index.js.map | 1 - dist/types/index.d.ts | 1 - dist/types/index.js | 14 - dist/types/index.js.map | 1 - dist/types/types.d.ts | 69 ----- dist/types/types.js | 3 - dist/types/types.js.map | 1 - dist/utils/index.d.ts | 1 - dist/utils/index.js | 14 - dist/utils/index.js.map | 1 - dist/utils/utils.d.ts | 104 ------- dist/utils/utils.js | 389 --------------------------- dist/utils/utils.js.map | 1 - src/types/types.ts | 2 +- 23 files changed, 2 insertions(+), 815 deletions(-) delete mode 100644 dist/components/index.d.ts delete mode 100644 dist/components/index.js delete mode 100644 dist/components/index.js.map delete mode 100644 dist/components/mention-input.d.ts delete mode 100644 dist/components/mention-input.js delete mode 100644 dist/components/mention-input.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 dist/types/index.d.ts delete mode 100644 dist/types/index.js delete mode 100644 dist/types/index.js.map delete mode 100644 dist/types/types.d.ts delete mode 100644 dist/types/types.js delete mode 100644 dist/types/types.js.map delete mode 100644 dist/utils/index.d.ts delete mode 100644 dist/utils/index.js delete mode 100644 dist/utils/index.js.map delete mode 100644 dist/utils/utils.d.ts delete mode 100644 dist/utils/utils.js delete mode 100644 dist/utils/utils.js.map diff --git a/.gitignore b/.gitignore index d6f2790..487bd12 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ # .idea node_modules/ +dist/ npm-debug.log yarn-error.log diff --git a/dist/components/index.d.ts b/dist/components/index.d.ts deleted file mode 100644 index 31174cf..0000000 --- a/dist/components/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './mention-input'; diff --git a/dist/components/index.js b/dist/components/index.js deleted file mode 100644 index 8dc1254..0000000 --- a/dist/components/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./mention-input"), exports); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/components/index.js.map b/dist/components/index.js.map deleted file mode 100644 index 473e91b..0000000 --- a/dist/components/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC"} \ No newline at end of file diff --git a/dist/components/mention-input.d.ts b/dist/components/mention-input.d.ts deleted file mode 100644 index a6fcb73..0000000 --- a/dist/components/mention-input.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { FC } from 'react'; -import { MentionInputProps } from '../types'; -declare const MentionInput: FC; -export { MentionInput }; diff --git a/dist/components/mention-input.js b/dist/components/mention-input.js deleted file mode 100644 index 5d48abc..0000000 --- a/dist/components/mention-input.js +++ /dev/null @@ -1,169 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __rest = (this && this.__rest) || function (s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.MentionInput = void 0; -const react_1 = __importStar(require("react")); -const react_native_1 = require("react-native"); -const utils_1 = require("../utils"); -const AddOrEdit = (arr, val, i) => { - if (i === -1) { - arr.push(val); - } - else { - arr[i] = val; - } -}; -const MentionInput = (_a) => { - var { value, onChange, partTypes = [], inputRef: propInputRef, containerStyle, defaultPartsData = [], onSelectionChange, onChangePartsData } = _a, textInputProps = __rest(_a, ["value", "onChange", "partTypes", "inputRef", "containerStyle", "defaultPartsData", "onSelectionChange", "onChangePartsData"]); - const textInput = react_1.useRef(null); - const [selection, setSelection] = react_1.useState({ start: 0, end: 0 }); - const [partsData, setPartsData] = react_1.useState(defaultPartsData); - const { plainText, parts, } = react_1.useMemo(() => utils_1.parseValue(value, partTypes), [value, partTypes]); - const handleSelectionChange = (event) => { - setSelection(event.nativeEvent.selection); - onSelectionChange && onSelectionChange(event); - }; - /** - * Callback that trigger on TextInput text change - * - * @param changedText - */ - const onChangeInput = (changedText) => { - const newValue = utils_1.generateValueFromPartsAndChangedText(parts, plainText, changedText); - const { parts: newParts } = utils_1.parseValue(newValue, partTypes); - partDataHasChanged(newParts); - onChange(newValue); - }; - /** - * Determines when the onChangePartsData event should triggerred - * @param newParts - */ - const partDataHasChanged = (newParts) => { - const partsWithData = newParts.filter(part => part.partType && utils_1.isMentionPartType(part.partType)); - const newPartsData = partsWithData.reduce((acc, part) => { - var _a, _b, _c; - const id = (_a = part.data) === null || _a === void 0 ? void 0 : _a.id; - const name = (_b = part.data) === null || _b === void 0 ? void 0 : _b.name; - const partData = partsData.find(pd => pd.id === id); - const accI = acc.findIndex(ad => ad.id === id); - const lastValue = acc[accI]; - const val = { cant: ((_c = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _c !== void 0 ? _c : 0) + 1, data: partData === null || partData === void 0 ? void 0 : partData.data, id, name }; - AddOrEdit(acc, val, accI); - return acc; - }, []); - const eventMustBeTriggered = newPartsData.length !== partsData.length - || newPartsData.some(npd => { var _a; return ((_a = partsData.find(pd => pd.id === npd.id)) === null || _a === void 0 ? void 0 : _a.cant) !== npd.cant; }); - if (eventMustBeTriggered) - ChangePartsData(newPartsData); - }; - const ChangePartsData = (newPartsData) => { - setPartsData(newPartsData); - if (typeof onChangePartsData === 'function') { - onChangePartsData(newPartsData); - } - }; - /** - * We memoize the keyword to know should we show mention suggestions or not - */ - const keywordByTrigger = react_1.useMemo(() => { - return utils_1.getMentionPartSuggestionKeywords(parts, plainText, selection, partTypes); - }, [parts, plainText, selection, partTypes]); - /** - * Callback on mention suggestion press. We should: - * - Get updated value - * - Trigger onChange callback with new value - */ - const onSuggestionPress = (mentionType) => (suggestion) => { - var _a; - const newValue = utils_1.generateValueWithAddedSuggestion(parts, mentionType, plainText, selection, suggestion); - if (!newValue) { - return; - } - // - const copyPartsData = [...partsData]; - const i = copyPartsData.findIndex(ad => ad.id === suggestion.id); - const lastValue = copyPartsData[i]; - const val = { - cant: ((_a = lastValue === null || lastValue === void 0 ? void 0 : lastValue.cant) !== null && _a !== void 0 ? _a : 0) + 1, - data: suggestion, - id: suggestion.id, - name: suggestion.name - }; - AddOrEdit(copyPartsData, val, i); - ChangePartsData(copyPartsData); - onChange(newValue); - /** - * Move cursor to the end of just added mention starting from trigger string and including: - * - Length of trigger string - * - Length of mention name - * - Length of space after mention (1) - * - * Not working now due to the RN bug - */ - // const newCursorPosition = currentPart.position.start + triggerPartIndex + trigger.length + - // suggestion.name.length + 1; - // textInput.current?.setNativeProps({selection: {start: newCursorPosition, end: newCursorPosition}}); - }; - const handleTextInputRef = (ref) => { - textInput.current = ref; - if (propInputRef) { - if (typeof propInputRef === 'function') { - propInputRef(ref); - } - else { - propInputRef.current = ref; - } - } - }; - const renderMentionSuggestions = (mentionType) => (react_1.default.createElement(react_1.default.Fragment, { key: mentionType.trigger }, mentionType.renderSuggestions && mentionType.renderSuggestions({ - keyword: keywordByTrigger[mentionType.trigger], - onSuggestionPress: onSuggestionPress(mentionType), - }))); - return (react_1.default.createElement(react_native_1.View, { style: containerStyle }, - partTypes - .filter(one => (utils_1.isMentionPartType(one) - && one.renderSuggestions != null - && !one.isBottomMentionSuggestionsRender)) - .map(renderMentionSuggestions), - react_1.default.createElement(react_native_1.TextInput, Object.assign({ multiline: true }, textInputProps, { ref: handleTextInputRef, onChangeText: onChangeInput, onSelectionChange: handleSelectionChange }), - react_1.default.createElement(react_native_1.Text, null, parts.map(({ text, partType, data }, index) => { - var _a, _b; - return partType ? (react_1.default.createElement(react_native_1.Text, { key: `${index}-${(_a = data === null || data === void 0 ? void 0 : data.trigger) !== null && _a !== void 0 ? _a : 'pattern'}`, style: (_b = partType.textStyle) !== null && _b !== void 0 ? _b : utils_1.defaultMentionTextStyle }, text)) : (react_1.default.createElement(react_native_1.Text, { key: index }, text)); - }))), - partTypes - .filter(one => (utils_1.isMentionPartType(one) - && one.renderSuggestions != null - && one.isBottomMentionSuggestionsRender)) - .map(renderMentionSuggestions))); -}; -exports.MentionInput = MentionInput; -//# sourceMappingURL=mention-input.js.map \ No newline at end of file diff --git a/dist/components/mention-input.js.map b/dist/components/mention-input.js.map deleted file mode 100644 index 97d188d..0000000 --- a/dist/components/mention-input.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"mention-input.js","sourceRoot":"","sources":["../../src/components/mention-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA+E;AAC/E,+CAMsB;AAGtB,oCAOkB;AAClB,MAAM,SAAS,GAAG,CAAoB,GAAQ,EAAE,GAAM,EAAE,CAAS,EAAE,EAAE;IACnE,IAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QACX,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACf;SAAM;QACL,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;KACd;AACH,CAAC,CAAA;AAED,MAAM,YAAY,GAA0B,CAC1C,EAaqB,EACrB,EAAE;QAdF,EACE,KAAK,EACL,QAAQ,EAER,SAAS,GAAG,EAAE,EAEd,QAAQ,EAAE,YAAY,EAEtB,cAAc,EACd,gBAAgB,GAAG,EAAE,EACrB,iBAAiB,EACjB,iBAAiB,OAEE,EADhB,cAAc,cAZnB,8HAaC,CADkB;IAGnB,MAAM,SAAS,GAAG,cAAM,CAAmB,IAAI,CAAC,CAAC;IAEjD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,gBAAQ,CAAC,EAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC,CAAC;IAC/D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,gBAAQ,CAAC,gBAAgB,CAAC,CAAC;IAE7D,MAAM,EACJ,SAAS,EACT,KAAK,GACN,GAAG,eAAO,CAAC,GAAG,EAAE,CAAC,kBAAU,CAAC,KAAK,EAAE,SAAS,CAAC,E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GAAG,CAAC;eACnB,GAAG,CAAC,iBAAiB,IAAI,IAAI;eAC7B,GAAG,CAAC,gCAAgC,CACxC,CAAuB;aACvB,GAAG,CAAC,wBAAwB,CAAC,CAE3B,CACR,CAAC;AACJ,CAAC,CAAC;AAEO,oCAAY"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index d9a1101..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './components'; -export type { Suggestion, Part, MentionSuggestionsProps, PartType, } from './types'; -export { mentionRegEx, isMentionPartType, getMentionValue, parseValue, replaceMentionValues, } from './utils'; diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9ece04b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.replaceMentionValues = exports.parseValue = exports.getMentionValue = exports.isMentionPartType = exports.mentionRegEx = void 0; -__exportStar(require("./components"), exports); -var utils_1 = require("./utils"); -Object.defineProperty(exports, "mentionRegEx", { enumerable: true, get: function () { return utils_1.mentionRegEx; } }); -Object.defineProperty(exports, "isMentionPartType", { enumerable: true, get: function () { return utils_1.isMentionPartType; } }); -Object.defineProperty(exports, "getMentionValue", { enumerable: true, get: function () { return utils_1.getMentionValue; } }); -Object.defineProperty(exports, "parseValue", { enumerable: true, get: function () { return utils_1.parseValue; } }); -Object.defineProperty(exports, "replaceMentionValues", { enumerable: true, get: function () { return utils_1.replaceMentionValues; } }); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 681fe4b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAA6B;AAM7B,iCAEiB;AADf,qGAAA,YAAY,OAAA;AAAE,0GAAA,iBAAiB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAAE,mGAAA,UAAU,OAAA;AAAE,6GAAA,oBAAoB,OAAA"} \ No newline at end of file diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts deleted file mode 100644 index fcb073f..0000000 --- a/dist/types/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types'; diff --git a/dist/types/index.js b/dist/types/index.js deleted file mode 100644 index 66b0c96..0000000 --- a/dist/types/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./types"), exports); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/types/index.js.map b/dist/types/index.js.map deleted file mode 100644 index 881fa19..0000000 --- a/dist/types/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB"} \ No newline at end of file diff --git a/dist/types/types.d.ts b/dist/types/types.d.ts deleted file mode 100644 index e3da739..0000000 --- a/dist/types/types.d.ts +++ /dev/null @@ -1,69 +0,0 @@ -import type { Change } from 'diff'; -import type { ReactNode, Ref } from 'react'; -import type { StyleProp, TextInput, TextInputProps, TextStyle, ViewStyle } from 'react-native'; -declare type Suggestion = { - id: string; - name: string; -}; -declare type MentionData = { - original: string; - trigger: string; - name: string; - id: string; -}; -declare type PartData = { - name: string; - id: string; - cant: number; - data: any; -}; -declare type CharactersDiffChange = Omit & { - count: number; -}; -declare type RegexMatchResult = string[] & { - 0: string; - 1: string; - 2: string; - 3: string; - 4: string; - index: number; - groups: MentionData; -}; -declare type Position = { - start: number; - end: number; -}; -declare type MentionSuggestionsProps = { - keyword: string | undefined; - onSuggestionPress: (suggestion: Suggestion) => void; -}; -declare type MentionPartType = { - trigger: string; - renderSuggestions?: (props: MentionSuggestionsProps) => ReactNode; - allowedSpacesCount?: number; - isInsertSpaceAfterMention?: boolean; - isBottomMentionSuggestionsRender?: boolean; - textStyle?: StyleProp; - getPlainString?: (mention: MentionData) => string; -}; -declare type PatternPartType = { - pattern: RegExp; - textStyle?: StyleProp; -}; -declare type PartType = MentionPartType | PatternPartType; -declare type Part = { - text: string; - position: Position; - partType?: PartType; - data?: MentionData; -}; -declare type MentionInputProps = Omit & { - value: string; - onChange: (value: string) => void; - onChangePartsData: (partsData: PartData[]) => void; - defaultPartsData: PartData[]; - partTypes?: PartType[]; - inputRef?: Ref; - containerStyle?: StyleProp; -}; -export type { Suggestion, MentionData, CharactersDiffChange, RegexMatchResult, Position, Part, MentionSuggestionsProps, MentionPartType, PatternPartType, PartType, MentionInputProps, PartData }; diff --git a/dist/types/types.js b/dist/types/types.js deleted file mode 100644 index 11e638d..0000000 --- a/dist/types/types.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/types/types.js.map b/dist/types/types.js.map deleted file mode 100644 index 67c6c9d..0000000 --- a/dist/types/types.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/utils/index.d.ts b/dist/utils/index.d.ts deleted file mode 100644 index 04bca77..0000000 --- a/dist/utils/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils'; diff --git a/dist/utils/index.js b/dist/utils/index.js deleted file mode 100644 index e6f0868..0000000 --- a/dist/utils/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./utils"), exports); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/utils/index.js.map b/dist/utils/index.js.map deleted file mode 100644 index b6566c7..0000000 --- a/dist/utils/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB"} \ No newline at end of file diff --git a/dist/utils/utils.d.ts b/dist/utils/utils.d.ts deleted file mode 100644 index f1880b6..0000000 --- a/dist/utils/utils.d.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { StyleProp, TextStyle } from 'react-native'; -import { MentionData, MentionPartType, Part, PartType, Position, Suggestion } from '../types'; -/** - * RegEx grouped results. Example - "@[Full Name](123abc)" - * We have 4 groups here: - * - The whole original string - "@[Full Name](123abc)" - * - Mention trigger - "@" - * - Name - "Full Name" - * - Id - "123abc" - */ -declare const mentionRegEx: RegExp; -declare const defaultMentionTextStyle: StyleProp; -declare const isMentionPartType: (partType: PartType) => partType is MentionPartType; -/** - * Function for getting object with keyword for each mention part type - * - * If keyword is undefined then we don't tracking mention typing and shouldn't show suggestions. - * If keyword is not undefined (even empty string '') then we are tracking mention typing. - * - * Examples where @name is just plain text yet, not mention: - * '|abc @name dfg' - keyword is undefined - * 'abc @| dfg' - keyword is '' - * 'abc @name| dfg' - keyword is 'name' - * 'abc @na|me dfg' - keyword is 'na' - * 'abc @|name dfg' - keyword is against '' - * 'abc @name |dfg' - keyword is 'name ' - * 'abc @name dfg|' - keyword is 'name dfg' - * 'abc @name dfg |' - keyword is undefined (we have more than one space) - * 'abc @name dfg he|' - keyword is undefined (we have more than one space) - */ -declare const getMentionPartSuggestionKeywords: (parts: Part[], plainText: string, selection: Position, partTypes: PartType[]) => { - [trigger: string]: string | undefined; -}; -/** - * Generates new value when we changing text. - * - * @param parts full parts list - * @param originalText original plain text - * @param changedText changed plain text - */ -declare const generateValueFromPartsAndChangedText: (parts: Part[], originalText: string, changedText: string) => string; -/** - * Method for adding suggestion to the parts and generating value. We should: - * - Find part with plain text where we were tracking mention typing using selection state - * - Split the part to next parts: - * -* Before new mention - * -* With new mention - * -* After mention with space at the beginning - * - Generate new parts array and convert it to value - * - * @param parts - full part list - * @param mentionType - actually the mention type - * @param plainText - current plain text - * @param selection - current selection - * @param suggestion - suggestion that should be added - */ -declare const generateValueWithAddedSuggestion: (parts: Part[], mentionType: MentionPartType, plainText: string, selection: Position, suggestion: Suggestion) => string | undefined; -/** - * Method for generating part for plain text - * - * @param text - plain text that will be added to the part - * @param positionOffset - position offset from the very beginning of text - */ -declare const generatePlainTextPart: (text: string, positionOffset?: number) => Part; -/** - * Method for generating part for mention - * - * @param mentionPartType - * @param mention - mention data - * @param positionOffset - position offset from the very beginning of text - */ -declare const generateMentionPart: (mentionPartType: MentionPartType, mention: MentionData, positionOffset?: number) => Part; -/** - * Method for generation mention value that accepts mention regex - * - * @param trigger - * @param suggestion - */ -declare const getMentionValue: (trigger: string, suggestion: Suggestion) => string; -/** - * Recursive function for deep parse MentionInput's value and get plainText with parts - * - * @param value - the MentionInput's value - * @param partTypes - All provided part types - * @param positionOffset - offset from the very beginning of plain text - */ -declare const parseValue: (value: string, partTypes: PartType[], positionOffset?: number) => { - plainText: string; - parts: Part[]; -}; -/** - * Function for generation value from parts array - * - * @param parts - */ -declare const getValueFromParts: (parts: Part[]) => string; -/** - * Replace all mention values in value to some specified format - * - * @param value - value that is generated by MentionInput component - * @param replacer - function that takes mention object as parameter and returns string - */ -declare const replaceMentionValues: (value: string, replacer: (mention: MentionData) => string) => string; -export { mentionRegEx, defaultMentionTextStyle, isMentionPartType, getMentionPartSuggestionKeywords, generateValueFromPartsAndChangedText, generateValueWithAddedSuggestion, generatePlainTextPart, generateMentionPart, getMentionValue, parseValue, getValueFromParts, replaceMentionValues, }; diff --git a/dist/utils/utils.js b/dist/utils/utils.js deleted file mode 100644 index 56c9eba..0000000 --- a/dist/utils/utils.js +++ /dev/null @@ -1,389 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.replaceMentionValues = exports.getValueFromParts = exports.parseValue = exports.getMentionValue = exports.generateMentionPart = exports.generatePlainTextPart = exports.generateValueWithAddedSuggestion = exports.generateValueFromPartsAndChangedText = exports.getMentionPartSuggestionKeywords = exports.isMentionPartType = exports.defaultMentionTextStyle = exports.mentionRegEx = void 0; -const diff_1 = require("diff"); -// @ts-ignore the lib do not have TS declarations yet -const string_prototype_matchall_1 = __importDefault(require("string.prototype.matchall")); -/** - * RegEx grouped results. Example - "@[Full Name](123abc)" - * We have 4 groups here: - * - The whole original string - "@[Full Name](123abc)" - * - Mention trigger - "@" - * - Name - "Full Name" - * - Id - "123abc" - */ -const mentionRegEx = /((.)\[([^[]*)]\(([^(^)]*)\))/gi; -exports.mentionRegEx = mentionRegEx; -const defaultMentionTextStyle = { fontWeight: 'bold', color: 'blue' }; -exports.defaultMentionTextStyle = defaultMentionTextStyle; -const defaultPlainStringGenerator = ({ trigger }, { name }) => `${trigger}${name}`; -const isMentionPartType = (partType) => { - return partType.trigger != null; -}; -exports.isMentionPartType = isMentionPartType; -const getPartIndexByCursor = (parts, cursor, isIncludeEnd) => { - return parts.findIndex(one => cursor >= one.position.start && isIncludeEnd ? cursor <= one.position.end : cursor < one.position.end); -}; -/** - * The method for getting parts between two cursor positions. - * ``` - * | part1 | part2 | part3 | - * a b c|d e f g h i j h k|l m n o - * ``` - * We will get 3 parts here: - * 1. Part included 'd' - * 2. Part included 'efghij' - * 3. Part included 'hk' - * Cursor will move to position after 'k' - * - * @param parts full part list - * @param cursor current cursor position - * @param count count of characters that didn't change - */ -const getPartsInterval = (parts, cursor, count) => { - const newCursor = cursor + count; - const currentPartIndex = getPartIndexByCursor(parts, cursor); - const currentPart = parts[currentPartIndex]; - const newPartIndex = getPartIndexByCursor(parts, newCursor, true); - const newPart = parts[newPartIndex]; - let partsInterval = []; - if (!currentPart || !newPart) { - return partsInterval; - } - // Push whole first affected part or sub-part of the first affected part - if (currentPart.position.start === cursor && currentPart.position.end <= newCursor) { - partsInterval.push(currentPart); - } - else { - partsInterval.push(generatePlainTextPart(currentPart.text.substr(cursor - currentPart.position.start, count))); - } - if (newPartIndex > currentPartIndex) { - // Concat fully included parts - partsInterval = partsInterval.concat(parts.slice(currentPartIndex + 1, newPartIndex)); - // Push whole last affected part or sub-part of the last affected part - if (newPart.position.end === newCursor && newPart.position.start >= cursor) { - partsInterval.push(newPart); - } - else { - partsInterval.push(generatePlainTextPart(newPart.text.substr(0, newCursor - newPart.position.start))); - } - } - return partsInterval; -}; -/** - * Function for getting object with keyword for each mention part type - * - * If keyword is undefined then we don't tracking mention typing and shouldn't show suggestions. - * If keyword is not undefined (even empty string '') then we are tracking mention typing. - * - * Examples where @name is just plain text yet, not mention: - * '|abc @name dfg' - keyword is undefined - * 'abc @| dfg' - keyword is '' - * 'abc @name| dfg' - keyword is 'name' - * 'abc @na|me dfg' - keyword is 'na' - * 'abc @|name dfg' - keyword is against '' - * 'abc @name |dfg' - keyword is 'name ' - * 'abc @name dfg|' - keyword is 'name dfg' - * 'abc @name dfg |' - keyword is undefined (we have more than one space) - * 'abc @name dfg he|' - keyword is undefined (we have more than one space) - */ -const getMentionPartSuggestionKeywords = (parts, plainText, selection, partTypes) => { - const keywordByTrigger = {}; - partTypes.filter(isMentionPartType).forEach(({ trigger, allowedSpacesCount = 1, }) => { - keywordByTrigger[trigger] = undefined; - // Check if we don't have selection range - if (selection.end != selection.start) { - return; - } - // Find the part with the cursor - const part = parts.find(one => selection.end > one.position.start && selection.end <= one.position.end); - // Check if the cursor is not in mention type part - if (part == null || part.data != null) { - return; - } - const triggerIndex = plainText.lastIndexOf(trigger, selection.end); - // Return undefined in case when: - if ( - // - the trigger index is not event found - triggerIndex == -1 - // - the trigger index is out of found part with selection cursor - || triggerIndex < part.position.start - // - the trigger is not at the beginning and we don't have space or new line before trigger - || (triggerIndex > 0 && !/[\s\n]/gi.test(plainText[triggerIndex - 1]))) { - return; - } - // Looking for break lines and spaces between the current cursor and trigger - let spacesCount = 0; - for (let cursor = selection.end - 1; cursor >= triggerIndex; cursor -= 1) { - // Mention cannot have new line - if (plainText[cursor] === '\n') { - return; - } - // Incrementing space counter if the next symbol is space - if (plainText[cursor] === ' ') { - spacesCount += 1; - // Check maximum allowed spaces in trigger word - if (spacesCount > allowedSpacesCount) { - return; - } - } - } - keywordByTrigger[trigger] = plainText.substring(triggerIndex + 1, selection.end); - }); - return keywordByTrigger; -}; -exports.getMentionPartSuggestionKeywords = getMentionPartSuggestionKeywords; -/** - * Generates new value when we changing text. - * - * @param parts full parts list - * @param originalText original plain text - * @param changedText changed plain text - */ -const generateValueFromPartsAndChangedText = (parts, originalText, changedText) => { - const changes = diff_1.diffChars(originalText, changedText); - let newParts = []; - let cursor = 0; - changes.forEach(change => { - switch (true) { - /** - * We should: - * - Move cursor forward on the changed text length - */ - case change.removed: { - cursor += change.count; - break; - } - /** - * We should: - * - Push new part to the parts with that new text - */ - case change.added: { - newParts.push(generatePlainTextPart(change.value)); - break; - } - /** - * We should concat parts that didn't change. - * - In case when we have only one affected part we should push only that one sub-part - * - In case we have two affected parts we should push first - */ - default: { - if (change.count !== 0) { - newParts = newParts.concat(getPartsInterval(parts, cursor, change.count)); - cursor += change.count; - } - break; - } - } - }); - return getValueFromParts(newParts); -}; -exports.generateValueFromPartsAndChangedText = generateValueFromPartsAndChangedText; -/** - * Method for adding suggestion to the parts and generating value. We should: - * - Find part with plain text where we were tracking mention typing using selection state - * - Split the part to next parts: - * -* Before new mention - * -* With new mention - * -* After mention with space at the beginning - * - Generate new parts array and convert it to value - * - * @param parts - full part list - * @param mentionType - actually the mention type - * @param plainText - current plain text - * @param selection - current selection - * @param suggestion - suggestion that should be added - */ -const generateValueWithAddedSuggestion = (parts, mentionType, plainText, selection, suggestion) => { - var _a; - const currentPartIndex = parts.findIndex(one => selection.end >= one.position.start && selection.end <= one.position.end); - const currentPart = parts[currentPartIndex]; - if (!currentPart) { - return; - } - const triggerPartIndex = currentPart.text.lastIndexOf(mentionType.trigger, selection.end - currentPart.position.start); - const newMentionPartPosition = { - start: triggerPartIndex, - end: selection.end - currentPart.position.start, - }; - const isInsertSpaceToNextPart = mentionType.isInsertSpaceAfterMention - // Cursor is at the very end of parts or text row - && (plainText.length === selection.end || ((_a = parts[currentPartIndex]) === null || _a === void 0 ? void 0 : _a.text.startsWith('\n', newMentionPartPosition.end))); - return getValueFromParts([ - ...parts.slice(0, currentPartIndex), - // Create part with string before mention - generatePlainTextPart(currentPart.text.substring(0, newMentionPartPosition.start)), - generateMentionPart(mentionType, Object.assign({ original: getMentionValue(mentionType.trigger, suggestion), trigger: mentionType.trigger }, suggestion)), - // Create part with rest of string after mention and add a space if needed - generatePlainTextPart(`${isInsertSpaceToNextPart ? ' ' : ''}${currentPart.text.substring(newMentionPartPosition.end)}`), - ...parts.slice(currentPartIndex + 1), - ]); -}; -exports.generateValueWithAddedSuggestion = generateValueWithAddedSuggestion; -/** - * Method for generating part for plain text - * - * @param text - plain text that will be added to the part - * @param positionOffset - position offset from the very beginning of text - */ -const generatePlainTextPart = (text, positionOffset = 0) => ({ - text, - position: { - start: positionOffset, - end: positionOffset + text.length, - }, -}); -exports.generatePlainTextPart = generatePlainTextPart; -/** - * Method for generating part for mention - * - * @param mentionPartType - * @param mention - mention data - * @param positionOffset - position offset from the very beginning of text - */ -const generateMentionPart = (mentionPartType, mention, positionOffset = 0) => { - const text = mentionPartType.getPlainString - ? mentionPartType.getPlainString(mention) - : defaultPlainStringGenerator(mentionPartType, mention); - return { - text, - position: { - start: positionOffset, - end: positionOffset + text.length, - }, - partType: mentionPartType, - data: mention, - }; -}; -exports.generateMentionPart = generateMentionPart; -/** - * Generates part for matched regex result - * - * @param partType - current part type (pattern or mention) - * @param result - matched regex result - * @param positionOffset - position offset from the very beginning of text - */ -const generateRegexResultPart = (partType, result, positionOffset = 0) => ({ - text: result[0], - position: { - start: positionOffset, - end: positionOffset + result[0].length, - }, - partType, -}); -/** - * Method for generation mention value that accepts mention regex - * - * @param trigger - * @param suggestion - */ -const getMentionValue = (trigger, suggestion) => `${trigger}[${suggestion.name}](${suggestion.id})`; -exports.getMentionValue = getMentionValue; -const getMentionDataFromRegExMatchResult = ([, original, trigger, name, id]) => ({ - original, - trigger, - name, - id, -}); -/** - * Recursive function for deep parse MentionInput's value and get plainText with parts - * - * @param value - the MentionInput's value - * @param partTypes - All provided part types - * @param positionOffset - offset from the very beginning of plain text - */ -const parseValue = (value, partTypes, positionOffset = 0) => { - if (value == null) { - value = ''; - } - let plainText = ''; - let parts = []; - // We don't have any part types so adding just plain text part - if (partTypes.length === 0) { - plainText += value; - parts.push(generatePlainTextPart(value, positionOffset)); - } - else { - const [partType, ...restPartTypes] = partTypes; - const regex = isMentionPartType(partType) ? mentionRegEx : partType.pattern; - const matches = Array.from(string_prototype_matchall_1.default(value !== null && value !== void 0 ? value : '', regex)); - // In case when we didn't get any matches continue parsing value with rest part types - if (matches.length === 0) { - return parseValue(value, restPartTypes, positionOffset); - } - // In case when we have some text before matched part parsing the text with rest part types - if (matches[0].index != 0) { - const text = value.substr(0, matches[0].index); - const plainTextAndParts = parseValue(text, restPartTypes, positionOffset); - parts = parts.concat(plainTextAndParts.parts); - plainText += plainTextAndParts.plainText; - } - // Iterating over all found pattern matches - for (let i = 0; i < matches.length; i++) { - const result = matches[i]; - if (isMentionPartType(partType)) { - const mentionData = getMentionDataFromRegExMatchResult(result); - // Matched pattern is a mention and the mention doesn't match current mention type - // We should parse the mention with rest part types - if (mentionData.trigger !== partType.trigger) { - const plainTextAndParts = parseValue(mentionData.original, restPartTypes, positionOffset + plainText.length); - parts = parts.concat(plainTextAndParts.parts); - plainText += plainTextAndParts.plainText; - } - else { - const part = generateMentionPart(partType, mentionData, positionOffset + plainText.length); - parts.push(part); - plainText += part.text; - } - } - else { - const part = generateRegexResultPart(partType, result, positionOffset + plainText.length); - parts.push(part); - plainText += part.text; - } - // Check if the result is not at the end of whole value so we have a text after matched part - // We should parse the text with rest part types - if ((result.index + result[0].length) !== value.length) { - // Check if it is the last result - const isLastResult = i === matches.length - 1; - // So we should to add the last substring of value after matched mention - const text = value.slice(result.index + result[0].length, isLastResult ? undefined : matches[i + 1].index); - const plainTextAndParts = parseValue(text, restPartTypes, positionOffset + plainText.length); - parts = parts.concat(plainTextAndParts.parts); - plainText += plainTextAndParts.plainText; - } - } - } - // Exiting from parseValue - return { - plainText, - parts, - }; -}; -exports.parseValue = parseValue; -/** - * Function for generation value from parts array - * - * @param parts - */ -const getValueFromParts = (parts) => parts - .map(item => (item.data ? item.data.original : item.text)) - .join(''); -exports.getValueFromParts = getValueFromParts; -/** - * Replace all mention values in value to some specified format - * - * @param value - value that is generated by MentionInput component - * @param replacer - function that takes mention object as parameter and returns string - */ -const replaceMentionValues = (value, replacer) => value.replace(mentionRegEx, (fullMatch, original, trigger, name, id) => replacer({ - original, - trigger, - name, - id, -})); -exports.replaceMentionValues = replaceMentionValues; -//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/dist/utils/utils.js.map b/dist/utils/utils.js.map deleted file mode 100644 index 3778172..0000000 --- a/dist/utils/utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAiC;AAEjC,qDAAqD;AACrD,0FAAiD;AAYjD;;;;;;;GAOG;AACH,MAAM,YAAY,GAAG,gCAAgC,CAAC;AA+cpD,oCAAY;AA7cd,MAAM,uBAAuB,GAAyB,EAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAC,CAAC;AA8cxF,0DAAuB;AA5czB,MAAM,2BAA2B,GAAG,CAAC,EAAC,OAAO,EAAkB,EAAE,EAAC,IAAI,EAAc,EAAE,EAAE,CAAC,GAAG,OAAO,GAAG,IAAI,EAAE,CAAC;AAE7G,MAAM,iBAAiB,GAAG,CAAC,QAAkB,EAA+B,EAAE;IAC5E,OAAQ,QAA4B,CAAC,OAAO,IAAI,IAAI,CAAC;AACvD,CAAC,CAAC;AAycA,8CAAiB;AAvcnB,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAE,MAAc,EAAE,YAAsB,EAAE,EAAE;IACrF,OAAO,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,IAAI,YAAY,CAAC,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvI,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,MAAc,EAAE,KAAa,EAAU,EAAE;IAChF,MAAM,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC;IAEjC,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gBAEF,MAAM,iBAAiB,GAAG,UAAU,CAAC,IAAI,EAAE,aAAa,EAAE,cAAc,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;gBAC7F,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;gBAC9C,SAAS,IAAI,iBAAiB,CAAC,SAAS,CAAC;aAC1C;SACF;KACF;IAED,0BAA0B;IAC1B,OAAO;QACL,SAAS;QACT,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AAqCA,gCAAU;AAnCZ;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK;KAC/C,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACzD,IAAI,CAAC,EAAE,CAAC,CAAC;AA6BV,8CAAiB;AA3BnB;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,CAC3B,KAAa,EACb,QAA0C,EAC1C,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC;IACpF,QAAQ;IACR,OAAO;IACP,IAAI;IACJ,EAAE;CACH,CAAC,CAAC,CAAC;AAcF,oDAAoB"} \ No newline at end of file diff --git a/src/types/types.ts b/src/types/types.ts index 33e3a55..8bafa65 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -103,7 +103,7 @@ type MentionInputProps = Omit & { // returns an array with the data passed in the onSuggestionPress method in renderSuggestion. It allows you to overload with data in case you need more than the name and the id onChangePartsData: (partsData: PartData[]) => void; // Default value for partsData, useful when MentionInput is passed a value by the 'value' or 'defaultValue' property that the user has not entered. This property is only used as an initial value. - defaultPartsData: PartData[]; + defaultPartsData: Omit[]; partTypes?: PartType[]; inputRef?: Ref; From c2ef4c26ae0ddaea7f1efca12efc54859bf15528 Mon Sep 17 00:00:00 2001 From: Denifer Santiago Date: Sat, 20 Mar 2021 17:25:33 -0400 Subject: [PATCH 10/10] fixing bug: Property 'cant' is missing in type 'Omit' but required in type 'PartData' --- src/components/mention-input.tsx | 2 +- src/types/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/mention-input.tsx b/src/components/mention-input.tsx index 4777e03..98cf379 100644 --- a/src/components/mention-input.tsx +++ b/src/components/mention-input.tsx @@ -43,7 +43,7 @@ const MentionInput: FC = ( const textInput = useRef(null); const [selection, setSelection] = useState({start: 0, end: 0}); - const [partsData, setPartsData] = useState(defaultPartsData); + const [partsData, setPartsData] = useState(defaultPartsData); const { plainText, diff --git a/src/types/types.ts b/src/types/types.ts index 8bafa65..1ba5599 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -16,7 +16,7 @@ type MentionData = { type PartData = { name: string; id: string; - cant: number; + cant?: number; data: any; };