Skip to content

Integrate react-material-workspace-layout, update dependencies #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"name": "react-nlp-annotate",
"version": "0.1.21",
"homepage": "https://workaroundonline.github.io/react-nlp-annotate/",
"dependencies": {},
"version": "0.2.0",
"homepage": "https://waoai.github.io/react-nlp-annotate/",
"dependencies": {
"react-hotkeys": "^2.0.0",
"react-material-workspace-layout": "^0.1.6",
"use-event-callback": "^0.1.0"
},
"scripts": {
"build": "npm run build:babel && cp ./package.json ./dist/package.json",
"build": "rimraf dist && npm run build:babel && cp ./package.json ./dist/package.json",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa! I didn't know that but it's a really quick and good solution! 🤘

"build:babel": "NODE_ENV=production babel ./src --out-dir=./dist",
"release": "npm run build && cd dist && npm publish",
"storybook": "start-storybook -p 9050 -s public",
Expand All @@ -20,16 +24,19 @@
"not ie <= 11",
"not op_mini all"
],
"eslintConfig": {
"extends": "react-app"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@material-ui/core": "^3.9.2",
"@material-ui/icons": "^3.0.2",
"@material-ui/styles": "^3.0.0-alpha.10",
"@storybook/addon-actions": "^4",
"@storybook/addon-links": "^4",
"@storybook/addons": "^4",
"@storybook/react": "^4",
"@material-ui/core": "^4.10.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/styles": "^4.10.0",
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-links": "^5.3.19",
"@storybook/addons": "^5.3.19",
"@storybook/react": "^5.3.19",
"axios": "^0.19.0",
"chroma-js": "^2.0.3",
"downloadjs": "^1.4.7",
Expand All @@ -38,12 +45,13 @@
"js-base64": "^2.5.1",
"lodash": "^4.17.11",
"query-string": "^6.8.1",
"react": "16.8.0-alpha.1",
"react-dom": "16.8.0-alpha.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-monaco-editor": "^0.26.2",
"react-scripts": "2.1.3",
"react-select": "^3.0.8",
"react-syntax-highlighter": "^10.3.0",
"rimraf": "^3.0.2",
"spelling": "^2.0.1"
}
}
53 changes: 47 additions & 6 deletions src/components/Container/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
// @flow

import React from "react"
import React, { useMemo } from "react"
import Box from "@material-ui/core/Box"
import Typography from "@material-ui/core/Typography"
import Workspace from "react-material-workspace-layout/Workspace"

export default ({ children }: any) => (
<div style={{ border: "1px solid #ccc", padding: 10, borderRadius: 4 }}>
{children}
</div>
)
export default ({
children,
onNext,
onPrev,
currentSampleIndex = 0,
numberOfSamples = 1,
titleContent,
onClickHeaderItem
}: any) => {
const headerItems = useMemo(
() =>
[
(currentSampleIndex > 0 || onPrev) && { name: "Prev", onClick: onPrev },
(numberOfSamples > currentSampleIndex + 1 || onNext) && {
name: "Next",
onClick: onNext
},
{ name: "Done" }
].filter(Boolean),
[currentSampleIndex, numberOfSamples]
)
return (
<Workspace
headerLeftSide={
titleContent === undefined ? (
<Box paddingLeft={2} fontWeight="bold">
<Typography>
Sample {currentSampleIndex + 1} / {numberOfSamples}
</Typography>
</Box>
) : (
titleContent
)
}
onClickHeaderItem={onClickHeaderItem}
headerItems={headerItems}
iconSidebarItems={[]}
rightSidebarItems={[]}
>
<Box padding={2}>{children}</Box>
</Workspace>
)
}
16 changes: 16 additions & 0 deletions src/components/Container/index.story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow

import React from "react"
import { storiesOf } from "@storybook/react"
import { action } from "@storybook/addon-actions"
import Container from "./"

