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

79 lines
2.1 KiB
TypeScript
Raw Normal View History

import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { LevelForOverride } from "./level";
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
}
}
2017-03-08 17:16:51 +01:00
interface INumAttributesProperties {
readonly numId: number;
2016-05-21 00:02:46 +01:00
}
class NumAttributes extends XmlAttributeComponent<INumAttributesProperties> {
protected readonly xmlKeys = { numId: "w:numId" };
2016-05-21 00:02:46 +01:00
}
2019-11-01 01:57:01 +00:00
export class ConcreteNumbering extends XmlComponent {
public readonly id: number;
2016-05-26 15:08:34 +01:00
2019-11-08 03:11:19 +00:00
constructor(numId: number, abstractNumId: number, public readonly reference?: string) {
2016-05-21 00:02:46 +01:00
super("w:num");
2018-01-23 01:33:12 +00:00
this.root.push(
new NumAttributes({
numId: numId,
}),
);
2016-05-21 00:02:46 +01:00
this.root.push(new AbstractNumId(abstractNumId));
this.id = numId;
}
public overrideLevel(num: number, start?: number): LevelOverride {
const olvl = new LevelOverride(num, start);
this.root.push(olvl);
return olvl;
}
}
class LevelOverrideAttributes extends XmlAttributeComponent<{ readonly ilvl: number }> {
protected readonly xmlKeys = { ilvl: "w:ilvl" };
}
export class LevelOverride extends XmlComponent {
private readonly lvl: LevelForOverride;
2018-01-29 01:55:25 +00:00
constructor(private readonly 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));
}
2019-11-06 20:54:39 +00:00
this.lvl = new LevelForOverride({
level: this.levelNum,
});
this.root.push(this.lvl);
}
2018-08-07 01:25:28 +01:00
public get Level(): LevelForOverride {
return this.lvl;
}
}
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
}