import { reconstituteTable, TableEmoji, type TableFullProps, TableHeaderDataset, tableIdentifier, TableTitle } from './TableHeader'; import { reconstituteResponseElement, ResponseElement, type ResponseElementProps, responseIdPrefix } from './ResponseElement'; import { useCallback } from 'preact/hooks'; export interface ResponseTypeProps { table: TableFullProps, selectedMappingId: number | null, contents: Omit[], } export interface PartialResponseTypeProps { table?: Partial; selectedMappingId?: number | null; contents?: Omit[]; } export function reconstituteResponseType(element: HTMLLIElement, partial?: PartialResponseTypeProps): ResponseTypeProps { const table = reconstituteTable(element.querySelector('.tableHeader')!, partial?.table) as TableFullProps; let selected: number | null | undefined = partial?.selectedMappingId ?? null, contents: Omit[] | undefined = partial?.contents; if (!contents) { contents = []; for (const child of Array.from(element.querySelector('.responseTypeList')!.children) as HTMLLIElement[]) { const childContents = reconstituteResponseElement(child); if (typeof selected === 'undefined' && childContents.selected) { selected = childContents.result.mappingId; } contents.push(childContents); } if (typeof selected === 'undefined') { selected = null; } } else if (typeof selected === 'undefined') { const active = element.querySelector('.response.active'); selected = active ? parseInt(active.id.substring(responseIdPrefix.length)) : null; } return { table, selectedMappingId: selected, contents }; } export interface ResponseTypeEvents { onSelectResponse?: (tableId: number, mappingId: number) => void } export const responseListIdPrefix = 'responses-'; export function ResponseType({ table, selectedMappingId, contents, onSelectResponse }: ResponseTypeProps & ResponseTypeEvents) { const onSelectChild = useCallback((mappingId: number) => { if (onSelectResponse) { onSelectResponse(table.id, mappingId) } }, [onSelectResponse]); return
  • {' '}

      {contents.map(result => )}
  • ; }