storiesOf("Container", module).add("Basic", () => (
<Container
onNext={action("onNext")}
onPrev={action("onPrev")}
onClickHeaderItem={action("onClickHeaderItem")}
>
Some inner content
</Container>
))
168 changes: 84 additions & 84 deletions src/components/Document/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export default function Document({
sequence,
onHighlightedChanged = () => null,
onSequenceChange = () => null,
nothingHighlighted,
nothingHighlighted = false,
colorLabelMap = {}
}: Props) {
const [mouseDown, changeMouseDown] = useState()
const [[firstSelected, lastSelected], changeHighlightedRangeState] = useState(
[null, null]
)
const [
[firstSelected, lastSelected],
changeHighlightedRangeState
] = useState([null, null])
const changeHighlightedRange = ([first, last]) => {
changeHighlightedRangeState([first, last])
const highlightedItems = []
Expand All @@ -51,89 +52,88 @@ export default function Document({
onMouseUp={() => changeMouseDown(false)}
>
{sequence.map((seq, i) => (
<>
<span
onMouseDown={() => {
if (seq.label) return
changeHighlightedRange([i, i])
}}
onMouseMove={() => {
if (seq.label) return
if (mouseDown && i !== lastSelected) {
changeHighlightedRange([
firstSelected === null ? i : firstSelected,
i
])
}
}}
style={
seq.label
? {
display: "inline-flex",
backgroundColor:
seq.color || colorLabelMap[seq.label] || "#333",
color: "#fff",
padding: 4,
margin: 4,
paddingLeft: 10,
paddingRight: 10,
borderRadius: 4,
userSelect: "none"
}
: {
display: "inline-flex",
backgroundColor:
seq.text !== " " && highlightedItems.includes(i)
? "#ccc"
: "inherit",
color: "#333",
marginTop: 4,
marginBottom: 4,
paddingTop: 4,
paddingBottom: 4,
paddingLeft: 2,
paddingRight: 2,
userSelect: "none"
}
<span
key={i}
onMouseDown={() => {
if (seq.label) return
changeHighlightedRange([i, i])
}}
onMouseMove={() => {
if (seq.label) return
if (mouseDown && i !== lastSelected) {
changeHighlightedRange([
firstSelected === null ? i : firstSelected,
i
])
}
key={i}
>
{seq.label ? (
<Tooltip title={seq.label} placement="bottom">
<div>{seq.text}</div>
</Tooltip>
) : (
<div>{seq.text}</div>
)}
{seq.label && (
<div
onClick={() => {
onSequenceChange(
sequence
.flatMap(s => (s !== seq ? s : stringToSequence(s.text)))
.filter(s => s.text.length > 0)
)
}}
style={{
}}
style={
seq.label
? {
display: "inline-flex",
cursor: "pointer",
alignSelf: "center",
fontSize: 11,
width: 18,
height: 18,
alignItems: "center",
justifyContent: "center",
marginLeft: 4,
borderRadius: 9,
backgroundColor:
seq.color || colorLabelMap[seq.label] || "#333",
color: "#fff",
backgroundColor: "rgba(0,0,0,0.2)"
}}
>
<span>{"\u2716"}</span>
</div>
)}
</span>
</>
padding: 4,
margin: 4,
paddingLeft: 10,
paddingRight: 10,
borderRadius: 4,
userSelect: "none"
}
: {
display: "inline-flex",
backgroundColor:
seq.text !== " " && highlightedItems.includes(i)
? "#ccc"
: "inherit",
color: "#333",
marginTop: 4,
marginBottom: 4,
paddingTop: 4,
paddingBottom: 4,
paddingLeft: 2,
paddingRight: 2,
userSelect: "none"
}
}
key={i}
>
{seq.label ? (
<Tooltip title={seq.label} placement="bottom">
<div>{seq.text}</div>
</Tooltip>
) : (
<div>{seq.text}</div>
)}
{seq.label && (
<div
onClick={() => {
onSequenceChange(
sequence
.flatMap(s => (s !== seq ? s : stringToSequence(s.text)))
.filter(s => s.text.length > 0)
)
}}
style={{
display: "inline-flex",
cursor: "pointer",
alignSelf: "center",
fontSize: 11,
width: 18,
height: 18,
alignItems: "center",
justifyContent: "center",
marginLeft: 4,
borderRadius: 9,
color: "#fff",
backgroundColor: "rgba(0,0,0,0.2)"
}}
>
<span>{"\u2716"}</span>
</div>
)}
</span>
))}
</div>
)
Expand Down
3 changes: 3 additions & 0 deletions src/components/DocumentLabeler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export default function DocumentLabeler(props: LabelDocumentProps) {
<div>
<div>
<LabelSelector
hotkeysEnabled={props.hotkeysEnabled}
labels={props.labels}
onSelectLabel={(labelId: string) => {
console.log({ labelId })
if (props.multipleLabels) {
changeSelectedLabels(selectedLabels.concat([labelId]))
props.onChange(selectedLabels.concat([labelId]))
Expand All @@ -38,6 +40,7 @@ export default function DocumentLabeler(props: LabelDocumentProps) {
if (!label) return
return (
<LabelButton
key={labelId}
{...label}
small
deletable
Expand Down
Loading