From f706d8e62d0068d14aac576e936fceaa93b60601 Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 14:42:17 -0400 Subject: [PATCH 01/13] Modify sdt-properties to accommodate for children elements --- src/file/table-of-contents/sdt-properties.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/file/table-of-contents/sdt-properties.ts b/src/file/table-of-contents/sdt-properties.ts index f1f2c56304..481235752a 100644 --- a/src/file/table-of-contents/sdt-properties.ts +++ b/src/file/table-of-contents/sdt-properties.ts @@ -1,9 +1,25 @@ // http://www.datypic.com/sc/ooxml/e-w_sdtPr-1.html +import { CheckBoxUtil } from "@file/checkbox"; import { StringValueElement, XmlComponent } from "@file/xml-components"; +export type SdtPrChild = + | CheckBoxUtil; + +export interface ISdtPropertiesOptions { + readonly children : readonly SdtPrChild[]; +} export class StructuredDocumentTagProperties extends XmlComponent { - public constructor(alias: string) { + public constructor(alias?: string, options?: ISdtPropertiesOptions) { super("w:sdtPr"); - this.root.push(new StringValueElement("w:alias", alias)); + + if(typeof alias === 'string'){ + this.root.push(new StringValueElement("w:alias", alias)); + } + + if(options?.children){ + for(const child of options.children){ + this.root.push(child) + } + } } } From 79363c2c2cefd0b89a2e3e5d22a96143b873588d Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 14:43:10 -0400 Subject: [PATCH 02/13] Modify Pargraph's children to accept CheckBox --- src/file/paragraph/paragraph.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index a12b88df6a..feafb1450f 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -6,6 +6,7 @@ import { FileChild } from "@file/file-child"; import { TargetModeType } from "../relationships/relationship/relationship"; import { DeletedTextRun, InsertedTextRun } from "../track-revision"; +import { CheckBox } from "../checkbox"; import { ColumnBreak, PageBreak } from "./formatting/break"; import { Bookmark, ConcreteHyperlink, ExternalHyperlink, InternalHyperlink } from "./links"; import { Math } from "./math"; @@ -33,7 +34,8 @@ export type ParagraphChild = | Comment | CommentRangeStart | CommentRangeEnd - | CommentReference; + | CommentReference + | CheckBox; export interface IParagraphOptions extends IParagraphPropertiesOptions { readonly text?: string; From aa8438d8bd1e1ad0cb8b47833ad3f7c31b312d1a Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 14:49:03 -0400 Subject: [PATCH 03/13] Create CheckBox element and supporting child elements --- src/file/checkbox/checkbox-symbol.ts | 29 ++++++++++++++++++ src/file/checkbox/checkbox-util.ts | 44 +++++++++++++++++++++++++++ src/file/checkbox/checkbox.ts | 45 ++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 src/file/checkbox/checkbox-symbol.ts create mode 100644 src/file/checkbox/checkbox-util.ts create mode 100644 src/file/checkbox/checkbox.ts diff --git a/src/file/checkbox/checkbox-symbol.ts b/src/file/checkbox/checkbox-symbol.ts new file mode 100644 index 0000000000..7e172c3141 --- /dev/null +++ b/src/file/checkbox/checkbox-symbol.ts @@ -0,0 +1,29 @@ +// This represents element type CT_SdtCheckboxSymbol element +// +// +// +// + +import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; +import { shortHexNumber } from "@util/values"; + +class CheckboxSymbolAttributes extends XmlAttributeComponent<{ + readonly val?: string | number | boolean; + readonly symbolfont?: string; +}> { + protected readonly xmlKeys = { + val: "w14:val", + symbolfont: "w14:font", + }; +} + +export class CheckBoxSymbolElement extends XmlComponent { + public constructor(name: string, val: string, font?: string) { + super(name); + if (font) { + this.root.push(new CheckboxSymbolAttributes({ val: shortHexNumber(val), symbolfont: font })); + } else { + this.root.push(new CheckboxSymbolAttributes({ val })); + } + } +} diff --git a/src/file/checkbox/checkbox-util.ts b/src/file/checkbox/checkbox-util.ts new file mode 100644 index 0000000000..a3732c282e --- /dev/null +++ b/src/file/checkbox/checkbox-util.ts @@ -0,0 +1,44 @@ +// +// +// +// +// +// +// +// + +import { XmlComponent } from "@file/xml-components"; +import { CheckBoxSymbolElement } from "@file/checkbox/checkbox-symbol"; + +export interface ICheckboxSymbolProperties { + readonly value?: string; + readonly font?: string; +} + +export interface ICheckboxSymbolOptions { + readonly checked?: boolean; + readonly checkedState?: ICheckboxSymbolProperties; + readonly uncheckedState?: ICheckboxSymbolProperties; +} + +export class CheckBoxUtil extends XmlComponent { + private readonly DEFAULT_UNCHECKED_SYMBOL: string = "2610"; + private readonly DEFAULT_CHECKED_SYMBOL: string = "2612"; + private readonly DEFAULT_FONT: string = "MS Gothic"; + public constructor(options?: ICheckboxSymbolOptions) { + super("w14:checkbox"); + + const value = options?.checked ? "1" : "0"; + let symbol: string; + let font: string; + this.root.push(new CheckBoxSymbolElement("w14:checked", value)); + + symbol = options?.checkedState?.value ? options?.checkedState?.value : this.DEFAULT_CHECKED_SYMBOL; + font = options?.checkedState?.font ? options?.checkedState?.font : this.DEFAULT_FONT; + this.root.push(new CheckBoxSymbolElement("w14:checkedState", symbol, font)); + + symbol = options?.uncheckedState?.value ? options?.uncheckedState?.value : this.DEFAULT_UNCHECKED_SYMBOL; + font = options?.uncheckedState?.font ? options?.uncheckedState?.font : this.DEFAULT_FONT; + this.root.push(new CheckBoxSymbolElement("w14:uncheckedState", symbol, font)); + } +} diff --git a/src/file/checkbox/checkbox.ts b/src/file/checkbox/checkbox.ts new file mode 100644 index 0000000000..9f8b55e4f2 --- /dev/null +++ b/src/file/checkbox/checkbox.ts @@ -0,0 +1,45 @@ +import { SymbolRun } from "@file/paragraph/run/symbol-run"; +import { StructuredDocumentTagProperties } from "@file/table-of-contents/sdt-properties"; +import { StructuredDocumentTagContent } from "@file/table-of-contents/sdt-content"; +import { XmlComponent } from "@file/xml-components"; +import { CheckBoxUtil, ICheckboxSymbolOptions } from "./checkbox-util"; + +export class CheckBox extends XmlComponent { + // default values per Microsoft + private readonly DEFAULT_UNCHECKED_SYMBOL: string = "2610"; + private readonly DEFAULT_CHECKED_SYMBOL: string = "2612"; + private readonly DEFAULT_FONT: string = "MS Gothic"; + public constructor(options?: ICheckboxSymbolOptions) { + super("w:sdt"); + + this.root.push( + new StructuredDocumentTagProperties(undefined, { + children: [new CheckBoxUtil(options)], + }), + ); + + const content = new StructuredDocumentTagContent(); + const checkedFont: string | undefined = options?.checkedState?.font; + const checkedText: string | undefined = options?.checkedState?.value; + const uncheckedFont: string | undefined = options?.uncheckedState?.font; + const uncheckedText: string | undefined = options?.uncheckedState?.value; + let symbolFont: string; + let char: string; + + if (options?.checked) { + symbolFont = checkedFont ? checkedFont : this.DEFAULT_FONT; + char = checkedText ? checkedText : this.DEFAULT_CHECKED_SYMBOL; + } else { + symbolFont = uncheckedFont ? uncheckedFont : this.DEFAULT_FONT; + char = uncheckedText ? uncheckedText : this.DEFAULT_UNCHECKED_SYMBOL; + } + + const initialRenderedChar = new SymbolRun({ + char: char, + symbolfont: symbolFont, + }); + + content.addChildElement(initialRenderedChar); + this.root.push(content); + } +} From cad4a5510bf981cd73f1b813933641f1ec8f68e6 Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 14:50:07 -0400 Subject: [PATCH 04/13] Create test files for CheckBox and CheckBoxUtil --- src/file/checkbox/checkbox-util.spec.ts | 85 ++++++++++ src/file/checkbox/checkbox.spec.ts | 204 ++++++++++++++++++++++++ 2 files changed, 289 insertions(+) create mode 100644 src/file/checkbox/checkbox-util.spec.ts create mode 100644 src/file/checkbox/checkbox.spec.ts diff --git a/src/file/checkbox/checkbox-util.spec.ts b/src/file/checkbox/checkbox-util.spec.ts new file mode 100644 index 0000000000..74fc74b820 --- /dev/null +++ b/src/file/checkbox/checkbox-util.spec.ts @@ -0,0 +1,85 @@ +import { describe, expect, it } from "vitest"; +import { Formatter } from "@export/formatter"; +import { CheckBoxUtil } from "."; + +describe("CheckBoxUtil", () => { + describe("#constructor()", () => { + it("should create a CheckBoxUtil with proper root and default values", () => { + const checkBoxUtil = new CheckBoxUtil(); + + const tree = new Formatter().format(checkBoxUtil); + + expect(tree).to.deep.equal({ + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "0", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": "MS Gothic", + "w14:val": "2612", + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "MS Gothic", + "w14:val": "2610", + }, + }, + }, + ], + }); + }); + + it("should create a CheckBoxUtil with proper structure and custom values", () => { + const checkBoxUtil = new CheckBoxUtil({ + checked: true, + checkedState: { + value: "2713", + font: "Segoe UI Symbol", + }, + uncheckedState: { + value: "2705", + font: "Segoe UI Symbol", + }, + }); + + const tree = new Formatter().format(checkBoxUtil); + + expect(tree).to.deep.equal({ + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "1", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2713", + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2705", + }, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/checkbox/checkbox.spec.ts b/src/file/checkbox/checkbox.spec.ts new file mode 100644 index 0000000000..6e00b100a0 --- /dev/null +++ b/src/file/checkbox/checkbox.spec.ts @@ -0,0 +1,204 @@ +import { describe, expect, it } from "vitest"; +import { Formatter } from "@export/formatter"; +import { CheckBox } from "."; + +describe("CheckBox", () => { + describe("#constructor()", () => { + it("should create a CheckBoxUtil with proper root and default values", () => { + const checkBox = new CheckBox(); + + const tree = new Formatter().format(checkBox); + + expect(tree).to.deep.equal({ + "w:sdt": [ + { + "w:sdtPr": [ + { + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "0", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": "MS Gothic", + "w14:val": "2612", + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "MS Gothic", + "w14:val": "2610", + }, + }, + }, + ], + }, + ], + }, + { + "w:sdtContent": [ + { + "w:r": [ + { + "w:sym": { + _attr: { + "w:char": "2610", + "w:font": "MS Gothic", + }, + }, + }, + ], + }, + ], + }, + ], + }); + }); + + it.each([ + ["2713", "Segoe UI Symbol", "2713", "Segoe UI Symbol"], + [undefined, undefined, "2612", "MS Gothic"], + ])("should create a CheckBoxUtil with proper root and custom values", (inputChar, inputFont, actualChar, actualFont) => { + const checkBox = new CheckBox({ + checked: true, + checkedState: { + value: inputChar, + font: inputFont, + }, + uncheckedState: { + value: "2705", + font: "Segoe UI Symbol", + }, + }); + + const tree = new Formatter().format(checkBox); + + expect(tree).to.deep.equal({ + "w:sdt": [ + { + "w:sdtPr": [ + { + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "1", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": actualFont, + "w14:val": actualChar, + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2705", + }, + }, + }, + ], + }, + ], + }, + { + "w:sdtContent": [ + { + "w:r": [ + { + "w:sym": { + _attr: { + "w:char": actualChar, + "w:font": actualFont, + }, + }, + }, + ], + }, + ], + }, + ], + }); + }); + + it("should create a CheckBoxUtil with proper root and custom values", () => { + const checkBox = new CheckBox({ + checked: false, + checkedState: { + value: "2713", + font: "Segoe UI Symbol", + }, + uncheckedState: { + value: "2705", + font: "Segoe UI Symbol", + }, + }); + + const tree = new Formatter().format(checkBox); + + expect(tree).to.deep.equal({ + "w:sdt": [ + { + "w:sdtPr": [ + { + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "0", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2713", + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2705", + }, + }, + }, + ], + }, + ], + }, + { + "w:sdtContent": [ + { + "w:r": [ + { + "w:sym": { + _attr: { + "w:char": "2705", + "w:font": "Segoe UI Symbol", + }, + }, + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); From 337ff464cfee6a3e8de4cb865cdf83919ce1c331 Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 14:51:10 -0400 Subject: [PATCH 05/13] Modify/create index files to handle exporting --- src/file/checkbox/index.ts | 3 +++ src/file/index.ts | 1 + 2 files changed, 4 insertions(+) create mode 100644 src/file/checkbox/index.ts diff --git a/src/file/checkbox/index.ts b/src/file/checkbox/index.ts new file mode 100644 index 0000000000..9af5c31e28 --- /dev/null +++ b/src/file/checkbox/index.ts @@ -0,0 +1,3 @@ +export * from "./checkbox-util"; +export * from "./checkbox-symbol"; +export * from "./checkbox"; diff --git a/src/file/index.ts b/src/file/index.ts index 4bdac87ef9..6cf75e4f24 100644 --- a/src/file/index.ts +++ b/src/file/index.ts @@ -17,3 +17,4 @@ export * from "./track-revision"; export * from "./shared"; export * from "./border"; export * from "./vertical-align"; +export * from "./checkbox"; From d1f75e3a422a6b5109e9894bc5edf2c45a9c112e Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 15:20:56 -0400 Subject: [PATCH 06/13] Revert unnecessary changes to sdt-properties --- src/file/table-of-contents/sdt-properties.ts | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/file/table-of-contents/sdt-properties.ts b/src/file/table-of-contents/sdt-properties.ts index 481235752a..241122593a 100644 --- a/src/file/table-of-contents/sdt-properties.ts +++ b/src/file/table-of-contents/sdt-properties.ts @@ -1,25 +1,10 @@ // http://www.datypic.com/sc/ooxml/e-w_sdtPr-1.html -import { CheckBoxUtil } from "@file/checkbox"; import { StringValueElement, XmlComponent } from "@file/xml-components"; -export type SdtPrChild = - | CheckBoxUtil; - -export interface ISdtPropertiesOptions { - readonly children : readonly SdtPrChild[]; -} export class StructuredDocumentTagProperties extends XmlComponent { - public constructor(alias?: string, options?: ISdtPropertiesOptions) { + public constructor(alias: string) { super("w:sdtPr"); - if(typeof alias === 'string'){ - this.root.push(new StringValueElement("w:alias", alias)); - } - - if(options?.children){ - for(const child of options.children){ - this.root.push(child) - } - } + this.root.push(new StringValueElement("w:alias", alias)); } } From b8f83fd6addd0a51c8e900dc7ff9bb957ebc3816 Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 15:21:45 -0400 Subject: [PATCH 07/13] Update CheckBox element and test file according to sdt-properties correction --- src/file/checkbox/checkbox.spec.ts | 21 +++++++++++++++++++++ src/file/checkbox/checkbox.ts | 8 +++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/file/checkbox/checkbox.spec.ts b/src/file/checkbox/checkbox.spec.ts index 6e00b100a0..98e96e582b 100644 --- a/src/file/checkbox/checkbox.spec.ts +++ b/src/file/checkbox/checkbox.spec.ts @@ -13,6 +13,13 @@ describe("CheckBox", () => { "w:sdt": [ { "w:sdtPr": [ + { + "w:alias": { + _attr: { + "w:val": "Checkbox", + }, + }, + }, { "w14:checkbox": [ { @@ -84,6 +91,13 @@ describe("CheckBox", () => { "w:sdt": [ { "w:sdtPr": [ + { + "w:alias": { + _attr: { + "w:val": "Checkbox", + }, + }, + }, { "w14:checkbox": [ { @@ -152,6 +166,13 @@ describe("CheckBox", () => { "w:sdt": [ { "w:sdtPr": [ + { + "w:alias": { + _attr: { + "w:val": "Checkbox", + }, + }, + }, { "w14:checkbox": [ { diff --git a/src/file/checkbox/checkbox.ts b/src/file/checkbox/checkbox.ts index 9f8b55e4f2..f3ba88113c 100644 --- a/src/file/checkbox/checkbox.ts +++ b/src/file/checkbox/checkbox.ts @@ -12,11 +12,9 @@ export class CheckBox extends XmlComponent { public constructor(options?: ICheckboxSymbolOptions) { super("w:sdt"); - this.root.push( - new StructuredDocumentTagProperties(undefined, { - children: [new CheckBoxUtil(options)], - }), - ); + const properties = new StructuredDocumentTagProperties("Checkbox"); + properties.addChildElement(new CheckBoxUtil(options)); + this.root.push(properties); const content = new StructuredDocumentTagContent(); const checkedFont: string | undefined = options?.checkedState?.font; From 20e0213c7d4d1eb2c13465da1f18d3f26ea67bb5 Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 15:37:00 -0400 Subject: [PATCH 08/13] Revert "Revert unnecessary changes to sdt-properties" This reverts commit d1f75e3a422a6b5109e9894bc5edf2c45a9c112e. --- src/file/table-of-contents/sdt-properties.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/file/table-of-contents/sdt-properties.ts b/src/file/table-of-contents/sdt-properties.ts index 241122593a..481235752a 100644 --- a/src/file/table-of-contents/sdt-properties.ts +++ b/src/file/table-of-contents/sdt-properties.ts @@ -1,10 +1,25 @@ // http://www.datypic.com/sc/ooxml/e-w_sdtPr-1.html +import { CheckBoxUtil } from "@file/checkbox"; import { StringValueElement, XmlComponent } from "@file/xml-components"; +export type SdtPrChild = + | CheckBoxUtil; + +export interface ISdtPropertiesOptions { + readonly children : readonly SdtPrChild[]; +} export class StructuredDocumentTagProperties extends XmlComponent { - public constructor(alias: string) { + public constructor(alias?: string, options?: ISdtPropertiesOptions) { super("w:sdtPr"); - this.root.push(new StringValueElement("w:alias", alias)); + if(typeof alias === 'string'){ + this.root.push(new StringValueElement("w:alias", alias)); + } + + if(options?.children){ + for(const child of options.children){ + this.root.push(child) + } + } } } From 58e7dbf445f5cd8779d7520a32b686a5b86fc20d Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 15:39:39 -0400 Subject: [PATCH 09/13] Revert "Modify sdt-properties to accommodate for children elements" This reverts commit f706d8e62d0068d14aac576e936fceaa93b60601. --- src/file/table-of-contents/sdt-properties.ts | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/file/table-of-contents/sdt-properties.ts b/src/file/table-of-contents/sdt-properties.ts index 481235752a..f1f2c56304 100644 --- a/src/file/table-of-contents/sdt-properties.ts +++ b/src/file/table-of-contents/sdt-properties.ts @@ -1,25 +1,9 @@ // http://www.datypic.com/sc/ooxml/e-w_sdtPr-1.html -import { CheckBoxUtil } from "@file/checkbox"; import { StringValueElement, XmlComponent } from "@file/xml-components"; -export type SdtPrChild = - | CheckBoxUtil; - -export interface ISdtPropertiesOptions { - readonly children : readonly SdtPrChild[]; -} export class StructuredDocumentTagProperties extends XmlComponent { - public constructor(alias?: string, options?: ISdtPropertiesOptions) { + public constructor(alias: string) { super("w:sdtPr"); - - if(typeof alias === 'string'){ - this.root.push(new StringValueElement("w:alias", alias)); - } - - if(options?.children){ - for(const child of options.children){ - this.root.push(child) - } - } + this.root.push(new StringValueElement("w:alias", alias)); } } From 41c0fb5fc094ea80fe9367940e0c64cd9a483e97 Mon Sep 17 00:00:00 2001 From: Juan D Date: Fri, 23 Jun 2023 13:04:28 -0400 Subject: [PATCH 10/13] Update sdt-properties to make alias optional --- src/file/table-of-contents/sdt-properties.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/file/table-of-contents/sdt-properties.ts b/src/file/table-of-contents/sdt-properties.ts index f1f2c56304..998167d22a 100644 --- a/src/file/table-of-contents/sdt-properties.ts +++ b/src/file/table-of-contents/sdt-properties.ts @@ -2,8 +2,10 @@ import { StringValueElement, XmlComponent } from "@file/xml-components"; export class StructuredDocumentTagProperties extends XmlComponent { - public constructor(alias: string) { + public constructor(alias?: string) { super("w:sdtPr"); - this.root.push(new StringValueElement("w:alias", alias)); + if(typeof alias === 'string'){ + this.root.push(new StringValueElement("w:alias", alias)); + } } } From 9e9ca526fec4ab851bb6ba9293442338c9aa72d9 Mon Sep 17 00:00:00 2001 From: Juan D Date: Fri, 23 Jun 2023 13:05:21 -0400 Subject: [PATCH 11/13] Prettier syntax update of sdt-properties --- src/file/table-of-contents/sdt-properties.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file/table-of-contents/sdt-properties.ts b/src/file/table-of-contents/sdt-properties.ts index 998167d22a..4ee856eda3 100644 --- a/src/file/table-of-contents/sdt-properties.ts +++ b/src/file/table-of-contents/sdt-properties.ts @@ -4,7 +4,7 @@ import { StringValueElement, XmlComponent } from "@file/xml-components"; export class StructuredDocumentTagProperties extends XmlComponent { public constructor(alias?: string) { super("w:sdtPr"); - if(typeof alias === 'string'){ + if (typeof alias === "string") { this.root.push(new StringValueElement("w:alias", alias)); } } From fa400bcf39fb50f4d6cdb1038732e9f6c4ca8d6a Mon Sep 17 00:00:00 2001 From: Juan D Date: Fri, 23 Jun 2023 13:06:18 -0400 Subject: [PATCH 12/13] update CheckBox and tests to handle optional alias field --- src/file/checkbox/checkbox.spec.ts | 24 +++++------------------- src/file/checkbox/checkbox.ts | 4 ++-- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/file/checkbox/checkbox.spec.ts b/src/file/checkbox/checkbox.spec.ts index 98e96e582b..a2df7819be 100644 --- a/src/file/checkbox/checkbox.spec.ts +++ b/src/file/checkbox/checkbox.spec.ts @@ -4,7 +4,7 @@ import { CheckBox } from "."; describe("CheckBox", () => { describe("#constructor()", () => { - it("should create a CheckBoxUtil with proper root and default values", () => { + it("should create a CheckBox with proper root and default values (no alias, no custom state)", () => { const checkBox = new CheckBox(); const tree = new Formatter().format(checkBox); @@ -13,13 +13,6 @@ describe("CheckBox", () => { "w:sdt": [ { "w:sdtPr": [ - { - "w:alias": { - _attr: { - "w:val": "Checkbox", - }, - }, - }, { "w14:checkbox": [ { @@ -73,7 +66,7 @@ describe("CheckBox", () => { ["2713", "Segoe UI Symbol", "2713", "Segoe UI Symbol"], [undefined, undefined, "2612", "MS Gothic"], ])("should create a CheckBoxUtil with proper root and custom values", (inputChar, inputFont, actualChar, actualFont) => { - const checkBox = new CheckBox({ + const checkBox = new CheckBox("Custom Checkbox", { checked: true, checkedState: { value: inputChar, @@ -94,7 +87,7 @@ describe("CheckBox", () => { { "w:alias": { _attr: { - "w:val": "Checkbox", + "w:val": "Custom Checkbox", }, }, }, @@ -147,8 +140,8 @@ describe("CheckBox", () => { }); }); - it("should create a CheckBoxUtil with proper root and custom values", () => { - const checkBox = new CheckBox({ + it("should create a CheckBoxUtil with proper root, custom state, and no alias", () => { + const checkBox = new CheckBox(undefined, { checked: false, checkedState: { value: "2713", @@ -166,13 +159,6 @@ describe("CheckBox", () => { "w:sdt": [ { "w:sdtPr": [ - { - "w:alias": { - _attr: { - "w:val": "Checkbox", - }, - }, - }, { "w14:checkbox": [ { diff --git a/src/file/checkbox/checkbox.ts b/src/file/checkbox/checkbox.ts index f3ba88113c..c60690e3af 100644 --- a/src/file/checkbox/checkbox.ts +++ b/src/file/checkbox/checkbox.ts @@ -9,10 +9,10 @@ export class CheckBox extends XmlComponent { private readonly DEFAULT_UNCHECKED_SYMBOL: string = "2610"; private readonly DEFAULT_CHECKED_SYMBOL: string = "2612"; private readonly DEFAULT_FONT: string = "MS Gothic"; - public constructor(options?: ICheckboxSymbolOptions) { + public constructor(alias?: string, options?: ICheckboxSymbolOptions) { super("w:sdt"); - const properties = new StructuredDocumentTagProperties("Checkbox"); + const properties = new StructuredDocumentTagProperties(alias); properties.addChildElement(new CheckBoxUtil(options)); this.root.push(properties); From 414d0248f5ada4101985854b4e081bac9805e5c0 Mon Sep 17 00:00:00 2001 From: Juan D Date: Fri, 23 Jun 2023 15:36:08 -0400 Subject: [PATCH 13/13] Update Checkbox test description --- src/file/checkbox/checkbox.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/file/checkbox/checkbox.spec.ts b/src/file/checkbox/checkbox.spec.ts index a2df7819be..8599e60f42 100644 --- a/src/file/checkbox/checkbox.spec.ts +++ b/src/file/checkbox/checkbox.spec.ts @@ -65,7 +65,7 @@ describe("CheckBox", () => { it.each([ ["2713", "Segoe UI Symbol", "2713", "Segoe UI Symbol"], [undefined, undefined, "2612", "MS Gothic"], - ])("should create a CheckBoxUtil with proper root and custom values", (inputChar, inputFont, actualChar, actualFont) => { + ])("should create a CheckBox with proper root and custom values", (inputChar, inputFont, actualChar, actualFont) => { const checkBox = new CheckBox("Custom Checkbox", { checked: true, checkedState: { @@ -140,7 +140,7 @@ describe("CheckBox", () => { }); }); - it("should create a CheckBoxUtil with proper root, custom state, and no alias", () => { + it("should create a CheckBox with proper root, custom state, and no alias", () => { const checkBox = new CheckBox(undefined, { checked: false, checkedState: {