Skip to content

Commit 1f65450

Browse files
committed
fix: provide better dev UX
1 parent 2c5bf57 commit 1f65450

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

package.json

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/webscopeio/react-textarea-autocomplete"
88
},
9-
"files": [
10-
"dist",
11-
"types.js",
12-
"style.css"
13-
],
9+
"files": ["dist", "types.js", "style.css"],
1410
"main": "dist/react-textarea-autocomplete.cjs.js",
1511
"module": "dist/react-textarea-autocomplete.es.js",
1612
"unpkg": "dist/react-textarea-autocomplete.umd.min.js",
@@ -20,12 +16,7 @@
2016
"url": "https://github.com/webscopeio/react-textarea-autocomplete/issues"
2117
},
2218
"homepage": "https://github.com/webscopeio/react-textarea-autocomplete",
23-
"keywords": [
24-
"react-component",
25-
"textarea",
26-
"autocomplete",
27-
"react"
28-
],
19+
"keywords": ["react-component", "textarea", "autocomplete", "react"],
2920
"scripts": {
3021
"build": "cp src/types.js types.js && rollup -c",
3122
"dev": "webpack-dev-server --config webpack.config.js",
@@ -41,7 +32,7 @@
4132
"precommit": "lint-staged"
4233
},
4334
"devDependencies": {
44-
"@jukben/emoji-search": "^1.1.2",
35+
"@jukben/emoji-search": "^1.1.5",
4536
"babel-core": "^6.26.0",
4637
"babel-loader": "^7.1.2",
4738
"babel-polyfill": "^6.26.0",
@@ -81,25 +72,16 @@
8172
"textarea-caret": "3.0.2"
8273
},
8374
"lint-staged": {
84-
"src/*.{js,jsx}": [
85-
"eslint src --fix",
86-
"git add"
87-
]
75+
"src/*.{js,jsx}": ["eslint src --fix", "git add"]
8876
},
8977
"jest": {
90-
"snapshotSerializers": [
91-
"enzyme-to-json/serializer"
92-
],
93-
"setupFiles": [
94-
"<rootDir>/setupJest.js"
95-
],
78+
"snapshotSerializers": ["enzyme-to-json/serializer"],
79+
"setupFiles": ["<rootDir>/setupJest.js"],
9680
"moduleNameMapper": {
9781
"\\.(css|scss)$": "<rootDir>/__mocks__/styleMock.js"
9882
}
9983
},
10084
"babel": {
101-
"presets": [
102-
"react-app"
103-
]
85+
"presets": ["react-app"]
10486
}
10587
}

src/Textarea.jsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ const DEFAULT_CARET_POSITION = 'next';
2121

2222
const errorMessage = (message: string) =>
2323
console.error(
24-
`RTA: dataProvider fails: ${
25-
message
26-
} Check the documentation or create issue if you think it's bug. https://github.com/webscopeio/react-textarea-autocomplete/issues`
24+
`RTA: dataProvider fails: ${message}
25+
\n\nCheck the documentation or create issue if you think it's bug. https://github.com/webscopeio/react-textarea-autocomplete/issues`
2726
);
2827
class ReactTextareaAutocomplete extends React.Component<
2928
TextareaProps,
@@ -188,12 +187,22 @@ class ReactTextareaAutocomplete extends React.Component<
188187
typeof item === 'object' &&
189188
(!output || typeof output !== 'function')
190189
) {
191-
throw new Error('Output function is not defined!');
190+
throw new Error(
191+
'Output functor is not defined! If you are using items as object you have to define "output" function. https://github.com/webscopeio/react-textarea-autocomplete#trigger-type'
192+
);
192193
}
193194

194195
if (output) {
195196
const textToReplace = output(item, currentTrigger);
196197

198+
if (!textToReplace || typeof textToReplace === 'number') {
199+
throw new Error(
200+
`Output functor should return string or object in shape {text: string, caretPosition: string | number}.\nGot "${String(
201+
textToReplace
202+
)}"\n\nSee https://github.com/webscopeio/react-textarea-autocomplete#trigger-type for more informations.\n`
203+
);
204+
}
205+
197206
if (typeof textToReplace === 'string') {
198207
return {
199208
text: textToReplace,
@@ -203,21 +212,21 @@ class ReactTextareaAutocomplete extends React.Component<
203212

204213
if (!textToReplace.text) {
205214
throw new Error(
206-
'Outupt "text" is not defined! Object should has shape {text: string, caretPosition: string | number}.'
215+
'Output "text" is not defined! Object should has shape {text: string, caretPosition: string | number}.\n'
207216
);
208217
}
209218

210219
if (!textToReplace.caretPosition) {
211220
throw new Error(
212-
'Outupt "caretPosition" is not defined! Object should has shape {text: string, caretPosition: string | number}.'
221+
'Output "caretPosition" is not defined! Object should has shape {text: string, caretPosition: string | number}.\n'
213222
);
214223
}
215224

216225
return textToReplace;
217226
}
218227

219228
if (typeof item !== 'string') {
220-
throw new Error('Output item should be string.');
229+
throw new Error('Output item should be string\n');
221230
}
222231

223232
return {

0 commit comments

Comments
 (0)