fix: added unique numeric id creator to avoid numbering render errors
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
import { IContext, IXmlableObject, NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { ConcreteHyperlink } from "@file/paragraph";
|
||||
|
||||
import { uniqueNumericId } from "@util/convenience-functions";
|
||||
import { uniqueNumericIdCreator } from "@util/convenience-functions";
|
||||
|
||||
import { createHyperlinkClick } from "./doc-properties-children";
|
||||
|
||||
@ -24,6 +24,8 @@ export interface DocPropertiesOptions {
|
||||
readonly title: string;
|
||||
}
|
||||
|
||||
const uniqueNumericId = uniqueNumericIdCreator();
|
||||
|
||||
export class DocProperties extends XmlComponent {
|
||||
public constructor({ name, description, title }: DocPropertiesOptions = { name: "", description: "", title: "" }) {
|
||||
super("wp:docPr");
|
||||
|
@ -2,7 +2,7 @@
|
||||
// https://stackoverflow.com/questions/58622437/purpose-of-abstractnum-and-numberinginstance
|
||||
import { AlignmentType } from "@file/paragraph";
|
||||
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
|
||||
import { convertInchesToTwip, uniqueNumericId } from "@util/convenience-functions";
|
||||
import { convertInchesToTwip, uniqueNumericIdCreator } from "@util/convenience-functions";
|
||||
|
||||
import { DocumentAttributes } from "../document/document-attributes";
|
||||
import { AbstractNumbering } from "./abstract-numbering";
|
||||
@ -16,6 +16,9 @@ export interface INumberingOptions {
|
||||
}[];
|
||||
}
|
||||
|
||||
const abstractNumUniqueNumericId = uniqueNumericIdCreator();
|
||||
const concreteNumUniqueNumericId = uniqueNumericIdCreator(1); // Setting initial to 1 as we have numId = 1 for "default-bullet-numbering"
|
||||
|
||||
// <xsd:element name="numbering" type="CT_Numbering"/>
|
||||
//
|
||||
// <xsd:complexType name="CT_Numbering">
|
||||
@ -55,7 +58,7 @@ export class Numbering extends XmlComponent {
|
||||
}),
|
||||
);
|
||||
|
||||
const abstractNumbering = new AbstractNumbering(uniqueNumericId(), [
|
||||
const abstractNumbering = new AbstractNumbering(abstractNumUniqueNumericId(), [
|
||||
{
|
||||
level: 0,
|
||||
format: LevelFormat.BULLET,
|
||||
@ -176,7 +179,7 @@ export class Numbering extends XmlComponent {
|
||||
this.abstractNumberingMap.set("default-bullet-numbering", abstractNumbering);
|
||||
|
||||
for (const con of options.config) {
|
||||
this.abstractNumberingMap.set(con.reference, new AbstractNumbering(uniqueNumericId(), con.levels));
|
||||
this.abstractNumberingMap.set(con.reference, new AbstractNumbering(abstractNumUniqueNumericId(), con.levels));
|
||||
this.referenceConfigMap.set(con.reference, con.levels);
|
||||
}
|
||||
}
|
||||
@ -209,7 +212,7 @@ export class Numbering extends XmlComponent {
|
||||
const firstLevelStartNumber = referenceConfigLevels && referenceConfigLevels[0].start;
|
||||
|
||||
const concreteNumberingSettings = {
|
||||
numId: uniqueNumericId(),
|
||||
numId: concreteNumUniqueNumericId(),
|
||||
abstractNumId: abstractNumbering.id,
|
||||
reference,
|
||||
instance,
|
||||
|
@ -1,10 +1,12 @@
|
||||
// http://officeopenxml.com/WPbookmark.php
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { uniqueNumericId } from "@util/convenience-functions";
|
||||
import { uniqueNumericIdCreator } from "@util/convenience-functions";
|
||||
|
||||
import { ParagraphChild } from "../paragraph";
|
||||
import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes";
|
||||
|
||||
const uniqueNumericId = uniqueNumericIdCreator();
|
||||
|
||||
export class Bookmark {
|
||||
public readonly start: BookmarkStart;
|
||||
public readonly children: readonly ParagraphChild[];
|
||||
|
@ -1,12 +1,14 @@
|
||||
import { nanoid } from "nanoid/non-secure";
|
||||
|
||||
let currentCount = 0;
|
||||
|
||||
// Twip - twentieths of a point
|
||||
export const convertMillimetersToTwip = (millimeters: number): number => Math.floor((millimeters / 25.4) * 72 * 20);
|
||||
|
||||
export const convertInchesToTwip = (inches: number): number => Math.floor(inches * 72 * 20);
|
||||
|
||||
export const uniqueNumericId = (): number => ++currentCount;
|
||||
export const uniqueNumericIdCreator = (initial = 0): (() => number) => {
|
||||
let currentCount = initial;
|
||||
|
||||
return () => ++currentCount;
|
||||
};
|
||||
|
||||
export const uniqueId = (): string => nanoid().toLowerCase();
|
||||
|
Reference in New Issue
Block a user