remove from API delete()/IsDeleted(), and deleted check from prepForXml; not useful in declarative style API
This commit is contained in:
@ -62,19 +62,14 @@ describe("External styles factory", () => {
|
||||
// tslint:disable-next-line:no-any
|
||||
const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any;
|
||||
expect(importedStyle.root[1]).to.deep.equal({
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:ascii": "Arial",
|
||||
"w:cstheme": "minorHAnsi",
|
||||
@ -87,10 +82,8 @@ describe("External styles factory", () => {
|
||||
rootKey: "w:rFonts",
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:bidi": "ar-SA",
|
||||
"w:eastAsia": "en-US",
|
||||
@ -108,16 +101,12 @@ describe("External styles factory", () => {
|
||||
rootKey: "w:rPrDefault",
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:after": "160",
|
||||
"w:line": "259",
|
||||
@ -138,10 +127,8 @@ describe("External styles factory", () => {
|
||||
rootKey: "w:docDefaults",
|
||||
});
|
||||
expect(importedStyle.root[2]).to.deep.equal({
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:defLockedState": "1",
|
||||
"w:defUIPriority": "99",
|
||||
@ -165,10 +152,8 @@ describe("External styles factory", () => {
|
||||
|
||||
expect(importedStyle.root.length).to.equal(5);
|
||||
expect(importedStyle.root[3]).to.deep.equal({
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:default": "1",
|
||||
"w:styleId": "Normal",
|
||||
@ -177,10 +162,8 @@ describe("External styles factory", () => {
|
||||
rootKey: "_attr",
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:val": "Normal",
|
||||
},
|
||||
@ -190,7 +173,6 @@ describe("External styles factory", () => {
|
||||
rootKey: "w:name",
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
root: [],
|
||||
rootKey: "w:qFormat",
|
||||
},
|
||||
@ -199,10 +181,8 @@ describe("External styles factory", () => {
|
||||
});
|
||||
|
||||
expect(importedStyle.root[4]).to.deep.equal({
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:styleId": "Heading1",
|
||||
"w:type": "paragraph",
|
||||
@ -210,10 +190,8 @@ describe("External styles factory", () => {
|
||||
rootKey: "_attr",
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:val": "heading 1",
|
||||
},
|
||||
@ -223,10 +201,8 @@ describe("External styles factory", () => {
|
||||
rootKey: "w:name",
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:val": "Normal",
|
||||
},
|
||||
@ -236,26 +212,20 @@ describe("External styles factory", () => {
|
||||
rootKey: "w:basedOn",
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: [],
|
||||
rootKey: "w:keepNext",
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
root: [],
|
||||
rootKey: "w:keepLines",
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
root: {
|
||||
"w:color": "auto",
|
||||
"w:space": "1",
|
||||
|
@ -9,16 +9,10 @@ export interface IContext {
|
||||
|
||||
export abstract class BaseXmlComponent {
|
||||
protected readonly rootKey: string;
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
protected deleted: boolean = false;
|
||||
|
||||
constructor(rootKey: string) {
|
||||
this.rootKey = rootKey;
|
||||
}
|
||||
|
||||
public abstract prepForXml(context: IContext): IXmlableObject | undefined;
|
||||
|
||||
public get IsDeleted(): boolean {
|
||||
return this.deleted;
|
||||
}
|
||||
}
|
||||
|
@ -20,28 +20,24 @@ const xmlString = `
|
||||
`;
|
||||
|
||||
const convertedXmlElement = {
|
||||
deleted: false,
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
rootKey: "w:p",
|
||||
root: [
|
||||
{ deleted: false, 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: "_attr", root: { "w:one": "value 1", "w:two": "value 2" } },
|
||||
{ rootKey: "w:rPr", root: [{ rootKey: "w:noProof", root: ["some value"] }] },
|
||||
{
|
||||
deleted: false,
|
||||
rootKey: "w:r",
|
||||
root: [
|
||||
{ deleted: false, rootKey: "_attr", root: { active: "true" } },
|
||||
{ deleted: false, rootKey: "w:t", root: ["Text 1"] },
|
||||
{ rootKey: "_attr", root: { active: "true" } },
|
||||
{ rootKey: "w:t", root: ["Text 1"] },
|
||||
],
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
rootKey: "w:r",
|
||||
root: [
|
||||
{ deleted: false, rootKey: "_attr", root: { active: "true" } },
|
||||
{ deleted: false, rootKey: "w:t", root: ["Text 2"] },
|
||||
{ rootKey: "_attr", root: { active: "true" } },
|
||||
{ rootKey: "w:t", root: ["Text 2"] },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
import { EMPTY_OBJECT, XmlComponent } from "./";
|
||||
import { IContext } from "./base";
|
||||
import { XmlComponent } from "./";
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -14,12 +14,6 @@ export abstract class XmlComponent extends BaseXmlComponent {
|
||||
|
||||
public prepForXml(context: IContext): IXmlableObject | undefined {
|
||||
const children = this.root
|
||||
.filter((c) => {
|
||||
if (c instanceof BaseXmlComponent) {
|
||||
return !c.IsDeleted;
|
||||
}
|
||||
return c !== undefined;
|
||||
})
|
||||
.map((comp) => {
|
||||
if (comp instanceof BaseXmlComponent) {
|
||||
return comp.prepForXml(context);
|
||||
@ -44,10 +38,6 @@ export abstract class XmlComponent extends BaseXmlComponent {
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public delete(): void {
|
||||
this.deleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class IgnoreIfEmptyXmlComponent extends XmlComponent {
|
||||
|
Reference in New Issue
Block a user