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 { useT } from '@/i18n/useT' import { REFERENCE_TYPES } 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({ reference, index, count, readOnly, onDelete, }: { reference: Reference index: number count: number readOnly: boolean onDelete: () => void }) { 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 = `reference-${reference.id}` return (
  • 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')} />
    edit.run('move', { op: 'move', key, position })} /> {t('editor.action.delete')}
    {edit.fieldError('move') && (

    {edit.fieldError('move')}

    )}
  • ) }