diff --git a/src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx b/src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx index f9277a3ce..e221e3ebc 100644 --- a/src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx +++ b/src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx @@ -20,7 +20,7 @@ import { FindspotService } from 'fragmentarium/application/FindspotService' import { Session } from 'auth/Session' import ColophonEditor from 'fragmentarium/ui/fragment/ColophonEditor' import { Colophon } from 'fragmentarium/domain/Colophon' -import TokenAnnotationTool from './TokenAnnotationTool' +import TabularAnnotationTool from './TabularAnnotationTool' const ContentSection: FunctionComponent = ({ children, @@ -248,9 +248,8 @@ function AnnotationContents(props: TabsProps): JSX.Element { } return (
- diff --git a/src/fragmentarium/ui/fragment/TabularAnnotationTool.tsx b/src/fragmentarium/ui/fragment/TabularAnnotationTool.tsx new file mode 100644 index 000000000..35f920b9d --- /dev/null +++ b/src/fragmentarium/ui/fragment/TabularAnnotationTool.tsx @@ -0,0 +1,124 @@ +import { Fragment } from 'fragmentarium/domain/fragment' +import React, { Component } from 'react' +import { isTextLine } from 'transliteration/domain/type-guards' +// import DisplayToken from 'transliteration/ui/DisplayToken' +import { Token } from 'transliteration/domain/token' +import _ from 'lodash' +import { TextLine } from 'transliteration/domain/text-line' +import { Table } from 'react-bootstrap' +import lineNumberToString from 'transliteration/domain/lineNumberToString' +import './TokenAnnotationTool.sass' +import DisplayToken from 'transliteration/ui/DisplayToken' +import { LineNumber, LineNumberRange } from 'transliteration/domain/line-number' +import { LemmaSearchForm } from '../LemmaSearchForm' +import WordService from 'dictionary/application/WordService' + +type Props = { + fragment: Fragment + wordService: WordService + onSave(fragment: Fragment): void +} + +type AnnotationRow = { + lineNumber: LineNumber | LineNumberRange + lineIndex: number + token: Token + newUniqueLemma: string[] + tokenIndex: number + uniqueId: string +} + +type AnnotationTable = AnnotationRow[] + +export default class TokenAnnotationTool extends Component { + private annotationTable: AnnotationTable + fragment: Fragment + + constructor(props: Props) { + super(props) + this.fragment = props.fragment + this.annotationTable = this.createAnnotationTable() + } + + createAnnotationTable(): AnnotationTable { + const lines = this.props.fragment.text.allLines + + return lines + .map((line, lineIndex) => ({ line, lineIndex })) + .filter((indexedLine) => isTextLine(indexedLine.line)) + .flatMap((indexedLine) => { + const line = indexedLine.line as TextLine + return line.content.map((token, tokenIndex) => ({ + lineNumber: line.lineNumber, + token, + tokenIndex, + uniqueId: _.uniqueId(), + lineIndex: indexedLine.lineIndex, + newUniqueLemma: [], + })) + }) + } + + LemmaEditor({ + row, + wordService, + }: { + row: AnnotationRow + wordService: WordService + }): JSX.Element { + const lemmas = row.token.uniqueLemma || [] + return !row.token.lemmatizable ? ( + <> + ) : ( + () => console.log('something')} + placeholder="Add lemma..." + /> + ) + } + + render(): JSX.Element { + let lastLineNumber = '' + return ( + + + + + + + + + + {this.annotationTable.map((row, index) => { + const lineNumber = lineNumberToString(row.lineNumber) + const displayRow = ( + + + + + + ) + lastLineNumber = lineNumber + return displayRow + })} + +
LineTokenLemma
+ {lineNumber !== lastLineNumber && + `(${lineNumberToString(row.lineNumber)})`} + + + + +
+ ) + } +} diff --git a/src/fragmentarium/ui/fragment/TokenAnnotationTool.sass b/src/fragmentarium/ui/fragment/TokenAnnotationTool.sass index 2907ed8bc..dfe336386 100644 --- a/src/fragmentarium/ui/fragment/TokenAnnotationTool.sass +++ b/src/fragmentarium/ui/fragment/TokenAnnotationTool.sass @@ -1,5 +1,10 @@ .annotation-tool - width: unset + + &__table-annotator + width: unset + tbody + td:last-child + min-width: 10em &__wrapper max-height: 50%