Skip to content

Commit 8f891f9

Browse files
authored
chore: use father (#11)
* use father * update now * add lint file * fix lint * clean up ignore
1 parent 51c3ec0 commit 8f891f9

File tree

10 files changed

+53
-55
lines changed

10 files changed

+53
-55
lines changed

.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const base = require('@umijs/fabric/dist/eslint');
2+
3+
module.exports = {
4+
...base,
5+
rules: {
6+
...base.rules,
7+
'jsx-a11y/no-autofocus': 0,
8+
},
9+
};

.fatherrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
cjs: 'babel',
3+
esm: { type: 'babel', importLibToEs: true },
4+
preCommit: {
5+
eslint: true,
6+
prettier: true,
7+
},
8+
};

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.storybook
12
*.iml
23
*.log
34
.idea/
@@ -37,5 +38,5 @@ jest.config.js
3738
tsconfig.json
3839
tslint.json
3940
tsconfig.test.json
40-
.eslintrc.js
4141
.prettierignore
42+
.doc/

now.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"src": "package.json",
77
"use": "@now/static-build",
8-
"config": { "distDir": "build" }
8+
"config": { "distDir": ".doc" }
99
}
1010
]
1111
}

package.json

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"files": [
1414
"assets/*.css",
1515
"es",
16+
"dist",
1617
"lib"
1718
],
1819
"homepage": "http://github.com/react-component/mentions",
@@ -24,61 +25,39 @@
2425
"url": "http://github.com/react-component/mentions/issues"
2526
},
2627
"license": "MIT",
27-
"config": {
28-
"port": 8093
29-
},
3028
"scripts": {
31-
"build": "rc-tools run build",
32-
"compile": "rc-tools run compile --babel-runtime",
33-
"gh-pages": "rc-tools run gh-pages",
34-
"start": "rc-tools run storybook",
35-
"pub": "rc-tools run pub --babel-runtime",
36-
"lint": "rc-tools run lint",
37-
"lint:fix": "rc-tools run lint --fix",
38-
"prettier": "rc-tools run prettier",
39-
"test": "rc-tools run test",
40-
"prepublish": "rc-tools run guard",
41-
"init-tslint": "rc-tools run gen-lint-config",
42-
"coverage": "rc-tools run test --coverage",
43-
"pre-commit": "rc-tools run pre-commit",
44-
"storybook": "rc-tools run storybook",
45-
"lint-staged": "lint-staged",
29+
"start": "father doc dev --storybook",
30+
"build": "father doc build --storybook",
31+
"compile": "father build",
32+
"prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish",
33+
"lint": "eslint src/ --ext .tsx,.ts",
34+
"test": "father test",
4635
"now-build": "npm run build"
4736
},
37+
"peerDependencies": {
38+
"react": "*"
39+
},
4840
"devDependencies": {
4941
"@types/classnames": "^2.2.6",
5042
"@types/enzyme": "^3.1.15",
5143
"@types/react": "^16.7.17",
5244
"@types/react-dom": "^16.0.11",
5345
"@types/warning": "^3.0.0",
54-
"enzyme": "^3.8.0",
55-
"enzyme-adapter-react-16": "^1.7.1",
46+
"@umijs/fabric": "^1.1.9",
5647
"enzyme-to-json": "^3.1.4",
57-
"lint-staged": "^8.1.0",
48+
"father": "^2.13.6",
5849
"lodash.debounce": "^4.0.8",
59-
"pre-commit": "1.x",
60-
"querystring": "^0.2.0",
61-
"rc-tools": "^9.5.2",
50+
"np": "^5.0.3",
6251
"react": "^16.0.0",
6352
"react-dom": "^16.0.0",
6453
"typescript": "^3.2.2"
6554
},
6655
"dependencies": {
6756
"@ant-design/create-react-context": "^0.2.4",
68-
"babel-runtime": "^6.23.0",
6957
"classnames": "^2.2.6",
7058
"rc-menu": "^7.4.22",
7159
"rc-trigger": "^2.6.2",
7260
"rc-util": "^4.6.0",
7361
"react-lifecycles-compat": "^3.0.4"
74-
},
75-
"pre-commit": [
76-
"lint-staged"
77-
],
78-
"lint-staged": {
79-
"*.{js,jsx,ts,tsx}": [
80-
"npm run pre-commit",
81-
"git add"
82-
]
8362
}
8463
}

src/DropdownMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DropdownMenu extends React.Component<DropdownMenuProps, {}> {
2929
activeKey={activeOption.value}
3030
onSelect={({ key }: { key: string }) => {
3131
const option = options.find(({ value }) => value === key);
32-
selectOption(option!);
32+
selectOption(option);
3333
}}
3434
onFocus={onFocus}
3535
>
@@ -50,7 +50,7 @@ class DropdownMenu extends React.Component<DropdownMenuProps, {}> {
5050
);
5151
})}
5252

