import { RstNode, type RstNodeJson, type RstNodeObject, type RstNodeSource } from '../RstNode.ts' import type { RstNodeRegistrar } from '../../Parser/RstNodeRegistrar.ts' import type { RstNodeType } from '../RstNodeType.ts' // ---------------------------------------------------------------------------- // MARK: Node // ---------------------------------------------------------------------------- export type RstTableRowData = { isHeadRow: boolean } export class RstTableRow extends RstNode { readonly isHeadRow: boolean constructor( registrar: RstNodeRegistrar, source: RstNodeSource, children: ReadonlyArray = [], isHeadRow: boolean, ) { super(registrar, source, children) this.isHeadRow = isHeadRow } override toObject(): RstNodeObject { const root = super.toObject() if (this.isHeadRow) { root.data = { isHeadRow: this.isHeadRow, } } return root } override toJSON(): RstNodeJson { const root = super.toJSON() as RstNodeJson root.data = { isHeadRow: this.isHeadRow, } return root } static reviveRstNodeFromJson(registrar: RstNodeRegistrar, json: RstNodeJson): RstTableRow { const children = json.children.map((childJson) => registrar.reviveRstNodeFromJson(childJson)) return new RstTableRow(registrar, structuredClone(json.source), children, json.data.isHeadRow) } override clone(registrar: RstNodeRegistrar): RstTableRow { const children = this.children.map((child) => child.clone(registrar)) return new RstTableRow(registrar, structuredClone(this.source), children, this.isHeadRow) } override get nodeType(): RstNodeType { return 'TableRow' } override toShortString(): string { return `${super.toShortString()} isHeadRow:${this.isHeadRow}` } }