Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
b7334a1ab5 | |||
9229f45d59 | |||
2bd4aacdd5 |
@ -18,6 +18,7 @@ const receiptTabStops = [
|
||||
const twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }];
|
||||
|
||||
const doc = new Document({
|
||||
defaultTabStop: 0,
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "8.3.0",
|
||||
"version": "8.4.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "docx",
|
||||
"version": "8.3.0",
|
||||
"version": "8.4.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "^20.3.1",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "8.3.0",
|
||||
"version": "8.4.0",
|
||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||
"type": "module",
|
||||
"main": "build/index.umd.js",
|
||||
|
@ -39,6 +39,7 @@ export interface IPropertiesOptions {
|
||||
readonly compatibility?: ICompatibilityOptions;
|
||||
readonly customProperties?: readonly ICustomPropertyOptions[];
|
||||
readonly evenAndOddHeaderAndFooters?: boolean;
|
||||
readonly defaultTabStop?: number;
|
||||
}
|
||||
|
||||
// <xs:element name="coreProperties" type="CT_CoreProperties"/>
|
||||
|
@ -77,6 +77,7 @@ export class File {
|
||||
evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false,
|
||||
trackRevisions: options.features?.trackRevisions,
|
||||
updateFields: options.features?.updateFields,
|
||||
defaultTabStop: options.defaultTabStop,
|
||||
});
|
||||
|
||||
this.media = new Media();
|
||||
|
@ -157,9 +157,9 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
* Ensure there is only one w:tabs tag with multiple w:tab
|
||||
*/
|
||||
const tabDefinitions: readonly TabStopDefinition[] = [
|
||||
...(options.rightTabStop ? [{ type: TabStopType.RIGHT, position: options.rightTabStop }] : []),
|
||||
...(options.rightTabStop !== undefined ? [{ type: TabStopType.RIGHT, position: options.rightTabStop }] : []),
|
||||
...(options.tabStops ? options.tabStops : []),
|
||||
...(options.leftTabStop ? [{ type: TabStopType.LEFT, position: options.leftTabStop }] : []),
|
||||
...(options.leftTabStop !== undefined ? [{ type: TabStopType.LEFT, position: options.leftTabStop }] : []),
|
||||
];
|
||||
|
||||
if (tabDefinitions.length > 0) {
|
||||
|
@ -112,6 +112,23 @@ describe("Settings", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should add defaultTabStop setting with version", () => {
|
||||
const settings = new Settings({
|
||||
defaultTabStop: 100,
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(settings);
|
||||
expect(Object.keys(tree)).has.length(1);
|
||||
expect(tree["w:settings"]).to.be.an("array");
|
||||
expect(tree["w:settings"]).to.deep.include({
|
||||
"w:defaultTabStop": {
|
||||
_attr: {
|
||||
"w:val": 100,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Remove when deprecating compatibilityModeVersion
|
||||
it("should add compatibility setting with legacy version", () => {
|
||||
const settings = new Settings({
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { NumberValueElement, OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { Compatibility, ICompatibilityOptions } from "./compatibility";
|
||||
|
||||
@ -152,6 +152,7 @@ export interface ISettingsOptions {
|
||||
readonly trackRevisions?: boolean;
|
||||
readonly updateFields?: boolean;
|
||||
readonly compatibility?: ICompatibilityOptions;
|
||||
readonly defaultTabStop?: number;
|
||||
}
|
||||
|
||||
export class Settings extends XmlComponent {
|
||||
@ -198,6 +199,11 @@ export class Settings extends XmlComponent {
|
||||
this.root.push(new OnOffElement("w:updateFields", options.updateFields));
|
||||
}
|
||||
|
||||
// https://c-rex.net/samples/ooxml/e1/Part4/OOXML_P4_DOCX_defaultTabStop_topic_ID0EIXSX.html
|
||||
if (options.defaultTabStop !== undefined) {
|
||||
this.root.push(new NumberValueElement("w:defaultTabStop", options.defaultTabStop));
|
||||
}
|
||||
|
||||
this.root.push(
|
||||
new Compatibility({
|
||||
...(options.compatibility ?? {}),
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"target": "ES2015",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"lib": ["ES2015", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
|
Reference in New Issue
Block a user