53-
{!options.length && <MenuItem disabled={true}>{notFoundContent}</MenuItem>}
53+
{!options.length && <MenuItem disabled>{notFoundContent}</MenuItem>}
5454
</Menu>
5555
);
5656
};

src/Mentions.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
7777
}
7878

7979
public textarea?: HTMLTextAreaElement;
80+
8081
public measure?: HTMLDivElement;
82+
8183
public focusId: number | undefined = undefined;
8284

8385
constructor(props: MentionsProps) {
@@ -98,7 +100,7 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
98100

99101
// Sync measure div top with textarea for rc-trigger usage
100102
if (measuring) {
101-
this.measure!.scrollTop = this.textarea!.scrollTop;
103+
this.measure.scrollTop = this.textarea.scrollTop;
102104
}
103105
}
104106

@@ -138,7 +140,6 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
138140
event.preventDefault();
139141
} else if (which === KeyCode.ESC) {
140142
this.stopMeasure();
141-
return;
142143
} else if (which === KeyCode.ENTER) {
143144
// Measure hit
144145
const option = this.getOptions()[activeIndex];
@@ -177,8 +178,8 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
177178

178179
if (measureIndex !== -1) {
179180
const measureText = selectionStartText.slice(measureIndex + measurePrefix.length);
180-
const validateMeasure: boolean = validateSearch!(measureText, this.props);
181-
const matchOption: boolean = !!this.getOptions(measureText).length;
181+
const validateMeasure: boolean = validateSearch(measureText, this.props);
182+
const matchOption = !!this.getOptions(measureText).length;
182183

183184
if (validateMeasure) {
184185
if (
@@ -247,13 +248,13 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
247248
measureLocation,
248249
targetText: mentionValue,
249250
prefix: measurePrefix,
250-
selectionStart: this.textarea!.selectionStart,
251-
split: split!,
251+
selectionStart: this.textarea.selectionStart,
252+
split,
252253
});
253254
this.triggerChange(text);
254255
this.stopMeasure(() => {
255256
// We need restore the selection position
256-
setInputSelection(this.textarea!, selectionLocation);
257+
setInputSelection(this.textarea, selectionLocation);
257258
});
258259

259260
if (onSelect) {
@@ -285,7 +286,7 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
285286
if (filterOption === false) {
286287
return true;
287288
}
288-
return filterOption!(targetMeasureText, option);
289+
return filterOption(targetMeasureText, option);
289290
});
290291
return list;
291292
};
@@ -312,11 +313,11 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
312313
}
313314

314315
public focus() {
315-
this.textarea!.focus();
316+
this.textarea.focus();
316317
}
317318

318319
public blur() {
319-
this.textarea!.blur();
320+
this.textarea.blur();
320321
}
321322

322323
public render() {
@@ -377,7 +378,7 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
377378
transitionName={transitionName}
378379
placement={placement}
379380
options={options}
380-
visible={true}
381+
visible
381382
>
382383
<span>{measurePrefix}</span>
383384
</KeywordTrigger>

src/MentionsContext.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ export interface MentionsContextProps {
1212
}
1313

1414
// We will never use default, here only to fix TypeScript warning
15-
const MentionsContext: Context<MentionsContextProps> = createReactContext(
16-
{} as MentionsContextProps,
17-
);
15+
const MentionsContext: Context<MentionsContextProps> = createReactContext(null);
1816

1917
export const MentionsContextProvider = MentionsContext.Provider;
2018
export const MentionsContextConsumer = MentionsContext.Consumer;

src/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { OptionProps } from './Option';
33

44
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
55

6-
type OmitFunc = <T extends object, K extends [...Array<keyof T>]>(
6+
type OmitFunc = <T extends object, K extends [...(keyof T)[]]>(
77
obj: T,
88
...keys: K
99
) => { [K2 in Exclude<keyof T, K[number]>]: T[K2] };
@@ -23,7 +23,7 @@ export const omit: OmitFunc = (obj, ...keys) => {
2323
* Cut input selection into 2 part and return text before selection start
2424
*/
2525
export function getBeforeSelectionText(input: HTMLTextAreaElement) {
26-
const { selectionStart } = input as any;
26+
const { selectionStart } = input;
2727
return input.value.slice(0, selectionStart);
2828
}
2929

tests/shared/input.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ export function simulateInput(wrapper, text = '', keyEvent) {
1212
const textareaInstance = wrapper.find('textarea').instance();
1313
textareaInstance.value = text;
1414
textareaInstance.selectionStart = text.length;
15-
textareaInstance.selectionStart = text.length;
1615

1716
if (!keyEvent) {
1817
wrapper.find('textarea').simulate('change', {
1918
target: { value: text },
2019
});
2120
}
2221

22+
textareaInstance.selectionStart = text.length;
2323
wrapper.find('textarea').simulate('keyUp', myKeyEvent);
24+
2425
wrapper.update();
2526
}
27+
/* eslint-enable */

0 commit comments

Comments
 (0)