Documentation and Refactoring (#3028)
* Documentation and Refactoring * Documentation and Refactoring * Fix lint issues * Convert components to Builder style --------- Co-authored-by: Dolan Miu <dmiu@bloomberg.net>
This commit is contained in:
@ -2,19 +2,23 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
type MathAngledBracketsOptions = { readonly children: readonly MathComponent[] };
|
||||
|
||||
export class MathAngledBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
public constructor(options: MathAngledBracketsOptions) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
new MathBracketProperties({
|
||||
beginningCharacter: "〈",
|
||||
endingCharacter: "〉",
|
||||
createMathBracketProperties({
|
||||
characters: {
|
||||
beginningCharacter: "〈",
|
||||
endingCharacter: "〉",
|
||||
},
|
||||
}),
|
||||
);
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathBeginningCharacter } from "./math-beginning-character";
|
||||
import { createMathBeginningCharacter } from "./math-beginning-character";
|
||||
|
||||
describe("MathBeginningCharacter", () => {
|
||||
describe("createMathBeginningCharacter", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathBeginningCharacter with correct root key", () => {
|
||||
const mathBeginningCharacter = new MathBeginningCharacter("[");
|
||||
const mathBeginningCharacter = createMathBeginningCharacter({ character: "[" });
|
||||
|
||||
const tree = new Formatter().format(mathBeginningCharacter);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,14 +1,12 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_begChr-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
class MathBeginningCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> {
|
||||
protected readonly xmlKeys = { character: "m:val" };
|
||||
}
|
||||
type MathBeginningCharacterOptions = { readonly character: string };
|
||||
|
||||
export class MathBeginningCharacter extends XmlComponent {
|
||||
public constructor(character: string) {
|
||||
super("m:begChr");
|
||||
|
||||
this.root.push(new MathBeginningCharacterAttributes({ character }));
|
||||
}
|
||||
}
|
||||
export const createMathBeginningCharacter = ({ character }: MathBeginningCharacterOptions): XmlComponent =>
|
||||
new BuilderElement<MathBeginningCharacterOptions>({
|
||||
name: "m:begChr",
|
||||
attributes: {
|
||||
character: { key: "m:val", value: character },
|
||||
},
|
||||
});
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
describe("MathBracketProperties", () => {
|
||||
describe("createMathBracketProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathBracketProperties with correct root key", () => {
|
||||
const mathBracketProperties = new MathBracketProperties();
|
||||
const mathBracketProperties = createMathBracketProperties({});
|
||||
|
||||
const tree = new Formatter().format(mathBracketProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -16,9 +16,11 @@ describe("MathBracketProperties", () => {
|
||||
});
|
||||
|
||||
it("should create a MathBracketProperties with correct root key and add brackets", () => {
|
||||
const mathBracketProperties = new MathBracketProperties({
|
||||
beginningCharacter: "[",
|
||||
endingCharacter: "]",
|
||||
const mathBracketProperties = createMathBracketProperties({
|
||||
characters: {
|
||||
beginningCharacter: "[",
|
||||
endingCharacter: "]",
|
||||
},
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathBracketProperties);
|
||||
|
@ -1,16 +1,18 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_dPr-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathBeginningCharacter } from "./math-beginning-character";
|
||||
import { MathEndingCharacter } from "./math-ending-char";
|
||||
import { createMathBeginningCharacter } from "./math-beginning-character";
|
||||
import { createMathEndingCharacter } from "./math-ending-char";
|
||||
|
||||
export class MathBracketProperties extends XmlComponent {
|
||||
public constructor(options?: { readonly beginningCharacter: string; readonly endingCharacter: string }) {
|
||||
super("m:dPr");
|
||||
type MathBracketPropertiesOptions = { readonly characters?: { readonly beginningCharacter: string; readonly endingCharacter: string } };
|
||||
|
||||
if (!!options) {
|
||||
this.root.push(new MathBeginningCharacter(options.beginningCharacter));
|
||||
this.root.push(new MathEndingCharacter(options.endingCharacter));
|
||||
}
|
||||
}
|
||||
}
|
||||
export const createMathBracketProperties = ({ characters }: MathBracketPropertiesOptions): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:dPr",
|
||||
children: !!characters
|
||||
? [
|
||||
createMathBeginningCharacter({ character: characters.beginningCharacter }),
|
||||
createMathEndingCharacter({ character: characters.endingCharacter }),
|
||||
]
|
||||
: [],
|
||||
});
|
||||
|
@ -2,19 +2,21 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathCurlyBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
new MathBracketProperties({
|
||||
beginningCharacter: "{",
|
||||
endingCharacter: "}",
|
||||
createMathBracketProperties({
|
||||
characters: {
|
||||
beginningCharacter: "{",
|
||||
endingCharacter: "}",
|
||||
},
|
||||
}),
|
||||
);
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_endChr-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
class MathEndingCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> {
|
||||
protected readonly xmlKeys = { character: "m:val" };
|
||||
}
|
||||
type MathEndingCharacterOptions = { readonly character: string };
|
||||
|
||||
export class MathEndingCharacter extends XmlComponent {
|
||||
public constructor(character: string) {
|
||||
super("m:endChr");
|
||||
|
||||
this.root.push(new MathEndingCharacterAttributes({ character }));
|
||||
}
|
||||
}
|
||||
export const createMathEndingCharacter = ({ character }: MathEndingCharacterOptions): XmlComponent =>
|
||||
new BuilderElement<MathEndingCharacterOptions>({
|
||||
name: "m:endChr",
|
||||
attributes: {
|
||||
character: { key: "m:val", value: character },
|
||||
},
|
||||
});
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathEndingCharacter } from "./math-ending-char";
|
||||
import { createMathEndingCharacter } from "./math-ending-char";
|
||||
|
||||
describe("MathEndingCharacter", () => {
|
||||
describe("createMathEndingCharacter", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathEndingCharacter with correct root key", () => {
|
||||
const mathEndingCharacter = new MathEndingCharacter("]");
|
||||
const mathEndingCharacter = createMathEndingCharacter({ character: "]" });
|
||||
|
||||
const tree = new Formatter().format(mathEndingCharacter);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -2,14 +2,14 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathRoundBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(new MathBracketProperties());
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBracketProperties({}));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,21 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathSquareBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
new MathBracketProperties({
|
||||
beginningCharacter: "[",
|
||||
endingCharacter: "]",
|
||||
createMathBracketProperties({
|
||||
characters: {
|
||||
beginningCharacter: "[",
|
||||
endingCharacter: "]",
|
||||
},
|
||||
}),
|
||||
);
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user