Skip to content

Commit 393e8a5

Browse files
author
Martin Camacho
committed
Add prettierrc and fix lint
1 parent f4a7976 commit 393e8a5

11 files changed

+36
-68
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# production
1010
/dist
1111
/lib
12+
/example/dist
1213

1314
# misc
1415
.DS_Store

.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false,
4+
"trailingComma": "es5",
5+
"printWidth": 100,
6+
"bracketSpacing": false
7+
}

example/dist/app.js

-23
This file was deleted.

example/dist/app.js.map

-1
This file was deleted.

example/dist/index.html

-9
This file was deleted.

example/src/App.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ const TAG_COLORS = {
1010
PERSON: '#84d2ff',
1111
}
1212

13-
const Card = ({ children }) => (
13+
const Card = ({children}) => (
1414
<div
1515
style={{
1616
boxShadow: '0 2px 4px rgba(0,0,0,.1)',
1717
margin: 6,
1818
maxWidth: 500,
1919
padding: 16,
2020
}}
21-
>{children}</div>
22-
);
21+
>
22+
{children}
23+
</div>
24+
)
2325

2426
class App extends React.Component<any, any> {
2527
state = {
@@ -41,7 +43,7 @@ class App extends React.Component<any, any> {
4143
<h3 style={{marginTop: 0}}>react-text-annotate</h3>
4244
<a href="https://github.com/mcamac/react-text-annotate">Github</a>
4345
<p>A React component for interactively highlighting parts of text.</p>
44-
<div style={{ display: 'flex', marginBottom: 24 }}>
46+
<div style={{display: 'flex', marginBottom: 24}}>
4547
<Card>
4648
<h4>Default</h4>
4749
<select onChange={this.handleTagChange} value={this.state.tag}>
@@ -84,11 +86,13 @@ class App extends React.Component<any, any> {
8486
tag: this.state.tag,
8587
color: TAG_COLORS[this.state.tag],
8688
})}
87-
renderMark={(props) => (
89+
renderMark={props => (
8890
<mark
8991
key={props.key}
90-
onClick={() => props.onClick({ start: props.start, end: props.end })}
91-
>{props.content} [{props.tag}]</mark>
92+
onClick={() => props.onClick({start: props.start, end: props.end})}
93+
>
94+
{props.content} [{props.tag}]
95+
</mark>
9296
)}
9397
/>
9498
</Card>

package-lock.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"fork-ts-checker-webpack-plugin": "^0.4.1",
2525
"gh-pages": "^1.1.0",
2626
"html-webpack-plugin": "^3.2.0",
27-
"prettier": "^1.11.1",
27+
"prettier": "^1.12.1",
2828
"react-hot-loader": "^4.0.1",
2929
"style-loader": "^0.20.3",
3030
"ts-loader": "^4.1.0",

src/Mark.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22

33
export interface MarkProps {
4-
key: string,
4+
key: string
55
content: string
66
start: number
77
end: number
@@ -19,9 +19,7 @@ const Mark: React.SFC<MarkProps> = props => (
1919
>
2020
{props.content}
2121
{props.tag && (
22-
<span style={{fontSize: '0.7em', fontWeight: 500, marginLeft: 6}}>
23-
{props.tag}
24-
</span>
22+
<span style={{fontSize: '0.7em', fontWeight: 500, marginLeft: 6}}>{props.tag}</span>
2523
)}
2624
</mark>
2725
)

src/TokenAnnotator.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface TokenAnnotatorProps {
2525
// TODO: When React 16.3 types are ready, remove casts.
2626
class TokenAnnotator extends React.Component<TokenAnnotatorProps, {}> {
2727
static defaultProps = {
28-
renderMark: (props) => <Mark {...props} />,
28+
renderMark: props => <Mark {...props} />,
2929
}
3030

3131
rootRef: any
@@ -98,12 +98,13 @@ class TokenAnnotator extends React.Component<TokenAnnotatorProps, {}> {
9898
<div style={style} ref={this.rootRef}>
9999
{splits.map(
100100
(split, i) =>
101-
split.mark ? renderMark({
101+
split.mark ? (
102+
renderMark({
102103
key: `${split.start}-${split.end}`,
103104
...split,
104-
onClick: this.handleSplitClick
105+
onClick: this.handleSplitClick,
105106
})
106-
: (
107+
) : (
107108
<Token key={split.i} {...split} />
108109
)
109110
)}

src/utils.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import * as sortBy from 'lodash.sortby'
22

3-
export const splitWithOffsets = (
4-
text,
5-
offsets: {start: number; end: number}[]
6-
) => {
3+
export const splitWithOffsets = (text, offsets: {start: number; end: number}[]) => {
74
let lastEnd = 0
85
const splits = []
96

@@ -34,10 +31,7 @@ export const splitWithOffsets = (
3431
return splits
3532
}
3633

37-
export const splitTokensWithOffsets = (
38-
text,
39-
offsets: {start: number; end: number}[]
40-
) => {
34+
export const splitTokensWithOffsets = (text, offsets: {start: number; end: number}[]) => {
4135
let lastEnd = 0
4236
const splits = []
4337

@@ -70,19 +64,15 @@ export const splitTokensWithOffsets = (
7064
}
7165

7266
export const selectionIsEmpty = (selection: Selection) => {
73-
let position = selection.anchorNode.compareDocumentPosition(
74-
selection.focusNode
75-
)
67+
let position = selection.anchorNode.compareDocumentPosition(selection.focusNode)
7668

7769
return position === 0 && selection.focusOffset === selection.anchorOffset
7870
}
7971

8072
export const selectionIsBackwards = (selection: Selection) => {
8173
if (selectionIsEmpty(selection)) return false
8274

83-
let position = selection.anchorNode.compareDocumentPosition(
84-
selection.focusNode
85-
)
75+
let position = selection.anchorNode.compareDocumentPosition(selection.focusNode)
8676

8777
let backward = false
8878
if (

0 commit comments

Comments
 (0)