import type { Reference, ReferenceType } from '@faunosteo/core-wasm/types' import ActionButton from '@/components/editor/fields/ActionButton' import MoveButtons from '@/components/editor/fields/MoveButtons' import SelectField from '@/components/editor/fields/SelectField' import TextField from '@/components/editor/fields/TextField' import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest' import { isBlank, nullable } from '@/editor/sheetDocument' import { useEditCommand } from '@/editor/useEditCommand' import { usePlural } from '@/editor/plural' import { useT } from '@/i18n/useT' import { REFERENCE_TYPES, type ReferenceHost } from './referenceTypes' const CARD = 'space-y-3 rounded-lg border border-[var(--color-border)] p-3' /** One reference: fields commit one by one, ↑ / ↓ reorder, delete asks the core. */ export default function ReferenceRow({ host, reference, index, count, cited, movable, readOnly, onDelete, }: { /** The place showing the row: its field ids carry it, both can be mounted at once. */ host: ReferenceHost reference: Reference /** Position in the whole bibliography, not in a filtered list. */ index: number count: number /** How many findings cite it. */ cited: number /** ↑ / ↓ only while neither the finding filter nor the search narrows the list. */ movable: boolean readOnly: boolean onDelete: () => void }) { const plural = usePlural() const t = useT() const edit = useEditCommand() const key = { kind: 'reference', id: reference.id } as const const send = (field: string, patch: Partial) => edit.run(field, { op: 'update', key, element: { kind: 'reference', value: { ...reference, ...patch } }, }) const options = REFERENCE_TYPES.map((type) => ({ value: type, label: t(`editor.reference.type.${type}`), })) const prefix = `${host}-reference-${reference.id}` return (
  • {plural('editor.references.cited', cited)}

    send('type', { type: type as ReferenceType })} readOnly={readOnly} error={edit.fieldError('type')} /> isBlank(value) ? edit.reject('citation', 'editor.field.required') : send('citation', { citation: value }) } readOnly={readOnly} multiline error={edit.fieldError('citation')} /> send('url', { url: nullable(value) })} readOnly={readOnly} error={edit.fieldError('url')} /> send('doi', { doi: nullable(value) })} readOnly={readOnly} error={edit.fieldError('doi')} />
    {movable && ( edit.run('move', { op: 'move', key, position }) } /> )} {t('editor.action.delete')}
    {edit.fieldError('move') && (

    {edit.fieldError('move')}

    )}
  • ) }