Files
docx-js/src/file/numbering/num.ts

81 lines
2.2 KiB
TypeScript
Raw Normal View History

import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
2016-05-21 00:02:46 +01:00
class AbstractNumId extends XmlComponent {
constructor(value: number) {
super("w:abstractNumId");
2018-01-23 01:33:12 +00:00
this.root.push(
new Attributes({
val: value,
}),
);
2016-05-21 00:02:46 +01:00
}
}
2021-03-12 03:58:05 +00:00
class NumAttributes extends XmlAttributeComponent<{
readonly numId: number;
2021-03-12 03:58:05 +00:00
}> {
protected readonly xmlKeys = { numId: "w:numId" };
2016-05-21 00:02:46 +01:00
}
2021-03-12 03:58:05 +00:00
export interface IConcreteNumberingOptions {
readonly numId: number;
readonly abstractNumId: number;
readonly reference: string;
readonly instance: number;
readonly overrideLevel?: {
readonly num: number;
readonly start?: number;
};
2016-05-21 00:02:46 +01:00
}
2019-11-01 01:57:01 +00:00
export class ConcreteNumbering extends XmlComponent {
2021-03-12 03:58:05 +00:00
public readonly numId: number;
public readonly reference: string;
public readonly instance: number;
2016-05-26 15:08:34 +01:00
2021-03-12 03:58:05 +00:00
constructor(options: IConcreteNumberingOptions) {
2016-05-21 00:02:46 +01:00
super("w:num");
2021-03-12 03:58:05 +00:00
this.numId = options.numId;
this.reference = options.reference;
this.instance = options.instance;
2018-01-23 01:33:12 +00:00
this.root.push(
new NumAttributes({
2021-03-12 03:58:05 +00:00
numId: options.numId,
2018-01-23 01:33:12 +00:00
}),
);
2021-03-12 03:58:05 +00:00
this.root.push(new AbstractNumId(options.abstractNumId));
if (options.overrideLevel) {
this.root.push(new LevelOverride(options.overrideLevel.num, options.overrideLevel.start));
}
}
}
class LevelOverrideAttributes extends XmlAttributeComponent<{ readonly ilvl: number }> {
protected readonly xmlKeys = { ilvl: "w:ilvl" };
}
export class LevelOverride extends XmlComponent {
2021-03-12 03:58:05 +00:00
constructor(levelNum: number, start?: number) {
super("w:lvlOverride");
2018-01-23 01:33:12 +00:00
this.root.push(new LevelOverrideAttributes({ ilvl: levelNum }));
if (start !== undefined) {
this.root.push(new StartOverride(start));
}
}
}
class StartOverrideAttributes extends XmlAttributeComponent<{ readonly val: number }> {
protected readonly xmlKeys = { val: "w:val" };
}
class StartOverride extends XmlComponent {
constructor(start: number) {
super("w:startOverride");
2018-01-23 01:33:12 +00:00
this.root.push(new StartOverrideAttributes({ val: start }));
}
2017-03-08 17:16:51 +01:00
}