import React from "react"; import * as std from "../../law/std"; import { assertNever } from "../../util"; import type { HTMLComponentProps } from "../common/html"; import { elProps, wrapHTMLComponent } from "../common/html"; import { DOCXSentenceChildrenRun, HTMLSentenceChildrenRun } from "./sentenceChildrenRun"; import type { DOCXComponentProps } from "../common/docx/component"; import { wrapDOCXComponent } from "../common/docx/component"; import { w } from "../common/docx/tags"; import { DOCXArticleGroup, HTMLArticleGroup } from "./articleGroup"; import { sentenceChildrenToString } from "../../parser/cst/rules/$sentenceChildren"; import { DOCXAppdxItem, HTMLAppdxItem } from "./appdxItem"; import { DOCXParagraphItem, HTMLParagraphItem } from "./paragraphItem"; import { DOCXTOC, HTMLTOC } from "./toc"; import EmptyParagraph from "../common/docx/EmptyParagraph"; import { withKey } from "../common"; export interface EnactStatementProps { el: std.EnactStatement, indent: number, } export const HTMLEnactStatementCSS = /*css*/` .enact-statement { clear: both; } `; export const HTMLEnactStatement = wrapHTMLComponent("HTMLEnactStatement", ((props: HTMLComponentProps & EnactStatementProps) => { const { el, htmlOptions, indent } = props; return (
); })); export const DOCXEnactStatement = wrapDOCXComponent("DOCXEnactStatement", ((props: DOCXComponentProps & EnactStatementProps) => { const { el, docxOptions, indent } = props; return ( ); })); export interface PreambleProps { el: std.Preamble, indent: number, } export const HTMLPreambleCSS = /*css*/` .preamble { clear: both; } `; export const HTMLPreamble = wrapHTMLComponent("HTMLPreamble", ((props: HTMLComponentProps & PreambleProps) => { const { el, htmlOptions, indent } = props; const blocks: React.JSX.Element[] = []; for (const child of el.children) { if ( std.isParagraph(child) ) { blocks.push(); } else { assertNever(child); } } return (
{withKey(blocks)}
); })); export const DOCXPreamble = wrapDOCXComponent("DOCXPreamble", ((props: DOCXComponentProps & PreambleProps) => { const { el, docxOptions, indent } = props; const blocks: React.JSX.Element[] = []; for (const child of el.children) { if ( std.isParagraph(child) ) { blocks.push(); } else { assertNever(child); } } return (<> {withKey(blocks)} ); })); export interface LawProps { el: std.Law, indent: number, } export const HTMLLawCSS = /*css*/` .law-title { font-weight: bold; } .law-num { font-weight: bold; } `; export const HTMLLaw = wrapHTMLComponent("HTMLLaw", ((props: HTMLComponentProps & LawProps) => { const { el, htmlOptions, indent } = props; const blocks: React.JSX.Element[] = []; const LawTitle = el.children.find(std.isLawBody)?.children.find(std.isLawTitle); const LawNum = el.children.find(std.isLawNum); if (LawTitle) { blocks.push((
)); } if (LawNum) { const LawNumString = sentenceChildrenToString(LawNum.children); const LawNumChildren = [...LawNum.children]; if (!/^[((]/.test(LawNumString)) LawNumChildren.unshift("("); if (!/[))]$/.test(LawNumString)) LawNumChildren.push(")"); blocks.push((
)); } const bodyBlocks: React.JSX.Element[] = []; for (const child of el.children.find(std.isLawBody)?.children ?? []) { if ( std.isLawTitle(child) ) { continue; } else if (std.isTOC(child)) { if (bodyBlocks.length > 0) bodyBlocks.push(

); bodyBlocks.push(); } else if (std.isMainProvision(child) || std.isSupplProvision(child)) { if (bodyBlocks.length > 0) bodyBlocks.push(

); bodyBlocks.push(); } else if (std.isAppdxItem(child)) { if (bodyBlocks.length > 0) bodyBlocks.push(

); bodyBlocks.push(); } else if (std.isEnactStatement(child)) { if (bodyBlocks.length > 0) bodyBlocks.push(

); bodyBlocks.push(); } else if (std.isPreamble(child)) { if (bodyBlocks.length > 0) bodyBlocks.push(

); bodyBlocks.push(); } else { assertNever(child); } } if (bodyBlocks.length > 0) { if (blocks.length > 0) blocks.push(

); blocks.push((
{withKey(bodyBlocks)}
)); } return (
{withKey(blocks)}
); })); export const DOCXLaw = wrapDOCXComponent("DOCXLaw", ((props: DOCXComponentProps & LawProps) => { const { el, docxOptions, indent } = props; const blocks: React.JSX.Element[] = []; const LawTitle = el.children.find(std.isLawBody)?.children.find(std.isLawTitle); const LawNum = el.children.find(std.isLawNum); if (LawTitle) { blocks.push(( )); } if (LawNum) { const LawNumString = sentenceChildrenToString(LawNum.children); const LawNumChildren = [...LawNum.children]; if (!/^[((]/.test(LawNumString)) LawNumChildren.unshift("("); if (!/[))]$/.test(LawNumString)) LawNumChildren.push(")"); blocks.push(( )); } for (const child of el.children.find(std.isLawBody)?.children ?? []) { if ( std.isLawTitle(child) ) { continue; } else if (std.isTOC(child)) { if (blocks.length > 0) blocks.push(); blocks.push(); } else if (std.isMainProvision(child) || std.isSupplProvision(child)) { if (blocks.length > 0) blocks.push(); blocks.push(); } else if (std.isAppdxItem(child)) { if (blocks.length > 0) blocks.push(); blocks.push(); } else if (std.isEnactStatement(child)) { if (blocks.length > 0) blocks.push(); blocks.push(); } else if (std.isPreamble(child)) { if (blocks.length > 0) blocks.push(); blocks.push(); } else { assertNever(child); } } return (<> {withKey(blocks)} ); }));