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 { DOCXParagraphItem, HTMLParagraphItem } from "./paragraphItem";
import { DOCXSupplNote, HTMLSupplNote } from "./supplNote";
import { withKey } from "../common";
export interface ArticleProps {
el: std.Article,
indent: number,
}
export const HTMLArticleCSS = /*css*/`
.article {
clear: both;
}
`;
export const HTMLArticle = wrapHTMLComponent("HTMLArticle", ((props: HTMLComponentProps & ArticleProps) => {
const { el, htmlOptions, indent } = props;
const blocks: React.JSX.Element[] = [];
const ArticleCaption = el.children.find(std.isArticleCaption);
const ArticleTitle = el.children.find(std.isArticleTitle);
const Paragraphs = el.children.filter(std.isParagraph);
if (ArticleCaption) {
blocks.push((
)); /* >>>> INDENT >>>> */
}
const bodyBlocks: React.JSX.Element[] = [];
for (const [i, child] of Paragraphs.entries()) {
if (i === 0 && ArticleTitle) {
bodyBlocks.push();
} else {
bodyBlocks.push();
}
}
for (const child of el.children) {
if (
std.isArticleCaption(child)
|| std.isArticleTitle(child)
|| std.isParagraph(child)
) {
continue;
} else if (child.tag === "SupplNote") {
bodyBlocks.push();
}
else { assertNever(child); }
}
if (bodyBlocks.length > 0) {
blocks.push((
{withKey(bodyBlocks)}
));
}
return (
{withKey(blocks)}
);
}));
export const DOCXArticle = wrapDOCXComponent("DOCXArticle", ((props: DOCXComponentProps & ArticleProps) => {
const { el, docxOptions, indent } = props;
const blocks: React.JSX.Element[] = [];
const ArticleCaption = el.children.find(std.isArticleCaption);
const ArticleTitle = el.children.find(std.isArticleTitle);
const Paragraphs = el.children.filter(std.isParagraph);
if (ArticleCaption) {
blocks.push((
)); /* >>>> INDENT >>>> */
}
const bodyBlocks: React.JSX.Element[] = [];
for (const [i, child] of Paragraphs.entries()) {
if (i === 0 && ArticleTitle) {
bodyBlocks.push();
} else {
bodyBlocks.push();
}
}
for (const child of el.children) {
if (
std.isArticleCaption(child)
|| std.isArticleTitle(child)
|| std.isParagraph(child)
) {
continue;
} else if (child.tag === "SupplNote") {
bodyBlocks.push();
}
else { assertNever(child); }
}
if (bodyBlocks.length > 0) {
blocks.push(<>
{withKey(bodyBlocks)}
>);
}
return (<>
{withKey(blocks)}
>);
}));