@portone/docx-editor 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +174 -0
- package/CONTRIBUTING.md +9 -1
- package/dist/DocxEditor.d.ts +6 -0
- package/dist/DocxEditor.js +12 -29
- package/dist/core.d.ts +23 -8
- package/dist/core.js +9 -4
- package/dist/docx/cloning.d.ts +38 -0
- package/dist/docx/cloning.js +74 -0
- package/dist/docx/commentOnlyChange.d.ts +14 -7
- package/dist/docx/commentOnlyChange.js +9 -139
- package/dist/docx/comments/constants.d.ts +3 -4
- package/dist/docx/comments/constants.js +4 -5
- package/dist/docx/comments/grammar.d.ts +86 -0
- package/dist/docx/comments/grammar.js +223 -0
- package/dist/docx/comments/parts.d.ts +52 -0
- package/dist/docx/comments/parts.js +279 -0
- package/dist/docx/comments/people.d.ts +11 -2
- package/dist/docx/comments/people.js +28 -106
- package/dist/docx/comments/policy.d.ts +7 -0
- package/dist/docx/comments/policy.js +43 -0
- package/dist/docx/comments/reading.d.ts +5 -3
- package/dist/docx/comments/reading.js +30 -29
- package/dist/docx/comments/writing.d.ts +19 -7
- package/dist/docx/comments/writing.js +105 -137
- package/dist/docx/documentSettings.d.ts +7 -0
- package/dist/docx/documentSettings.js +10 -2
- package/dist/docx/exportDocx.d.ts +40 -5
- package/dist/docx/exportDocx.js +71 -72
- package/dist/docx/exportRefs.d.ts +5 -2
- package/dist/docx/exportRefs.js +3 -1
- package/dist/docx/fidelity.d.ts +43 -0
- package/dist/docx/fidelity.js +64 -0
- package/dist/docx/formatting/attrs.d.ts +27 -0
- package/dist/docx/formatting/attrs.js +31 -0
- package/dist/docx/formatting/context.d.ts +31 -0
- package/dist/docx/formatting/context.js +42 -0
- package/dist/docx/formatting/direct.d.ts +6 -5
- package/dist/docx/formatting/direct.js +52 -81
- package/dist/docx/formatting/resolve.d.ts +45 -0
- package/dist/docx/formatting/resolve.js +140 -0
- package/dist/docx/formatting/runProperties.d.ts +93 -0
- package/dist/docx/formatting/runProperties.js +316 -0
- package/dist/docx/formatting/styles.js +3 -3
- package/dist/docx/formatting/tabStops.js +7 -22
- package/dist/docx/formatting.d.ts +4 -1
- package/dist/docx/formatting.js +4 -1
- package/dist/docx/headersFooters.js +13 -22
- package/dist/docx/identities.d.ts +67 -0
- package/dist/docx/identities.js +174 -0
- package/dist/docx/importDocx.d.ts +12 -1
- package/dist/docx/importDocx.js +72 -79
- package/dist/docx/importParagraph.d.ts +1 -1
- package/dist/docx/importParagraph.js +4 -3
- package/dist/docx/importTable.d.ts +1 -1
- package/dist/docx/importTable.js +17 -1
- package/dist/docx/invariants.d.ts +33 -0
- package/dist/docx/invariants.js +256 -0
- package/dist/docx/media.d.ts +6 -4
- package/dist/docx/media.js +6 -37
- package/dist/docx/newLists.d.ts +20 -0
- package/dist/docx/newLists.js +36 -0
- package/dist/docx/notes.js +6 -12
- package/dist/docx/numberingPlanner.d.ts +8 -0
- package/dist/docx/numberingPlanner.js +19 -0
- package/dist/docx/packageParts.d.ts +42 -0
- package/dist/docx/packageParts.js +135 -0
- package/dist/docx/pageGeometry.d.ts +2 -0
- package/dist/docx/pageGeometry.js +18 -9
- package/dist/docx/paraProps.d.ts +10 -22
- package/dist/docx/paraProps.js +75 -99
- package/dist/docx/partPlan.d.ts +36 -0
- package/dist/docx/partPlan.js +59 -0
- package/dist/docx/protectionPolicy.d.ts +127 -0
- package/dist/docx/protectionPolicy.js +169 -0
- package/dist/docx/relationships.d.ts +1 -1
- package/dist/docx/relationships.js +15 -15
- package/dist/docx/runProps.d.ts +9 -22
- package/dist/docx/runProps.js +15 -168
- package/dist/docx/scan.js +20 -52
- package/dist/docx/sdt.js +14 -37
- package/dist/docx/sdtProps.d.ts +8 -1
- package/dist/docx/sdtProps.js +10 -0
- package/dist/docx/serializeBlock.d.ts +2 -0
- package/dist/docx/serializeBlock.js +9 -7
- package/dist/docx/serializeParagraph.d.ts +2 -1
- package/dist/docx/serializeParagraph.js +25 -14
- package/dist/docx/serializeTable.js +63 -32
- package/dist/docx/session.d.ts +42 -14
- package/dist/docx/session.js +43 -17
- package/dist/docx/storyProjection.d.ts +36 -0
- package/dist/docx/storyProjection.js +23 -0
- package/dist/docx/tableFormatting/editing.js +130 -185
- package/dist/docx/tableFormatting/reading.d.ts +16 -6
- package/dist/docx/tableFormatting/reading.js +40 -20
- package/dist/docx/tableTemplate.js +37 -5
- package/dist/docx/theme.d.ts +0 -6
- package/dist/docx/theme.js +0 -8
- package/dist/download.d.ts +8 -5
- package/dist/download.js +2 -0
- package/dist/editor/clipboard/images.js +17 -3
- package/dist/editor/clipboard/inlineFormatting.d.ts +7 -0
- package/dist/editor/clipboard/inlineFormatting.js +20 -30
- package/dist/editor/commands/breakCommands.js +4 -3
- package/dist/editor/commands/canRunCommand.d.ts +2 -2
- package/dist/editor/commands/canRunCommand.js +1 -1
- package/dist/editor/commands/comments/editing.d.ts +6 -2
- package/dist/editor/commands/comments/editing.js +21 -36
- package/dist/editor/commands/exportQueries.d.ts +15 -0
- package/dist/editor/commands/exportQueries.js +14 -0
- package/dist/editor/commands/fidelityQueries.d.ts +12 -0
- package/dist/editor/commands/fidelityQueries.js +8 -0
- package/dist/editor/commands/formatting/editing.d.ts +2 -2
- package/dist/editor/commands/formatting/editing.js +26 -108
- package/dist/editor/commands/formatting/propertyCommands.d.ts +21 -0
- package/dist/editor/commands/formatting/propertyCommands.js +103 -0
- package/dist/editor/commands/formatting/shared.d.ts +3 -3
- package/dist/editor/commands/formatting/shared.js +5 -2
- package/dist/editor/commands/historyCommands.js +2 -1
- package/dist/editor/commands/indentCommands.js +5 -4
- package/dist/editor/commands/index.d.ts +11 -0
- package/dist/editor/commands/index.js +5 -0
- package/dist/editor/commands/linkCommands.js +5 -6
- package/dist/editor/commands/listCommands.js +8 -10
- package/dist/editor/commands/lockCommands.d.ts +7 -1
- package/dist/editor/commands/lockCommands.js +35 -37
- package/dist/editor/commands/paragraphCommands.js +28 -31
- package/dist/editor/commands/spacingCommands.js +1 -1
- package/dist/editor/commands/tabCommands.js +4 -3
- package/dist/editor/createEditor.d.ts +17 -29
- package/dist/editor/createEditor.js +61 -67
- package/dist/editor/documentStyles.d.ts +11 -35
- package/dist/editor/documentStyles.js +9 -52
- package/dist/editor/editorDocument.d.ts +56 -0
- package/dist/editor/editorDocument.js +74 -0
- package/dist/editor/externalClipboard.js +166 -33
- package/dist/editor/insertImage.js +4 -3
- package/dist/editor/insertTable.js +4 -3
- package/dist/editor/paragraphEdits.d.ts +11 -18
- package/dist/editor/paragraphEdits.js +7 -16
- package/dist/editor/plugins/displayDerivation.d.ts +47 -0
- package/dist/editor/plugins/displayDerivation.js +78 -0
- package/dist/editor/plugins/documentProtection.d.ts +3 -3
- package/dist/editor/plugins/imagePaste.js +4 -3
- package/dist/editor/plugins/keymap.js +18 -3
- package/dist/editor/plugins/lockedContent.d.ts +4 -4
- package/dist/editor/plugins/lockedContent.js +1 -1
- package/dist/editor/plugins/numberingDecorations.d.ts +5 -11
- package/dist/editor/plugins/numberingDecorations.js +7 -17
- package/dist/editor/plugins/paragraphDisplay.d.ts +7 -0
- package/dist/editor/plugins/paragraphDisplay.js +51 -0
- package/dist/editor/plugins/tabLayout.js +1 -1
- package/dist/editor/plugins/tableDisplay.d.ts +6 -0
- package/dist/editor/plugins/tableDisplay.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/model/format.d.ts +30 -8
- package/dist/model/format.js +35 -22
- package/dist/model/tabStops.d.ts +9 -0
- package/dist/model/tabStops.js +18 -0
- package/dist/numbering/listTemplate.js +49 -10
- package/dist/numbering/parseNumbering.d.ts +14 -1
- package/dist/numbering/parseNumbering.js +35 -22
- package/dist/numbering/writeNumbering.d.ts +3 -4
- package/dist/numbering/writeNumbering.js +14 -25
- package/dist/ooxml/childOrder.d.ts +34 -0
- package/dist/ooxml/childOrder.js +496 -0
- package/dist/ooxml/element.d.ts +65 -0
- package/dist/ooxml/element.js +68 -0
- package/dist/ooxml/errors.d.ts +3 -2
- package/dist/ooxml/fragment.d.ts +53 -0
- package/dist/ooxml/fragment.js +76 -0
- package/dist/ooxml/image.d.ts +4 -0
- package/dist/ooxml/image.js +3 -5
- package/dist/ooxml/names.d.ts +27 -0
- package/dist/ooxml/names.js +29 -0
- package/dist/ooxml/partSplice.d.ts +67 -0
- package/dist/ooxml/partSplice.js +169 -0
- package/dist/ooxml/precedence.d.ts +31 -0
- package/dist/ooxml/precedence.js +51 -0
- package/dist/ooxml/props.d.ts +112 -0
- package/dist/ooxml/props.js +214 -0
- package/dist/ooxml/simpleTypes.d.ts +103 -0
- package/dist/ooxml/simpleTypes.js +182 -0
- package/dist/ooxml/tabStops.js +8 -27
- package/dist/ooxml/tagScan.d.ts +34 -0
- package/dist/ooxml/tagScan.js +108 -0
- package/dist/ooxml/units.d.ts +25 -13
- package/dist/ooxml/units.js +65 -31
- package/dist/ooxml/xml.d.ts +52 -0
- package/dist/ooxml/xml.js +64 -5
- package/dist/page/blockKinds.d.ts +103 -0
- package/dist/page/blockKinds.js +11 -0
- package/dist/page/kinds/index.d.ts +6 -0
- package/dist/page/kinds/index.js +10 -0
- package/dist/page/kinds/paragraphKind.d.ts +10 -0
- package/dist/page/kinds/paragraphKind.js +71 -0
- package/dist/page/kinds/tableKind.d.ts +10 -0
- package/dist/page/kinds/tableKind.js +178 -0
- package/dist/page/measureBlocks.d.ts +3 -1
- package/dist/page/measureBlocks.js +24 -25
- package/dist/page/pageDecorations.d.ts +27 -28
- package/dist/page/pageDecorations.js +70 -151
- package/dist/page/pageLayout.d.ts +10 -62
- package/dist/page/pageLayout.js +60 -53
- package/dist/page/usePageLayout.d.ts +2 -2
- package/dist/page/usePageLayout.js +3 -11
- package/dist/schema/attrRoles.d.ts +42 -0
- package/dist/schema/attrRoles.js +141 -0
- package/dist/schema/displayDerivation.d.ts +82 -0
- package/dist/schema/displayDerivation.js +130 -0
- package/dist/schema/docxSchema.d.ts +9 -0
- package/dist/schema/docxSchema.js +237 -114
- package/dist/schema/editGuard.d.ts +99 -0
- package/dist/schema/editGuard.js +43 -0
- package/dist/schema/guards.d.ts +91 -0
- package/dist/schema/guards.js +108 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +2 -0
- package/dist/schema/locks.d.ts +17 -77
- package/dist/schema/locks.js +26 -70
- package/dist/schema/preservedGuards.d.ts +50 -0
- package/dist/schema/preservedGuards.js +80 -0
- package/dist/schema/protection.d.ts +17 -4
- package/dist/schema/protection.js +4 -2
- package/dist/schema/sourceEquality.d.ts +19 -0
- package/dist/schema/sourceEquality.js +39 -0
- package/dist/styles/inlineStyle.js +15 -6
- package/dist/table/cellFormatting.d.ts +8 -1
- package/dist/table/cellFormatting.js +10 -17
- package/dist/table/commands.d.ts +2 -2
- package/dist/table/commands.js +20 -18
- package/dist/table/format.d.ts +3 -0
- package/dist/table/format.js +3 -9
- package/dist/table/gridBorders.d.ts +14 -16
- package/dist/table/gridBorders.js +3 -41
- package/dist/table/index.d.ts +2 -2
- package/dist/table/merge.d.ts +4 -8
- package/dist/table/merge.js +5 -5
- package/package.json +10 -3
- package/dist/docx/comments/contentTypes.d.ts +0 -7
- package/dist/docx/comments/contentTypes.js +0 -38
- package/dist/docx/formatting/effectiveParagraph.d.ts +0 -15
- package/dist/docx/formatting/effectiveParagraph.js +0 -81
- package/dist/docx/propsXml.d.ts +0 -49
- package/dist/docx/propsXml.js +0 -302
- package/dist/docx/uniqueControls.d.ts +0 -14
- package/dist/docx/uniqueControls.js +0 -62
- package/dist/editor/plugins/bookmarkProtection.d.ts +0 -3
- package/dist/editor/plugins/bookmarkProtection.js +0 -28
- package/dist/editor/plugins/commentReservations.d.ts +0 -5
- package/dist/editor/plugins/commentReservations.js +0 -26
- package/dist/editor/plugins/noteProtection.d.ts +0 -3
- package/dist/editor/plugins/noteProtection.js +0 -25
- package/dist/editor/plugins/styledParagraphs.d.ts +0 -15
- package/dist/editor/plugins/styledParagraphs.js +0 -65
- package/dist/page/tableMeasurements.d.ts +0 -10
- package/dist/page/tableMeasurements.js +0 -115
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
// src/numbering/parseNumbering.ts
|
|
2
|
+
import {
|
|
3
|
+
ST_DecimalNumber,
|
|
4
|
+
ST_SignedTwipsMeasure,
|
|
5
|
+
ST_TwipsMeasure
|
|
6
|
+
} from "../ooxml/simpleTypes.js";
|
|
2
7
|
import { readTabStopDirectives } from "../ooxml/tabStops.js";
|
|
3
|
-
import { childValue,
|
|
4
|
-
import {
|
|
8
|
+
import { childValue, twipsToPt, wAttr } from "../ooxml/units.js";
|
|
9
|
+
import {
|
|
10
|
+
childByLocalName,
|
|
11
|
+
elementChildren,
|
|
12
|
+
parseXml,
|
|
13
|
+
withXmlParser
|
|
14
|
+
} from "../ooxml/xml.js";
|
|
5
15
|
var NUMBER_FORMATS = [
|
|
6
16
|
"decimal",
|
|
7
17
|
"bullet",
|
|
@@ -10,11 +20,6 @@ var NUMBER_FORMATS = [
|
|
|
10
20
|
"lowerRoman"
|
|
11
21
|
];
|
|
12
22
|
var EMPTY_NUMBERING = { lists: /* @__PURE__ */ new Map() };
|
|
13
|
-
function toInteger(value) {
|
|
14
|
-
if (value === null) return null;
|
|
15
|
-
const parsed = Number.parseInt(value, 10);
|
|
16
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
17
|
-
}
|
|
18
23
|
function isNumberFormat(value) {
|
|
19
24
|
return NUMBER_FORMATS.some((format) => format === value);
|
|
20
25
|
}
|
|
@@ -22,13 +27,17 @@ function indentOf(lvl) {
|
|
|
22
27
|
const pPr = childByLocalName(lvl, "pPr");
|
|
23
28
|
const ind = pPr ? childByLocalName(pPr, "ind") : null;
|
|
24
29
|
if (!ind) return null;
|
|
25
|
-
const startTwips =
|
|
26
|
-
|
|
30
|
+
const startTwips = ST_SignedTwipsMeasure.parse(
|
|
31
|
+
wAttr(ind, "start") ?? wAttr(ind, "left")
|
|
32
|
+
);
|
|
33
|
+
const endTwips = ST_SignedTwipsMeasure.parse(
|
|
34
|
+
wAttr(ind, "end") ?? wAttr(ind, "right")
|
|
35
|
+
);
|
|
27
36
|
const indent = {
|
|
28
37
|
startTwips,
|
|
29
38
|
endTwips,
|
|
30
|
-
hangingTwips:
|
|
31
|
-
firstLineTwips:
|
|
39
|
+
hangingTwips: ST_TwipsMeasure.parse(wAttr(ind, "hanging")),
|
|
40
|
+
firstLineTwips: ST_TwipsMeasure.parse(wAttr(ind, "firstLine"))
|
|
32
41
|
};
|
|
33
42
|
const empty = startTwips === null && endTwips === null && indent.hangingTwips === null && indent.firstLineTwips === null;
|
|
34
43
|
return empty ? null : indent;
|
|
@@ -38,9 +47,6 @@ var NO_LEVEL_INDENT = {
|
|
|
38
47
|
endPt: null,
|
|
39
48
|
textIndentPt: null
|
|
40
49
|
};
|
|
41
|
-
function twipsToPt(twips) {
|
|
42
|
-
return twips === null ? null : round(twips / 20);
|
|
43
|
-
}
|
|
44
50
|
function levelIndentPt(indent) {
|
|
45
51
|
if (!indent) return NO_LEVEL_INDENT;
|
|
46
52
|
const hangingPt = twipsToPt(indent.hangingTwips);
|
|
@@ -57,7 +63,7 @@ function readLevel(lvl) {
|
|
|
57
63
|
return {
|
|
58
64
|
format: isNumberFormat(format) ? format : "decimal",
|
|
59
65
|
text: childValue(lvl, "lvlText") ?? "",
|
|
60
|
-
start:
|
|
66
|
+
start: ST_DecimalNumber.parse(childValue(lvl, "start")) ?? 1,
|
|
61
67
|
indent: indentOf(lvl),
|
|
62
68
|
...tabStops.length === 0 ? {} : { tabStops }
|
|
63
69
|
};
|
|
@@ -66,23 +72,27 @@ function readLevels(parent) {
|
|
|
66
72
|
const levels = /* @__PURE__ */ new Map();
|
|
67
73
|
for (const child of elementChildren(parent)) {
|
|
68
74
|
if (child.localName !== "lvl") continue;
|
|
69
|
-
const ilvl =
|
|
75
|
+
const ilvl = ST_DecimalNumber.parse(wAttr(child, "ilvl"));
|
|
70
76
|
if (ilvl !== null) levels.set(ilvl, readLevel(child));
|
|
71
77
|
}
|
|
72
78
|
return levels;
|
|
73
79
|
}
|
|
74
80
|
function readList(num, abstractLevels) {
|
|
75
|
-
const abstractNumId =
|
|
81
|
+
const abstractNumId = ST_DecimalNumber.parse(
|
|
82
|
+
childValue(num, "abstractNumId")
|
|
83
|
+
);
|
|
76
84
|
if (abstractNumId === null) return null;
|
|
77
85
|
const levels = new Map(abstractLevels.get(abstractNumId) ?? []);
|
|
78
86
|
for (const child of elementChildren(num)) {
|
|
79
87
|
if (child.localName !== "lvlOverride") continue;
|
|
80
|
-
const ilvl =
|
|
88
|
+
const ilvl = ST_DecimalNumber.parse(wAttr(child, "ilvl"));
|
|
81
89
|
if (ilvl === null) continue;
|
|
82
90
|
const replacement = childByLocalName(child, "lvl");
|
|
83
91
|
const base = replacement ? readLevel(replacement) : levels.get(ilvl);
|
|
84
92
|
if (!base) continue;
|
|
85
|
-
const startOverride =
|
|
93
|
+
const startOverride = ST_DecimalNumber.parse(
|
|
94
|
+
childValue(child, "startOverride")
|
|
95
|
+
);
|
|
86
96
|
levels.set(
|
|
87
97
|
ilvl,
|
|
88
98
|
startOverride === null ? base : { ...base, start: startOverride }
|
|
@@ -90,19 +100,22 @@ function readList(num, abstractLevels) {
|
|
|
90
100
|
}
|
|
91
101
|
return { levels };
|
|
92
102
|
}
|
|
93
|
-
function parseNumbering(xml) {
|
|
103
|
+
function parseNumbering(xml, options) {
|
|
94
104
|
if (xml === null) return EMPTY_NUMBERING;
|
|
105
|
+
return withXmlParser(options?.xmlParser, () => readNumbering(xml));
|
|
106
|
+
}
|
|
107
|
+
function readNumbering(xml) {
|
|
95
108
|
const root = parseXml(xml).documentElement;
|
|
96
109
|
const abstractLevels = /* @__PURE__ */ new Map();
|
|
97
110
|
for (const child of elementChildren(root)) {
|
|
98
111
|
if (child.localName !== "abstractNum") continue;
|
|
99
|
-
const id =
|
|
112
|
+
const id = ST_DecimalNumber.parse(wAttr(child, "abstractNumId"));
|
|
100
113
|
if (id !== null) abstractLevels.set(id, readLevels(child));
|
|
101
114
|
}
|
|
102
115
|
const lists = /* @__PURE__ */ new Map();
|
|
103
116
|
for (const child of elementChildren(root)) {
|
|
104
117
|
if (child.localName !== "num") continue;
|
|
105
|
-
const numId =
|
|
118
|
+
const numId = ST_DecimalNumber.parse(wAttr(child, "numId"));
|
|
106
119
|
const list = numId === null ? null : readList(child, abstractLevels);
|
|
107
120
|
if (numId !== null && list) lists.set(numId, list);
|
|
108
121
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Splices the definitions of newly started lists into the original numbering.xml.
|
|
3
3
|
*
|
|
4
|
-
* Not one character of the original is altered; new elements are merely slotted in
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* the definitions go in front of the first number and the numbers go at the very end.
|
|
4
|
+
* Not one character of the original is altered; new elements are merely slotted in.
|
|
5
|
+
* OOXML requires the definitions (`abstractNum`) to come before the numbers (`num`), and
|
|
6
|
+
* `CHILD_ORDER.numbering` is what places each where it belongs among what the part holds.
|
|
8
7
|
*/
|
|
9
8
|
/**
|
|
10
9
|
* numbering.xml with a standard template definition added for every list number.
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
// src/numbering/writeNumbering.ts
|
|
2
|
-
import {
|
|
2
|
+
import { splicePart } from "../ooxml/partSplice.js";
|
|
3
3
|
import { wAttr } from "../ooxml/units.js";
|
|
4
4
|
import { elementChildren, parseXml } from "../ooxml/xml.js";
|
|
5
5
|
import { abstractNumXml, listKindOf, numXml } from "./listTemplate.js";
|
|
6
|
-
function openTagAt(xml, name) {
|
|
7
|
-
const match = new RegExp(`<(?:[A-Za-z_][\\w.-]*:)?${name}[\\s/>]`).exec(xml);
|
|
8
|
-
return match ? match.index : null;
|
|
9
|
-
}
|
|
10
|
-
function closeTagAt(xml, name) {
|
|
11
|
-
const matches = Array.from(
|
|
12
|
-
xml.matchAll(new RegExp(`</(?:[A-Za-z_][\\w.-]*:)?${name}\\s*>`, "g"))
|
|
13
|
-
);
|
|
14
|
-
return matches.at(-1)?.index ?? null;
|
|
15
|
-
}
|
|
16
6
|
function maxAbstractNumId(xml) {
|
|
17
7
|
let max = 0;
|
|
18
8
|
for (const child of elementChildren(parseXml(xml).documentElement)) {
|
|
@@ -24,25 +14,24 @@ function maxAbstractNumId(xml) {
|
|
|
24
14
|
}
|
|
25
15
|
function addListDefinitions(xml, numIds) {
|
|
26
16
|
if (numIds.length === 0) return xml;
|
|
27
|
-
const rootEnd = closeTagAt(xml, "numbering");
|
|
28
|
-
if (rootEnd === null) {
|
|
29
|
-
throw new DocxExportError(
|
|
30
|
-
"malformed-xml",
|
|
31
|
-
"no closing tag found in numbering.xml"
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
const numsAt = openTagAt(xml, "numIdMacAtCleanup") ?? rootEnd;
|
|
35
|
-
const definitionsAt = openTagAt(xml, "num") ?? numsAt;
|
|
36
17
|
const firstAbstractNumId = maxAbstractNumId(xml) + 1;
|
|
37
18
|
const additions = [...numIds].sort((a, b) => a - b).map((numId, index) => ({
|
|
38
19
|
numId,
|
|
39
20
|
abstractNumId: firstAbstractNumId + index
|
|
40
21
|
}));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
22
|
+
return splicePart(xml, {
|
|
23
|
+
root: "numbering",
|
|
24
|
+
insert: [
|
|
25
|
+
...additions.map((added) => ({
|
|
26
|
+
name: "abstractNum",
|
|
27
|
+
xml: abstractNumXml(added.abstractNumId, listKindOf(added.numId))
|
|
28
|
+
})),
|
|
29
|
+
...additions.map((added) => ({
|
|
30
|
+
name: "num",
|
|
31
|
+
xml: numXml(added.numId, added.abstractNumId)
|
|
32
|
+
}))
|
|
33
|
+
]
|
|
34
|
+
});
|
|
46
35
|
}
|
|
47
36
|
export {
|
|
48
37
|
addListDefinitions
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The order the children of one element go in, per parent.
|
|
3
|
+
*
|
|
4
|
+
* A writer that swaps one child of a formatting fragment has to put a child that was not there
|
|
5
|
+
* into the spot the format lays down, and `wml.xsd` is what lays it down. Each entry below names
|
|
6
|
+
* the complex type it mirrors, and `childOrder.test.ts` reads that type out of the committed
|
|
7
|
+
* schema and compares it, so an entry cannot drift from the format it claims to follow.
|
|
8
|
+
*
|
|
9
|
+
* Where the type is a sequence the order is the schema's and nothing else. Where it is a choice
|
|
10
|
+
* the schema fixes no order among the alternatives, so the order here is this package's
|
|
11
|
+
* convention: the schema's own document order. Mutually exclusive alternatives (a content
|
|
12
|
+
* control's type, a cell's markup record) are listed in that same order, since only one of them
|
|
13
|
+
* can ever stand there.
|
|
14
|
+
*
|
|
15
|
+
* A name is the local part alone, as `Props` carries it, which is also how the two children
|
|
16
|
+
* `w:settings` takes from other namespaces (`m:mathPr`, `sl:schemaLibrary`) are spelled here.
|
|
17
|
+
*/
|
|
18
|
+
interface ChildOrder {
|
|
19
|
+
readonly type: string;
|
|
20
|
+
readonly order: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
export declare const CHILD_ORDER: Readonly<Record<string, ChildOrder>>;
|
|
23
|
+
/**
|
|
24
|
+
* The order the children of this parent go in.
|
|
25
|
+
*
|
|
26
|
+
* A nested parent is asked for first (`pPr/rPr` is CT_ParaRPr, which puts a track-change record
|
|
27
|
+
* ahead of what a run's own `w:rPr` holds), so naming the enclosing element is what picks the
|
|
28
|
+
* right one of two entries for the same element name.
|
|
29
|
+
*
|
|
30
|
+
* Throws for a parent no entry covers, because a writer editing an element this registry has
|
|
31
|
+
* never seen would otherwise place its children by nothing at all.
|
|
32
|
+
*/
|
|
33
|
+
export declare function childOrderOf(name: string, parent?: string): readonly string[];
|
|
34
|
+
export {};
|