Skip to content

Commit

Permalink
initial prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
fsimonjetz committed Jul 29, 2024
1 parent fafa09d commit 1cb2f88
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +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 FragmentAnnotator from 'fragmentarium/ui/fragment/FragmentAnnotator'

const ContentSection: FunctionComponent = ({
children,
Expand Down Expand Up @@ -47,6 +48,7 @@ type TabName =
| 'references'
| 'archaeology'
| 'colophon'
| 'annotation'

const tabNames: TabName[] = [
'display',
Expand All @@ -55,6 +57,7 @@ const tabNames: TabName[] = [
'references',
'archaeology',
'colophon',
'annotation',
]

function EditorTab({
Expand Down Expand Up @@ -92,6 +95,7 @@ function TabContentsMatcher({
references: () => ReferencesContents(props),
archaeology: () => ArchaeologyContents(props),
colophon: () => ColophonContents(props),
annotation: () => AnnotationContents(props),
}[name]()
}

Expand Down Expand Up @@ -126,9 +130,7 @@ export const EditorTabs: FunctionComponent<TabsProps> = ({
{(session) => (
<Tabs
id={tabsId}
defaultActiveKey={
session.isAllowedToTransliterateFragments() ? 'edition' : 'display'
}
defaultActiveKey={'annotation'}
mountOnEnter={true}
className={
session.isGuestSession() ? 'CuneiformFragment__tabs-hidden' : ''
Expand Down Expand Up @@ -235,3 +237,7 @@ function ColophonContents(props: TabsProps): JSX.Element {

return <ColophonEditor updateColophon={updateColophon} {...props} />
}

function AnnotationContents(props: TabsProps): JSX.Element {
return <FragmentAnnotator fragment={props.fragment} />
}
4 changes: 4 additions & 0 deletions src/fragmentarium/ui/fragment/FragmentAnnotator.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.fragment-annotator__markable-token
flex-grow: 0
padding-left: 0
padding-right: 0
54 changes: 54 additions & 0 deletions src/fragmentarium/ui/fragment/FragmentAnnotator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react'
import { Fragment } from 'fragmentarium/domain/fragment'
import { Col, Container, Row } from 'react-bootstrap'
import { Token } from 'transliteration/domain/token'
import { isShift, isTextLine } from 'transliteration/domain/type-guards'
import './FragmentAnnotator.sass'
import { TextLine } from 'transliteration/domain/text-line'
import { AbstractLine } from 'transliteration/domain/abstract-line'

function isMarkable(token: Token): boolean {
return !isShift(token)
}

function DisplayMarkableRow({ line }: { line: TextLine }): JSX.Element {
return (
<Row>
{line.content.map((token, index) => (
<React.Fragment key={index}>
{index !== 0 && <>&nbsp;</>}
{isMarkable(token) && (
<Col className={'fragment-annotator__markable-token'}>
{token.cleanValue}
</Col>
)}
</React.Fragment>
))}
</Row>
)
}

function DisplayUnmarkableRow({ line }: { line: AbstractLine }): JSX.Element {
return <Row>{`(${line.prefix}A ${line.type})`}</Row>
}

export default function FragmentAnnotator({
fragment,
}: {
fragment: Fragment
}): JSX.Element {
console.log(fragment.text)
return (
<>
{fragment.text.lines.map((line, index) => (
<Container key={index}>
{isTextLine(line) ? (
<DisplayMarkableRow line={line} />
) : (
<DisplayUnmarkableRow line={line} />
)}
</Container>
))}
</>
)
}

0 comments on commit 1cb2f88

Please sign in to comment.