:feat: refine paragraph/run properties options
This commit is contained in:
@ -3,48 +3,13 @@ import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run"
|
||||
import { IXmlableObject, XmlComponent } from "file/xml-components";
|
||||
|
||||
import { File } from "../file";
|
||||
import { Alignment, AlignmentType } from "./formatting/alignment";
|
||||
import { Bidirectional } from "./formatting/bidirectional";
|
||||
import { IBorderOptions, ThematicBreak } from "./formatting/border";
|
||||
import { IIndentAttributesProperties, Indent } from "./formatting/indent";
|
||||
import { KeepLines, KeepNext } from "./formatting/keep";
|
||||
import { PageBreak, PageBreakBefore } from "./formatting/page-break";
|
||||
import { ContextualSpacing, ISpacingProperties, Spacing } from "./formatting/spacing";
|
||||
import { HeadingLevel, Style } from "./formatting/style";
|
||||
import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop";
|
||||
import { NumberProperties } from "./formatting/unordered-list";
|
||||
import { Bookmark, HyperlinkRef, OutlineLevel } from "./links";
|
||||
import { ParagraphProperties } from "./properties";
|
||||
import { PageBreak } from "./formatting/page-break";
|
||||
import { Bookmark, HyperlinkRef } from "./links";
|
||||
import { IParagraphPropertiesOptions, ParagraphProperties } from "./properties";
|
||||
import { PictureRun, Run, SequentialIdentifier, SymbolRun, TextRun } from "./run";
|
||||
|
||||
export interface IParagraphOptions {
|
||||
export interface IParagraphOptions extends IParagraphPropertiesOptions {
|
||||
readonly text?: string;
|
||||
readonly border?: IBorderOptions;
|
||||
readonly spacing?: ISpacingProperties;
|
||||
readonly outlineLevel?: number;
|
||||
readonly alignment?: AlignmentType;
|
||||
readonly heading?: HeadingLevel;
|
||||
readonly bidirectional?: boolean;
|
||||
readonly thematicBreak?: boolean;
|
||||
readonly pageBreakBefore?: boolean;
|
||||
readonly contextualSpacing?: boolean;
|
||||
readonly indent?: IIndentAttributesProperties;
|
||||
readonly keepLines?: boolean;
|
||||
readonly keepNext?: boolean;
|
||||
readonly tabStops?: Array<{
|
||||
readonly position: number | TabStopPosition;
|
||||
readonly type: TabStopType;
|
||||
readonly leader?: LeaderType;
|
||||
}>;
|
||||
readonly style?: string;
|
||||
readonly bullet?: {
|
||||
readonly level: number;
|
||||
};
|
||||
readonly numbering?: {
|
||||
readonly reference: string;
|
||||
readonly level: number;
|
||||
readonly custom?: boolean;
|
||||
};
|
||||
readonly children?: Array<
|
||||
TextRun | PictureRun | SymbolRun | Bookmark | PageBreak | SequentialIdentifier | FootnoteReferenceRun | HyperlinkRef
|
||||
>;
|
||||
@ -70,9 +35,7 @@ export class Paragraph extends XmlComponent {
|
||||
return;
|
||||
}
|
||||
|
||||
this.properties = new ParagraphProperties({
|
||||
border: options.border,
|
||||
});
|
||||
this.properties = new ParagraphProperties(options);
|
||||
|
||||
this.root.push(this.properties);
|
||||
|
||||
@ -80,72 +43,6 @@ export class Paragraph extends XmlComponent {
|
||||
this.root.push(new TextRun(options.text));
|
||||
}
|
||||
|
||||
if (options.spacing) {
|
||||
this.properties.push(new Spacing(options.spacing));
|
||||
}
|
||||
|
||||
if (options.outlineLevel !== undefined) {
|
||||
this.properties.push(new OutlineLevel(options.outlineLevel));
|
||||
}
|
||||
|
||||
if (options.alignment) {
|
||||
this.properties.push(new Alignment(options.alignment));
|
||||
}
|
||||
|
||||
if (options.heading) {
|
||||
this.properties.push(new Style(options.heading));
|
||||
}
|
||||
|
||||
if (options.bidirectional) {
|
||||
this.properties.push(new Bidirectional());
|
||||
}
|
||||
|
||||
if (options.thematicBreak) {
|
||||
this.properties.push(new ThematicBreak());
|
||||
}
|
||||
|
||||
if (options.pageBreakBefore) {
|
||||
this.properties.push(new PageBreakBefore());
|
||||
}
|
||||
|
||||
if (options.contextualSpacing) {
|
||||
this.properties.push(new ContextualSpacing(options.contextualSpacing));
|
||||
}
|
||||
|
||||
if (options.indent) {
|
||||
this.properties.push(new Indent(options.indent));
|
||||
}
|
||||
|
||||
if (options.keepLines) {
|
||||
this.properties.push(new KeepLines());
|
||||
}
|
||||
|
||||
if (options.keepNext) {
|
||||
this.properties.push(new KeepNext());
|
||||
}
|
||||
|
||||
if (options.tabStops) {
|
||||
for (const tabStop of options.tabStops) {
|
||||
this.properties.push(new TabStop(tabStop.type, tabStop.position, tabStop.leader));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.style) {
|
||||
this.properties.push(new Style(options.style));
|
||||
}
|
||||
|
||||
if (options.bullet) {
|
||||
this.properties.push(new Style("ListParagraph"));
|
||||
this.properties.push(new NumberProperties(1, options.bullet.level));
|
||||
}
|
||||
|
||||
if (options.numbering) {
|
||||
if (!options.numbering.custom) {
|
||||
this.properties.push(new Style("ListParagraph"));
|
||||
}
|
||||
this.properties.push(new NumberProperties(options.numbering.reference, options.numbering.level));
|
||||
}
|
||||
|
||||
if (options.children) {
|
||||
for (const child of options.children) {
|
||||
if (child instanceof Bookmark) {
|
||||
|
Reference in New Issue
Block a user