remove from API delete()/IsDeleted(), and deleted check from prepForXml; not useful in declarative style API

This commit is contained in:
Tom Hunkapiller
2021-05-22 03:19:06 +03:00
parent 37d099b457
commit ff14fcae3a
5 changed files with 7 additions and 75 deletions

View File

@ -62,19 +62,14 @@ describe("External styles factory", () => {
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any; const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any;
expect(importedStyle.root[1]).to.deep.equal({ expect(importedStyle.root[1]).to.deep.equal({
deleted: false,
root: [ root: [
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:ascii": "Arial", "w:ascii": "Arial",
"w:cstheme": "minorHAnsi", "w:cstheme": "minorHAnsi",
@ -87,10 +82,8 @@ describe("External styles factory", () => {
rootKey: "w:rFonts", rootKey: "w:rFonts",
}, },
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:bidi": "ar-SA", "w:bidi": "ar-SA",
"w:eastAsia": "en-US", "w:eastAsia": "en-US",
@ -108,16 +101,12 @@ describe("External styles factory", () => {
rootKey: "w:rPrDefault", rootKey: "w:rPrDefault",
}, },
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:after": "160", "w:after": "160",
"w:line": "259", "w:line": "259",
@ -138,10 +127,8 @@ describe("External styles factory", () => {
rootKey: "w:docDefaults", rootKey: "w:docDefaults",
}); });
expect(importedStyle.root[2]).to.deep.equal({ expect(importedStyle.root[2]).to.deep.equal({
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:defLockedState": "1", "w:defLockedState": "1",
"w:defUIPriority": "99", "w:defUIPriority": "99",
@ -165,10 +152,8 @@ describe("External styles factory", () => {
expect(importedStyle.root.length).to.equal(5); expect(importedStyle.root.length).to.equal(5);
expect(importedStyle.root[3]).to.deep.equal({ expect(importedStyle.root[3]).to.deep.equal({
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:default": "1", "w:default": "1",
"w:styleId": "Normal", "w:styleId": "Normal",
@ -177,10 +162,8 @@ describe("External styles factory", () => {
rootKey: "_attr", rootKey: "_attr",
}, },
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:val": "Normal", "w:val": "Normal",
}, },
@ -190,7 +173,6 @@ describe("External styles factory", () => {
rootKey: "w:name", rootKey: "w:name",
}, },
{ {
deleted: false,
root: [], root: [],
rootKey: "w:qFormat", rootKey: "w:qFormat",
}, },
@ -199,10 +181,8 @@ describe("External styles factory", () => {
}); });
expect(importedStyle.root[4]).to.deep.equal({ expect(importedStyle.root[4]).to.deep.equal({
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:styleId": "Heading1", "w:styleId": "Heading1",
"w:type": "paragraph", "w:type": "paragraph",
@ -210,10 +190,8 @@ describe("External styles factory", () => {
rootKey: "_attr", rootKey: "_attr",
}, },
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:val": "heading 1", "w:val": "heading 1",
}, },
@ -223,10 +201,8 @@ describe("External styles factory", () => {
rootKey: "w:name", rootKey: "w:name",
}, },
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:val": "Normal", "w:val": "Normal",
}, },
@ -236,26 +212,20 @@ describe("External styles factory", () => {
rootKey: "w:basedOn", rootKey: "w:basedOn",
}, },
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: [], root: [],
rootKey: "w:keepNext", rootKey: "w:keepNext",
}, },
{ {
deleted: false,
root: [], root: [],
rootKey: "w:keepLines", rootKey: "w:keepLines",
}, },
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: [ root: [
{ {
deleted: false,
root: { root: {
"w:color": "auto", "w:color": "auto",
"w:space": "1", "w:space": "1",

View File

@ -9,16 +9,10 @@ export interface IContext {
export abstract class BaseXmlComponent { export abstract class BaseXmlComponent {
protected readonly rootKey: string; protected readonly rootKey: string;
// tslint:disable-next-line:readonly-keyword
protected deleted: boolean = false;
constructor(rootKey: string) { constructor(rootKey: string) {
this.rootKey = rootKey; this.rootKey = rootKey;
} }
public abstract prepForXml(context: IContext): IXmlableObject | undefined; public abstract prepForXml(context: IContext): IXmlableObject | undefined;
public get IsDeleted(): boolean {
return this.deleted;
}
} }

View File

@ -20,28 +20,24 @@ const xmlString = `
`; `;
const convertedXmlElement = { const convertedXmlElement = {
deleted: false,
root: [ root: [
{ {
deleted: false,
rootKey: "w:p", rootKey: "w:p",
root: [ root: [
{ deleted: false, rootKey: "_attr", root: { "w:one": "value 1", "w:two": "value 2" } }, { rootKey: "_attr", root: { "w:one": "value 1", "w:two": "value 2" } },
{ deleted: false, rootKey: "w:rPr", root: [{ deleted: false, rootKey: "w:noProof", root: ["some value"] }] }, { rootKey: "w:rPr", root: [{ rootKey: "w:noProof", root: ["some value"] }] },
{ {
deleted: false,
rootKey: "w:r", rootKey: "w:r",
root: [ root: [
{ deleted: false, rootKey: "_attr", root: { active: "true" } }, { rootKey: "_attr", root: { active: "true" } },
{ deleted: false, rootKey: "w:t", root: ["Text 1"] }, { rootKey: "w:t", root: ["Text 1"] },
], ],
}, },
{ {
deleted: false,
rootKey: "w:r", rootKey: "w:r",
root: [ root: [
{ deleted: false, rootKey: "_attr", root: { active: "true" } }, { rootKey: "_attr", root: { active: "true" } },
{ deleted: false, rootKey: "w:t", root: ["Text 2"] }, { rootKey: "w:t", root: ["Text 2"] },
], ],
}, },
], ],

View File

@ -1,8 +1,7 @@
import { expect } from "chai"; import { expect } from "chai";
import { Formatter } from "export/formatter"; import { Formatter } from "export/formatter";
import { EMPTY_OBJECT, XmlComponent } from "./"; import { XmlComponent } from "./";
import { IContext } from "./base";
class TestComponent extends XmlComponent {} class TestComponent extends XmlComponent {}
@ -21,21 +20,4 @@ describe("XmlComponent", () => {
}); });
}); });
}); });
describe("#prepForXml()", () => {
it("should skip deleted elements", () => {
const child = new TestComponent("w:test1");
child.delete();
xmlComponent.addChildElement(child);
// tslint:disable-next-line: no-object-literal-type-assertion
const xml = xmlComponent.prepForXml({} as IContext);
if (!xml) {
return;
}
expect(xml["w:test"]).to.deep.equal(EMPTY_OBJECT);
});
});
}); });

View File

@ -14,12 +14,6 @@ export abstract class XmlComponent extends BaseXmlComponent {
public prepForXml(context: IContext): IXmlableObject | undefined { public prepForXml(context: IContext): IXmlableObject | undefined {
const children = this.root const children = this.root
.filter((c) => {
if (c instanceof BaseXmlComponent) {
return !c.IsDeleted;
}
return c !== undefined;
})
.map((comp) => { .map((comp) => {
if (comp instanceof BaseXmlComponent) { if (comp instanceof BaseXmlComponent) {
return comp.prepForXml(context); return comp.prepForXml(context);
@ -44,10 +38,6 @@ export abstract class XmlComponent extends BaseXmlComponent {
return this; return this;
} }
public delete(): void {
this.deleted = true;
}
} }
export abstract class IgnoreIfEmptyXmlComponent extends XmlComponent { export abstract class IgnoreIfEmptyXmlComponent extends XmlComponent {