@docx4j/core-ts 0.1.0 → 0.1.2
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/README.md +410 -10
- package/dist/model/content/Body.d.mts +109 -4
- package/dist/model/content/Body.mjs +300 -29
- package/dist/model/content/Comment.d.mts +78 -0
- package/dist/model/content/Comment.mjs +429 -0
- package/dist/model/content/ContentControl.d.mts +173 -0
- package/dist/model/content/ContentControl.mjs +638 -0
- package/dist/model/content/Font.d.mts +48 -8
- package/dist/model/content/Font.mjs +55 -13
- package/dist/model/content/InlinePicture.d.mts +103 -0
- package/dist/model/content/InlinePicture.mjs +361 -0
- package/dist/model/content/List.d.mts +253 -0
- package/dist/model/content/List.mjs +778 -0
- package/dist/model/content/Paragraph.d.mts +213 -16
- package/dist/model/content/Paragraph.mjs +611 -57
- package/dist/model/content/Range.d.mts +48 -4
- package/dist/model/content/Range.mjs +161 -4
- package/dist/model/content/Table.d.mts +130 -0
- package/dist/model/content/Table.mjs +429 -0
- package/dist/model/content/TrackedChange.d.mts +96 -0
- package/dist/model/content/TrackedChange.mjs +352 -0
- package/dist/model/content/comments.d.mts +122 -0
- package/dist/model/content/comments.mjs +248 -0
- package/dist/model/content/index.d.mts +13 -3
- package/dist/model/content/index.mjs +15 -3
- package/dist/model/content/ooxml.d.mts +17 -0
- package/dist/model/content/ooxml.mjs +214 -0
- package/dist/model/content/styles.d.mts +21 -0
- package/dist/model/content/styles.mjs +86 -0
- package/dist/model/content/tracking.d.mts +104 -0
- package/dist/model/content/tracking.mjs +313 -0
- package/dist/model/content/tree.d.mts +56 -9
- package/dist/model/content/tree.mjs +104 -31
- package/dist/model/customxml/CustomXmlPart.d.mts +158 -0
- package/dist/model/customxml/CustomXmlPart.mjs +415 -0
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +68 -0
- package/dist/model/customxml/CustomXmlPartCollection.mjs +183 -0
- package/dist/model/customxml/XmlMapping.d.mts +46 -0
- package/dist/model/customxml/XmlMapping.mjs +98 -0
- package/dist/model/customxml/bindings.d.mts +41 -0
- package/dist/model/customxml/bindings.mjs +230 -0
- package/dist/model/customxml/index.d.mts +7 -0
- package/dist/model/customxml/index.mjs +9 -0
- package/dist/model/customxml/insert.d.mts +20 -0
- package/dist/model/customxml/insert.mjs +22 -0
- package/dist/model/customxml/kinds.d.mts +103 -0
- package/dist/model/customxml/kinds.mjs +267 -0
- package/dist/model/customxml/xpath.d.mts +52 -0
- package/dist/model/customxml/xpath.mjs +205 -0
- package/dist/model/fonts/CJKToEnglish.d.mts +2 -0
- package/dist/model/fonts/CJKToEnglish.mjs +16 -0
- package/dist/model/fonts/FontFallback.d.mts +58 -0
- package/dist/model/fonts/FontFallback.mjs +219 -0
- package/dist/model/fonts/IdentityPlusMapper.d.mts +7 -0
- package/dist/model/fonts/IdentityPlusMapper.mjs +19 -0
- package/dist/model/fonts/LanguageTagToScriptMapping.d.mts +7 -0
- package/dist/model/fonts/LanguageTagToScriptMapping.mjs +67 -0
- package/dist/model/fonts/Mapper.d.mts +190 -0
- package/dist/model/fonts/Mapper.mjs +481 -0
- package/dist/model/fonts/PhysicalFont.d.mts +34 -0
- package/dist/model/fonts/PhysicalFont.mjs +62 -0
- package/dist/model/fonts/RunFontSelector.d.mts +194 -0
- package/dist/model/fonts/RunFontSelector.mjs +441 -0
- package/dist/model/fonts/ThemeFonts.d.mts +17 -0
- package/dist/model/fonts/ThemeFonts.mjs +76 -0
- package/dist/model/fonts/defaultTheme.d.mts +37 -0
- package/dist/model/fonts/defaultTheme.mjs +57 -0
- package/dist/model/fonts/families.generated.d.mts +11 -0
- package/dist/model/fonts/families.generated.mjs +17 -0
- package/dist/model/fonts/fontsInUse.d.mts +39 -0
- package/dist/model/fonts/fontsInUse.mjs +183 -0
- package/dist/model/fonts/index.d.mts +14 -0
- package/dist/model/fonts/index.mjs +29 -0
- package/dist/model/fonts/lookup.d.mts +5 -0
- package/dist/model/fonts/lookup.mjs +12 -0
- package/dist/model/fonts/registry.d.mts +31 -0
- package/dist/model/fonts/registry.mjs +103 -0
- package/dist/model/fonts/scripts.d.mts +2 -0
- package/dist/model/fonts/scripts.mjs +78 -0
- package/dist/model/fonts/substitutions.generated.d.mts +30 -0
- package/dist/model/fonts/substitutions.generated.mjs +12 -0
- package/dist/model/fonts/themes.generated.d.mts +6 -0
- package/dist/model/fonts/themes.generated.mjs +11 -0
- package/dist/model/index.d.mts +5 -0
- package/dist/model/index.mjs +13 -1
- package/dist/model/listnumbering/Emulator.d.mts +187 -0
- package/dist/model/listnumbering/Emulator.mjs +332 -0
- package/dist/model/listnumbering/definitions.d.mts +251 -0
- package/dist/model/listnumbering/definitions.mjs +571 -0
- package/dist/model/listnumbering/formats.d.mts +25 -0
- package/dist/model/listnumbering/formats.mjs +320 -0
- package/dist/model/listnumbering/index.d.mts +4 -0
- package/dist/model/listnumbering/index.mjs +15 -0
- package/dist/model/listnumbering/state.d.mts +97 -0
- package/dist/model/listnumbering/state.mjs +179 -0
- package/dist/model/properties/PropertyResolver.d.mts +216 -0
- package/dist/model/properties/PropertyResolver.mjs +524 -0
- package/dist/model/properties/catalogue.d.mts +179 -0
- package/dist/model/properties/catalogue.mjs +860 -0
- package/dist/model/properties/index.d.mts +4 -0
- package/dist/model/properties/index.mjs +9 -0
- package/dist/model/properties/log.d.mts +7 -0
- package/dist/model/properties/log.mjs +25 -0
- package/dist/model/properties/styleUtil.d.mts +112 -0
- package/dist/model/properties/styleUtil.mjs +359 -0
- package/dist/node/index.d.mts +1 -0
- package/dist/node/index.mjs +12 -0
- package/dist/office-js/document.d.mts +111 -0
- package/dist/office-js/document.mjs +267 -0
- package/dist/office-js/enums.d.mts +187 -0
- package/dist/office-js/enums.mjs +176 -0
- package/dist/office-js/errors.d.mts +29 -0
- package/dist/office-js/errors.mjs +39 -0
- package/dist/office-js/extras.d.mts +5 -0
- package/dist/office-js/extras.mjs +29 -0
- package/dist/office-js/fragment.d.mts +10 -0
- package/dist/office-js/fragment.mjs +23 -0
- package/dist/office-js/index.d.mts +183 -0
- package/dist/office-js/index.mjs +54 -0
- package/dist/office-js/proxy.d.mts +72 -0
- package/dist/office-js/proxy.mjs +279 -0
- package/dist/office-js/run.d.mts +32 -0
- package/dist/office-js/run.mjs +66 -0
- package/dist/office-js/supported.d.mts +7 -0
- package/dist/office-js/supported.generated.d.mts +1 -0
- package/dist/office-js/supported.generated.mjs +235 -0
- package/dist/office-js/supported.mjs +53 -0
- package/dist/office-js/toApiScript.d.mts +25 -0
- package/dist/office-js/toApiScript.mjs +394 -0
- package/dist/opc/ContentTypes.d.mts +11 -0
- package/dist/opc/ContentTypes.mjs +14 -0
- package/dist/opc/DirectoryPartStore.d.mts +47 -0
- package/dist/opc/DirectoryPartStore.mjs +123 -0
- package/dist/opc/exceptions.d.mts +30 -0
- package/dist/opc/exceptions.mjs +38 -0
- package/dist/opc/index.d.mts +1 -1
- package/dist/opc/index.mjs +1 -1
- package/dist/packages/OpcPackage.d.mts +19 -1
- package/dist/packages/OpcPackage.mjs +29 -0
- package/dist/packages/PresentationMLPackage.d.mts +71 -1
- package/dist/packages/PresentationMLPackage.mjs +179 -0
- package/dist/packages/SpreadsheetMLPackage.d.mts +30 -1
- package/dist/packages/SpreadsheetMLPackage.mjs +78 -0
- package/dist/packages/WordprocessingMLPackage.d.mts +124 -2
- package/dist/packages/WordprocessingMLPackage.mjs +309 -2
- package/dist/packages/index.d.mts +1 -1
- package/dist/packages/index.mjs +1 -1
- package/dist/parts/DefaultXmlPart.d.mts +18 -0
- package/dist/parts/DefaultXmlPart.mjs +34 -5
- package/dist/parts/Namespaces.d.mts +18 -0
- package/dist/parts/Namespaces.mjs +20 -0
- package/dist/parts/Part.d.mts +6 -0
- package/dist/parts/Part.mjs +13 -0
- package/dist/parts/PartRegistry.mjs +13 -1
- package/dist/parts/XmlPart.d.mts +33 -0
- package/dist/parts/XmlPart.mjs +105 -2
- package/dist/parts/pml/defaults.d.mts +6 -0
- package/dist/parts/pml/defaults.mjs +53 -0
- package/dist/parts/pml/index.d.mts +66 -3
- package/dist/parts/pml/index.mjs +206 -7
- package/dist/parts/pml/placeholders.d.mts +71 -0
- package/dist/parts/pml/placeholders.mjs +141 -0
- package/dist/parts/sml/index.d.mts +80 -1
- package/dist/parts/sml/index.mjs +154 -1
- package/dist/parts/wml/comments.d.mts +1 -0
- package/dist/parts/wml/comments.mjs +179 -0
- package/dist/parts/wml/defaultNumbering.d.mts +1 -0
- package/dist/parts/wml/defaultNumbering.mjs +216 -0
- package/dist/parts/wml/index.d.mts +121 -0
- package/dist/parts/wml/index.mjs +291 -0
- package/dist/xml/dom.mjs +1 -2
- package/package.json +25 -4
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import { isElement, typeNameOf } from '@docx4j/generated-objects-ts/builders/wml';
|
|
1
|
+
import { isElement, typeNameOf, runItemsOf } from '@docx4j/generated-objects-ts/builders/wml';
|
|
2
2
|
export { isElement, typeNameOf, walk, find, linkParents, textOf, W_NS } from '@docx4j/generated-objects-ts/builders/wml';
|
|
3
|
-
/** Types whose value holds runs (directly or through sdtContent);
|
|
3
|
+
/** Types whose value holds runs (directly or through sdtContent); the revision holders are separate. */
|
|
4
4
|
const RUN_HOLDERS = new Set([
|
|
5
|
-
'org_docx4j_wml.P.Hyperlink', 'org_docx4j_wml.SdtRun', 'org_docx4j_wml.
|
|
5
|
+
'org_docx4j_wml.P.Hyperlink', 'org_docx4j_wml.SdtRun', 'org_docx4j_wml.CTSmartTagRun',
|
|
6
6
|
'org_docx4j_wml.CTCustomXmlRun', 'org_docx4j_wml.P.Dir', 'org_docx4j_wml.P.Bdo', 'org_docx4j_wml.CTSimpleField',
|
|
7
|
-
'org_docx4j_wml.
|
|
7
|
+
'org_docx4j_wml.CTSdtContentRun',
|
|
8
8
|
]);
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return undefined;
|
|
9
|
+
/** w:ins, w:del and the two w:move forms (w:moveFrom and w:moveTo share docx4j's RunTrackChange). */
|
|
10
|
+
const REVISION_HOLDERS = new Set(['org_docx4j_wml.RunIns', 'org_docx4j_wml.RunDel', 'org_docx4j_wml.RunTrackChange']);
|
|
11
|
+
/** The kind of a run-level revision element, by its name; undefined when it is not one. */
|
|
12
|
+
export function revisionKindOf(el) {
|
|
13
|
+
var _a;
|
|
14
|
+
if (!REVISION_HOLDERS.has((_a = typeNameOf(el)) !== null && _a !== void 0 ? _a : ''))
|
|
15
|
+
return undefined;
|
|
16
|
+
const name = el.name.localPart;
|
|
17
|
+
return name === 'ins' || name === 'del' || name === 'moveFrom' || name === 'moveTo' ? name : undefined;
|
|
18
|
+
}
|
|
19
|
+
/** True when this view shows the runs of a revision of that kind. */
|
|
20
|
+
function shows(view, kind) {
|
|
21
|
+
return view === 'accepted' ? kind === 'ins' || kind === 'moveTo' : kind === 'del' || kind === 'moveFrom';
|
|
23
22
|
}
|
|
23
|
+
export { runItemsOf };
|
|
24
24
|
function itemText(item) {
|
|
25
25
|
var _a, _b;
|
|
26
26
|
const t = item.name.localPart;
|
|
27
27
|
const v = item.value;
|
|
28
28
|
switch (t) {
|
|
29
|
-
case 't':
|
|
29
|
+
case 't':
|
|
30
|
+
case 'delText': return String((_a = v.value) !== null && _a !== void 0 ? _a : '');
|
|
30
31
|
case 'tab': return '\t';
|
|
31
32
|
case 'br': return '\n';
|
|
32
33
|
case 'cr': return '\n';
|
|
@@ -39,11 +40,17 @@ function itemText(item) {
|
|
|
39
40
|
default: return undefined;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
/**
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* The text segments of a paragraph (or any run holder) in order. The default view is the
|
|
45
|
+
* accepted one: the runs of a `w:ins` or `w:moveTo` count, those of a `w:del` or `w:moveFrom`
|
|
46
|
+
* do not. `{ view: 'original' }` is the other way round (CR-002 phase F).
|
|
47
|
+
*/
|
|
48
|
+
export function segmentsOf(container, options) {
|
|
49
|
+
var _a;
|
|
50
|
+
const view = (_a = options === null || options === void 0 ? void 0 : options.view) !== null && _a !== void 0 ? _a : 'accepted';
|
|
44
51
|
const out = [];
|
|
45
52
|
let pos = 0;
|
|
46
|
-
const visitRuns = (items) => {
|
|
53
|
+
const visitRuns = (items, revision) => {
|
|
47
54
|
var _a;
|
|
48
55
|
if (!items)
|
|
49
56
|
return;
|
|
@@ -58,28 +65,56 @@ export function segmentsOf(container) {
|
|
|
58
65
|
const text = itemText(item);
|
|
59
66
|
if (text === undefined)
|
|
60
67
|
continue;
|
|
61
|
-
|
|
68
|
+
const seg = {
|
|
69
|
+
item, owner: content, index: j, run, runOwner: items, runIndex: i, text,
|
|
70
|
+
start: pos, end: pos + text.length, editable: item.name.localPart === 't',
|
|
71
|
+
};
|
|
72
|
+
if (revision)
|
|
73
|
+
seg.revision = revision;
|
|
74
|
+
out.push(seg);
|
|
62
75
|
pos += text.length;
|
|
63
76
|
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const kind = revisionKindOf(el);
|
|
80
|
+
if (kind !== undefined) {
|
|
81
|
+
if (!shows(view, kind))
|
|
82
|
+
continue;
|
|
83
|
+
const nested = runItemsOf(el.value);
|
|
84
|
+
if (nested)
|
|
85
|
+
visitRuns(nested, { kind, element: el, value: el.value, items: nested, owner: items });
|
|
64
86
|
}
|
|
65
87
|
else if (tn !== undefined && RUN_HOLDERS.has(tn)) {
|
|
66
|
-
visitRuns(runItemsOf(el.value));
|
|
88
|
+
visitRuns(runItemsOf(el.value), revision);
|
|
67
89
|
}
|
|
68
90
|
}
|
|
69
91
|
};
|
|
70
|
-
visitRuns(runItemsOf(container));
|
|
92
|
+
visitRuns(runItemsOf(container), undefined);
|
|
71
93
|
return out;
|
|
72
94
|
}
|
|
95
|
+
/** The text of a paragraph or container in one of the two views (`textOf` is the accepted one). */
|
|
96
|
+
export function textOfView(container, options) {
|
|
97
|
+
return segmentsOf(container, options).map((s) => s.text).join('');
|
|
98
|
+
}
|
|
73
99
|
/** The runs of a paragraph, direct and nested in hyperlinks, content controls and insertions, in order. */
|
|
74
|
-
export function runsOf(container) {
|
|
100
|
+
export function runsOf(container, options) {
|
|
101
|
+
var _a;
|
|
102
|
+
const view = (_a = options === null || options === void 0 ? void 0 : options.view) !== null && _a !== void 0 ? _a : 'accepted';
|
|
75
103
|
const out = [];
|
|
76
104
|
const visit = (items) => {
|
|
77
105
|
if (!items)
|
|
78
106
|
return;
|
|
79
107
|
for (const el of items) {
|
|
80
108
|
const tn = typeNameOf(el);
|
|
81
|
-
if (tn === 'org_docx4j_wml.R')
|
|
109
|
+
if (tn === 'org_docx4j_wml.R') {
|
|
82
110
|
out.push(el);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const kind = revisionKindOf(el);
|
|
114
|
+
if (kind !== undefined) {
|
|
115
|
+
if (shows(view, kind))
|
|
116
|
+
visit(runItemsOf(el.value));
|
|
117
|
+
}
|
|
83
118
|
else if (tn !== undefined && RUN_HOLDERS.has(tn))
|
|
84
119
|
visit(runItemsOf(el.value));
|
|
85
120
|
}
|
|
@@ -87,14 +122,49 @@ export function runsOf(container) {
|
|
|
87
122
|
visit(runItemsOf(container));
|
|
88
123
|
return out;
|
|
89
124
|
}
|
|
90
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* The block-level children of a container: body, header, footer, cell, sdt content, table (rows),
|
|
127
|
+
* row (cells). A content control of any kind (block, row, cell, run) answers with its
|
|
128
|
+
* `sdtContent`'s content, so that a traversal does not have to know the four types.
|
|
129
|
+
*/
|
|
91
130
|
export function childrenOf(value) {
|
|
92
|
-
var _a;
|
|
93
131
|
const v = value;
|
|
94
|
-
if (v.
|
|
95
|
-
return
|
|
132
|
+
if (v.sdtContent)
|
|
133
|
+
return v.sdtContent.content;
|
|
96
134
|
return Array.isArray(v.content) ? v.content : undefined;
|
|
97
135
|
}
|
|
136
|
+
/** w:sdt and w:customXml at row level: they hold the rows of a table (docx4j CTSdtRow, CTCustomXmlRow). */
|
|
137
|
+
const ROW_HOLDERS = new Set(['org_docx4j_wml.CTSdtRow', 'org_docx4j_wml.CTCustomXmlRow']);
|
|
138
|
+
/** The same at cell level. */
|
|
139
|
+
const CELL_HOLDERS = new Set(['org_docx4j_wml.CTSdtCell', 'org_docx4j_wml.CTCustomXmlCell']);
|
|
140
|
+
/** The rows of a table, in order, descending into row-level content controls (an OpenDoPE repeat). */
|
|
141
|
+
export function rowsOf(tbl) {
|
|
142
|
+
return located(childrenOf(tbl), 'org_docx4j_wml.Tr', ROW_HOLDERS);
|
|
143
|
+
}
|
|
144
|
+
/** The cells of a row, in order, descending into cell-level content controls. */
|
|
145
|
+
export function cellsOf(tr) {
|
|
146
|
+
return located(childrenOf(tr), 'org_docx4j_wml.Tc', CELL_HOLDERS);
|
|
147
|
+
}
|
|
148
|
+
function located(items, typeName, holders) {
|
|
149
|
+
const out = [];
|
|
150
|
+
const visit = (list) => {
|
|
151
|
+
if (!list)
|
|
152
|
+
return;
|
|
153
|
+
for (const element of list) {
|
|
154
|
+
const tn = typeNameOf(element);
|
|
155
|
+
if (tn === typeName)
|
|
156
|
+
out.push({ element, container: list });
|
|
157
|
+
else if (tn !== undefined && holders.has(tn) && typeof element.value === 'object' && element.value !== null)
|
|
158
|
+
visit(childrenOf(element.value));
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
visit(items);
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
/** Content controls: `w:sdt` at block, row, cell and run level, by TYPE_NAME. */
|
|
165
|
+
export const SDT_TYPES = new Set([
|
|
166
|
+
'org_docx4j_wml.SdtBlock', 'org_docx4j_wml.SdtRun', 'org_docx4j_wml.CTSdtRow', 'org_docx4j_wml.CTSdtCell',
|
|
167
|
+
]);
|
|
98
168
|
/** True for what a body or cell may hold directly (the Body content union), by TYPE_NAME. */
|
|
99
169
|
export const BLOCK_LEVEL_TYPES = new Set([
|
|
100
170
|
'org_docx4j_wml.P', 'org_docx4j_wml.Tbl', 'org_docx4j_wml.SdtBlock', 'org_docx4j_wml.CTCustomXmlBlock', 'org_docx4j_wml.CTAltChunk',
|
|
@@ -118,3 +188,6 @@ export function paragraphOf(runs, pPr) {
|
|
|
118
188
|
return { name: { namespaceURI: 'http://schemas.openxmlformats.org/wordprocessingml/2006/main', localPart: 'p' }, value };
|
|
119
189
|
}
|
|
120
190
|
export { isElement as isTypedElement };
|
|
191
|
+
// CR-002 phase G (comments) needs the two internals above: the run holders to walk to the
|
|
192
|
+
// markers inside hyperlinks and insertions, and the per-item text to give a marker its offset.
|
|
193
|
+
export { RUN_HOLDERS, itemText as itemTextOf };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { CustomXmlDataStoragePart } from '../../parts/DefaultXmlPart.mjs';
|
|
2
|
+
import { type XPathEngine, parsePrefixMappings, formatPrefixMappings } from './xpath.mjs';
|
|
3
|
+
/** Office JS `Word.CustomXmlNodeType`, in the CR's spelling. */
|
|
4
|
+
export type CustomXmlNodeType = 'Element' | 'Attribute' | 'Text' | 'CData' | 'ProcessingInstruction' | 'Comment' | 'Document' | 'Other';
|
|
5
|
+
/** One prefix mapping of a part's namespace manager. */
|
|
6
|
+
export interface CustomXmlPrefixMapping {
|
|
7
|
+
prefix: string;
|
|
8
|
+
namespaceUri: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Office JS `Word.CustomXmlPrefixMappingCollection`: the prefixes an XPath over this part may use.
|
|
12
|
+
* Seeded from the namespace declarations of the document element, so that a part Word wrote can be
|
|
13
|
+
* queried without declaring anything.
|
|
14
|
+
*/
|
|
15
|
+
export declare class CustomXmlPrefixMappingCollection {
|
|
16
|
+
private readonly map;
|
|
17
|
+
constructor(seed?: Record<string, string>);
|
|
18
|
+
get items(): CustomXmlPrefixMapping[];
|
|
19
|
+
addNamespace(prefix: string, namespaceUri: string): void;
|
|
20
|
+
/** The URI a prefix stands for, '' when it stands for none (Office JS lookupNamespace). */
|
|
21
|
+
lookupNamespace(prefix: string): string;
|
|
22
|
+
/** The first prefix bound to a URI, '' when none is (Office JS lookupPrefix). */
|
|
23
|
+
lookupPrefix(namespaceUri: string): string;
|
|
24
|
+
/** The mappings as an `xmlns:ns0='...'` string and as a map, for the engine. */
|
|
25
|
+
toMap(): Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
/** What a part view needs of its collection: the engine, and the removal of a part. */
|
|
28
|
+
export interface CustomXmlPartOwner {
|
|
29
|
+
readonly xpathEngine: XPathEngine;
|
|
30
|
+
removePart(part: CustomXmlPart): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A subset of Office JS `Word.CustomXmlPart` over a `CustomXmlDataStoragePart` (the customer's XML,
|
|
34
|
+
* a DOM) and its properties part (the `ds:datastoreItem` with the itemID and the schema
|
|
35
|
+
* references). The properties part is read from its DOM, never unmarshalled, so it stays byte for
|
|
36
|
+
* byte (as `Load` does for the itemID).
|
|
37
|
+
*/
|
|
38
|
+
export declare class CustomXmlPart {
|
|
39
|
+
/** The data part (extension: docx4j's part is the object here). */
|
|
40
|
+
readonly part: CustomXmlDataStoragePart;
|
|
41
|
+
private readonly owner;
|
|
42
|
+
/** The itemID as the properties part spells it, '{...}'. */
|
|
43
|
+
readonly itemID: string;
|
|
44
|
+
/** The `ds:schemaRef` URIs of the properties part. */
|
|
45
|
+
private readonly schemaRefs;
|
|
46
|
+
private prefixes;
|
|
47
|
+
constructor(
|
|
48
|
+
/** The data part (extension: docx4j's part is the object here). */
|
|
49
|
+
part: CustomXmlDataStoragePart, owner: CustomXmlPartOwner,
|
|
50
|
+
/** The itemID as the properties part spells it, '{...}'. */
|
|
51
|
+
itemID: string,
|
|
52
|
+
/** The `ds:schemaRef` URIs of the properties part. */
|
|
53
|
+
schemaRefs?: string[]);
|
|
54
|
+
/** The itemID, as Office JS reports it ('{...}'). */
|
|
55
|
+
get id(): string;
|
|
56
|
+
/** The DOM; throws when the part has not been parsed yet (`await pkg.customXmlParts.load()`). */
|
|
57
|
+
get document(): Document;
|
|
58
|
+
/** The document element as a node view. */
|
|
59
|
+
get documentElement(): CustomXmlNode;
|
|
60
|
+
/** The namespace of the document element ('' when it is in none). */
|
|
61
|
+
get namespaceUri(): string;
|
|
62
|
+
/** True for Word's own property stores (core, extended, custom and cover-page properties). */
|
|
63
|
+
get builtIn(): boolean;
|
|
64
|
+
/** The prefixes an XPath over this part may use; seeded from the document element's declarations. */
|
|
65
|
+
get namespaceManager(): CustomXmlPrefixMappingCollection;
|
|
66
|
+
/** The `ds:schemaRef` URIs of the properties part (Office JS schemaCollection). */
|
|
67
|
+
get schemaCollection(): string[];
|
|
68
|
+
/** The part's XML. Synchronous: a DOM part does not go through the marshaller. */
|
|
69
|
+
getXml(): string;
|
|
70
|
+
/** Replaces the part's XML; the part is re-marshalled on save. */
|
|
71
|
+
setXml(xml: string): void;
|
|
72
|
+
/** The nodes an XPath selects; `namespaceMappings` is Word's `xmlns:ns0='...'` string, else the namespace manager's. */
|
|
73
|
+
selectNodes(xpath: string, namespaceMappings?: string): CustomXmlNode[];
|
|
74
|
+
selectSingleNode(xpath: string, namespaceMappings?: string): CustomXmlNode | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Inserts `xml` as a child of the node the XPath selects, at `index` (appended when omitted).
|
|
77
|
+
* Departure from Office JS, which puts `namespaceMappings` second: here it is last and optional,
|
|
78
|
+
* as CR-002 section 3.5 specifies (section 12).
|
|
79
|
+
*/
|
|
80
|
+
insertElement(xpath: string, xml: string, namespaceMappings?: string, index?: number): CustomXmlNode;
|
|
81
|
+
/** Replaces the element the XPath selects with `xml`. */
|
|
82
|
+
updateElement(xpath: string, xml: string, namespaceMappings?: string): void;
|
|
83
|
+
/** Removes the element the XPath selects. */
|
|
84
|
+
deleteElement(xpath: string, namespaceMappings?: string): void;
|
|
85
|
+
/** Adds an attribute to the element the XPath selects. */
|
|
86
|
+
insertAttribute(xpath: string, name: string, value: string, namespaceMappings?: string): void;
|
|
87
|
+
/** Sets an attribute of the element the XPath selects (`prefix:name` is written in that prefix's namespace). */
|
|
88
|
+
updateAttribute(xpath: string, name: string, value: string, namespaceMappings?: string): void;
|
|
89
|
+
/** Removes an attribute of the element the XPath selects. */
|
|
90
|
+
deleteAttribute(xpath: string, name: string, namespaceMappings?: string): void;
|
|
91
|
+
/** Removes the part, its properties part and the relationships; bound controls lose their mapping. */
|
|
92
|
+
delete(): void;
|
|
93
|
+
/** Marks the part for re-marshalling: a DOM read for a query alone leaves it byte for byte. */
|
|
94
|
+
touch(): void;
|
|
95
|
+
get engine(): XPathEngine;
|
|
96
|
+
/** The prefix map to use: the given string, else the namespace manager's. */
|
|
97
|
+
mappingsFor(namespaceMappings: string | undefined): Record<string, string>;
|
|
98
|
+
selectFrom(context: Node, xpath: string, namespaceMappings?: string): CustomXmlNode[];
|
|
99
|
+
private requireNode;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A subset of Office JS `Word.CustomXmlNode`: a view over one DOM node of a custom XML part.
|
|
103
|
+
* `xpath` is the canonical `/ns0:a[1]/ns0:b[2]` form Word writes, which is what
|
|
104
|
+
* `XmlMapping.setMappingByNode` stores.
|
|
105
|
+
*/
|
|
106
|
+
export declare class CustomXmlNode {
|
|
107
|
+
/** The DOM node (extension). */
|
|
108
|
+
readonly node: Node;
|
|
109
|
+
/** The part the node belongs to. */
|
|
110
|
+
readonly ownerPart: CustomXmlPart;
|
|
111
|
+
constructor(
|
|
112
|
+
/** The DOM node (extension). */
|
|
113
|
+
node: Node,
|
|
114
|
+
/** The part the node belongs to. */
|
|
115
|
+
ownerPart: CustomXmlPart);
|
|
116
|
+
/** The local name; for an attribute, its name. */
|
|
117
|
+
get baseName(): string;
|
|
118
|
+
get namespaceUri(): string;
|
|
119
|
+
get nodeType(): CustomXmlNodeType;
|
|
120
|
+
/** The node's value: an attribute's value, a text node's data, an element's text. */
|
|
121
|
+
get nodeValue(): string;
|
|
122
|
+
set nodeValue(value: string);
|
|
123
|
+
/** The node's text content; setting replaces an element's children with one text node. */
|
|
124
|
+
get text(): string;
|
|
125
|
+
set text(value: string);
|
|
126
|
+
/** The node's XML. */
|
|
127
|
+
get xml(): string;
|
|
128
|
+
/** The canonical XPath of this node, as Word writes it into `w:dataBinding`. */
|
|
129
|
+
get xpath(): string;
|
|
130
|
+
/** The prefix mappings that XPath needs (empty when the node is in no namespace). */
|
|
131
|
+
get prefixMappings(): string;
|
|
132
|
+
get attributes(): CustomXmlNode[];
|
|
133
|
+
get childNodes(): CustomXmlNode[];
|
|
134
|
+
/** The element children only (extension: what a reader of a data store usually wants). */
|
|
135
|
+
get childElements(): CustomXmlNode[];
|
|
136
|
+
get parentNode(): CustomXmlNode | undefined;
|
|
137
|
+
get firstChild(): CustomXmlNode | undefined;
|
|
138
|
+
get lastChild(): CustomXmlNode | undefined;
|
|
139
|
+
get nextSibling(): CustomXmlNode | undefined;
|
|
140
|
+
get previousSibling(): CustomXmlNode | undefined;
|
|
141
|
+
hasChildNodes(): boolean;
|
|
142
|
+
selectNodes(xpath: string, namespaceMappings?: string): CustomXmlNode[];
|
|
143
|
+
selectSingleNode(xpath: string, namespaceMappings?: string): CustomXmlNode | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* Appends a child. Both forms of CR-002 open question 8 are taken: the XML text form
|
|
146
|
+
* `appendChildNode('<price>$20</price>')`, which is what an agent produces, and Office JS's
|
|
147
|
+
* `appendChildNode(name, namespaceUri, nodeType, nodeValue)`.
|
|
148
|
+
*/
|
|
149
|
+
appendChildNode(xml?: string, namespaceUri?: string, nodeType?: CustomXmlNodeType, nodeValue?: string, index?: number): CustomXmlNode;
|
|
150
|
+
/** Inserts a node before a sibling (appended when the sibling is omitted), as Office JS. */
|
|
151
|
+
insertNodeBefore(xml: string, nextSibling?: CustomXmlNode): CustomXmlNode;
|
|
152
|
+
removeChild(child: CustomXmlNode): void;
|
|
153
|
+
replaceChildNode(oldNode: CustomXmlNode, xml: string): CustomXmlNode;
|
|
154
|
+
/** Removes this node from its parent. */
|
|
155
|
+
delete(): void;
|
|
156
|
+
private create;
|
|
157
|
+
}
|
|
158
|
+
export { formatPrefixMappings, parsePrefixMappings };
|