-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from IDEA-Research/dev
Release: v0.12.0
- Loading branch information
Showing
18 changed files
with
323 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
deepdataspace/server/static/p__Annotator__index.1fc40bde.async.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
deepdataspace/server/static/p__Annotator__index.8750e2fd.async.js
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...tatic/p__Dataset__index.a1265ad5.async.js → ...tatic/p__Dataset__index.419888be.async.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...p__Lab__FlagTool__index.91ecbc6f.async.js → ...p__Lab__FlagTool__index.c0cac9b9.async.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...oject__Workspace__index.afc69f7b.async.js → ...oject__Workspace__index.2c2baf46.async.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
270 changes: 135 additions & 135 deletions
270
deepdataspace/server/static/umi.d5355c89.js → deepdataspace/server/static/umi.d97b8209.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
deepdataspace/server/static/umi.99ffc894.css → deepdataspace/server/static/umi.e762716e.css
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/components/src/Annotator/components/HighlightText/index.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.dds-annotator-highlight-text .ant-tag { | ||
margin-inline-end: 0px !important; | ||
font-size: 14px; | ||
cursor: pointer; | ||
} |
73 changes: 73 additions & 0 deletions
73
packages/components/src/Annotator/components/HighlightText/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useMemo } from 'react'; | ||
import { escapeRegExp } from 'lodash'; | ||
import { Tag } from 'antd'; | ||
|
||
import './index.less'; | ||
|
||
interface IHighlight { | ||
text: string; | ||
color: string; | ||
} | ||
|
||
interface IProps { | ||
text: string; | ||
highlights: IHighlight[]; | ||
onHoverHighlightWord: (text: string) => void; | ||
onLeaveHighlightWord: () => void; | ||
} | ||
|
||
const HighlightText: React.FC<IProps> = ({ | ||
text, | ||
highlights, | ||
onHoverHighlightWord, | ||
onLeaveHighlightWord, | ||
}) => { | ||
|
||
const segments = useMemo(() => { | ||
const computedSegments: React.ReactNode[] = []; | ||
const pattern = new RegExp( | ||
highlights.map(h => `\\b(${escapeRegExp(h.text)})\\b`).join('|'), | ||
'g' | ||
); | ||
|
||
const matches = Array.from(text.matchAll(pattern)); | ||
let lastIndex = 0; | ||
|
||
matches.forEach(match => { | ||
const matchText = match[0]; | ||
const index = match.index ?? 0; | ||
|
||
if (index > lastIndex) { | ||
computedSegments.push(text.substring(lastIndex, index)); | ||
} | ||
|
||
const highlightConfig = highlights.find(h => h.text === matchText); | ||
|
||
if (highlightConfig) { | ||
computedSegments.push( | ||
<Tag | ||
key={`${index}-${matchText}`} | ||
color={highlightConfig.color} | ||
bordered={false} | ||
onMouseEnter={() => onHoverHighlightWord(matchText)} | ||
onMouseLeave={onLeaveHighlightWord} | ||
> | ||
{matchText} | ||
</Tag> | ||
); | ||
} | ||
|
||
lastIndex = index + matchText.length; | ||
}); | ||
|
||
if (lastIndex < text.length) { | ||
computedSegments.push(text.substring(lastIndex)); | ||
} | ||
|
||
return computedSegments; | ||
}, [text, highlights, onHoverHighlightWord, onLeaveHighlightWord]); | ||
|
||
return <div className={'dds-annotator-highlight-text'}>{segments}</div>; | ||
}; | ||
|
||
export default HighlightText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.