@docx4j/core-ts 0.1.5 → 0.2.1
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 +81 -0
- package/dist/model/content/Body.d.mts +36 -2
- package/dist/model/content/Body.mjs +79 -4
- package/dist/model/content/Comment.d.mts +15 -5
- package/dist/model/content/Comment.mjs +70 -22
- package/dist/model/content/List.d.mts +13 -2
- package/dist/model/content/List.mjs +48 -9
- package/dist/model/content/Paragraph.d.mts +11 -1
- package/dist/model/content/Paragraph.mjs +37 -21
- package/dist/model/content/Range.d.mts +36 -5
- package/dist/model/content/Range.mjs +97 -26
- package/dist/model/content/binder.d.mts +44 -0
- package/dist/model/content/binder.mjs +128 -0
- package/dist/model/content/comments.d.mts +19 -1
- package/dist/model/content/index.d.mts +5 -3
- package/dist/model/content/index.mjs +3 -1
- package/dist/model/content/search.d.mts +27 -2
- package/dist/model/content/search.mjs +59 -3
- package/dist/model/content/stylesFacade.d.mts +37 -0
- package/dist/model/content/stylesFacade.mjs +114 -0
- package/dist/model/content/tracking.d.mts +57 -2
- package/dist/model/content/tracking.mjs +47 -15
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +7 -0
- package/dist/model/customxml/CustomXmlPartCollection.mjs +40 -6
- package/dist/model/customxml/xpath.d.mts +18 -3
- package/dist/model/customxml/xpath.mjs +18 -3
- package/dist/office-js/index.d.mts +3 -1
- package/dist/office-js/run.d.mts +12 -2
- package/dist/office-js/run.mjs +8 -1
- package/dist/office-js/shimmed.d.mts +46 -0
- package/dist/office-js/shimmed.mjs +1 -0
- package/dist/opc/exceptions.d.mts +25 -0
- package/dist/opc/exceptions.mjs +20 -0
- package/dist/opc/index.d.mts +1 -1
- package/dist/opc/index.mjs +1 -1
- package/dist/opc/mce/understood.mjs +37 -8
- package/dist/packages/WordprocessingMLPackage.d.mts +105 -3
- package/dist/packages/WordprocessingMLPackage.mjs +165 -2
- package/dist/parts/XmlPart.d.mts +44 -0
- package/dist/parts/XmlPart.mjs +86 -3
- package/dist/parts/sml/index.d.mts +9 -8
- package/dist/parts/sml/index.mjs +23 -19
- package/dist/parts/wml/index.d.mts +10 -2
- package/dist/parts/wml/index.mjs +11 -3
- package/dist/parts/wml/spliceableStyles.d.mts +1 -0
- package/dist/parts/wml/spliceableStyles.mjs +122 -0
- package/dist/xml/dom.d.mts +10 -1
- package/dist/xml/dom.mjs +46 -2
- package/package.json +2 -2
package/dist/office-js/run.d.mts
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import type { WordprocessingMLPackage } from '../packages/WordprocessingMLPackage.mjs';
|
|
2
2
|
import { Document, type RunOptions } from './document.mjs';
|
|
3
3
|
import { type PendingSink } from './proxy.mjs';
|
|
4
|
+
import type { Shimmed } from './shimmed.mjs';
|
|
4
5
|
export type { RunOptions };
|
|
6
|
+
/** The `Document` as the shim presents it (CR-002 section 22.1): `context.document`'s type. */
|
|
7
|
+
export type ShimmedDocument = Shimmed<Document>;
|
|
5
8
|
/** Office JS's `context.trackedObjects`: object lifetime is the garbage collector's business here. */
|
|
6
9
|
export interface TrackedObjects {
|
|
7
10
|
add<T>(object: T): T;
|
|
8
11
|
remove<T>(object: T): T;
|
|
9
12
|
}
|
|
10
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* A subset of Office JS `Word.RequestContext` over a package.
|
|
15
|
+
*
|
|
16
|
+
* `document` is typed `ShimmedDocument`, which is what the proxies actually present: every array a
|
|
17
|
+
* `Collection` with `items` and `getFirst`, every object `load`able (CR-002 section 22.1). The
|
|
18
|
+
* runtime object is the same either way; the type is what lets an add-in script type-check against
|
|
19
|
+
* this package exactly as it does against Office JS.
|
|
20
|
+
*/
|
|
11
21
|
export declare class RequestContext implements PendingSink {
|
|
12
22
|
/** The package this context is over (extension: Office JS has a host document). */
|
|
13
23
|
readonly package_: WordprocessingMLPackage;
|
|
14
|
-
readonly document:
|
|
24
|
+
readonly document: ShimmedDocument;
|
|
15
25
|
/** Tracking is a no-op: nothing here is a remote proxy. */
|
|
16
26
|
readonly trackedObjects: TrackedObjects;
|
|
17
27
|
private pending;
|
package/dist/office-js/run.mjs
CHANGED
|
@@ -7,7 +7,14 @@
|
|
|
7
7
|
import { Document } from './document.mjs';
|
|
8
8
|
import { EXTRA_MEMBERS } from './extras.mjs';
|
|
9
9
|
import { Wrapper, unwrap } from './proxy.mjs';
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* A subset of Office JS `Word.RequestContext` over a package.
|
|
12
|
+
*
|
|
13
|
+
* `document` is typed `ShimmedDocument`, which is what the proxies actually present: every array a
|
|
14
|
+
* `Collection` with `items` and `getFirst`, every object `load`able (CR-002 section 22.1). The
|
|
15
|
+
* runtime object is the same either way; the type is what lets an add-in script type-check against
|
|
16
|
+
* this package exactly as it does against Office JS.
|
|
17
|
+
*/
|
|
11
18
|
export class RequestContext {
|
|
12
19
|
constructor(
|
|
13
20
|
/** The package this context is over (extension: Office JS has a host document). */
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ClientResult, Collection } from './proxy.mjs';
|
|
2
|
+
/** Office JS's `load` / `track` / `untrack`, which every proxy answers and which return the object. */
|
|
3
|
+
export interface Loadable<T> {
|
|
4
|
+
/**
|
|
5
|
+
* Office JS's `load`: a no-op here, since the tree is in memory and nothing is a remote proxy
|
|
6
|
+
* (CR-002 section 3.10). Returns the object, so `body.load('text')` chains as it does in Word.
|
|
7
|
+
*/
|
|
8
|
+
load(option?: string | string[] | Record<string, unknown>): T;
|
|
9
|
+
track(): T;
|
|
10
|
+
untrack(): T;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What the shim presents for a value of type `T`:
|
|
14
|
+
*
|
|
15
|
+
* - a function becomes a function whose result is shimmed in turn (a method call on a proxy hands
|
|
16
|
+
* back another proxy), except that a promise stays a promise and a `ClientResult` stays one;
|
|
17
|
+
* - an array becomes a `Collection` of shimmed items - Office JS's `items`, `getFirst`,
|
|
18
|
+
* `getFirstOrNullObject`, `getLast`, `getLastOrNullObject` and `getCount`;
|
|
19
|
+
* - any other object becomes itself with its members shimmed, plus `load`, `track` and `untrack`;
|
|
20
|
+
* - a primitive is itself.
|
|
21
|
+
*
|
|
22
|
+
* Deliberately **not** distributive over unions of objects beyond the array case: a `Range | undefined`
|
|
23
|
+
* shims to `Shimmed<Range> | undefined`, which is what a caller wants, and the conditional's natural
|
|
24
|
+
* distribution gives that.
|
|
25
|
+
*/
|
|
26
|
+
export type Shimmed<T> = T extends ClientResult<unknown> ? T : T extends Promise<unknown> ? T : T extends (...args: infer A) => infer R ? ((...args: A) => Shimmed<R>) & Loadable<T> : T extends readonly (infer I)[] ? ShimmedCollection<I> : T extends object ? ShimmedObject<T> : T;
|
|
27
|
+
/** A collection of shimmed items, as the proxies wrap an array. */
|
|
28
|
+
export type ShimmedCollection<I> = Collection<Shimmed<I>> & Loadable<Collection<Shimmed<I>>>;
|
|
29
|
+
/**
|
|
30
|
+
* An object with every member shimmed, and Office JS's `load` / `track` / `untrack` beside them.
|
|
31
|
+
*
|
|
32
|
+
* `T &` matters and is not redundant: a mapped type keeps only the public members, so without it a
|
|
33
|
+
* shimmed `Body` is not assignable to `Body` and a consumer cannot pass `context.document.body` to
|
|
34
|
+
* its own function typed on the plain view - which is exactly what an add-in that shares one `edit`
|
|
35
|
+
* between Word and the shim does (`examples/office-addin/taskpane.ts`). Intersecting keeps that
|
|
36
|
+
* assignable while the mapped half still narrows an array member to a `Collection`.
|
|
37
|
+
*
|
|
38
|
+
* The **order** matters too, and is the subtler half: an intersection of two call signatures is an
|
|
39
|
+
* overload set, and TypeScript picks the first that matches. With `T` first, `getRange()` resolves
|
|
40
|
+
* to `T`'s own signature and hands back a plain `Range`, so `paragraph.getRange().font.load(...)`
|
|
41
|
+
* is rejected although the shim allows it. The mapped half therefore comes first, so the shimmed
|
|
42
|
+
* return type wins, and `T` follows to keep assignability.
|
|
43
|
+
*/
|
|
44
|
+
export type ShimmedObject<T> = {
|
|
45
|
+
[K in keyof T]: Shimmed<T[K]>;
|
|
46
|
+
} & T & Loadable<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -45,3 +45,28 @@ export declare class Xlsx4jException extends Docx4JException {
|
|
|
45
45
|
export declare class PartUnrecognisedException extends Docx4JException {
|
|
46
46
|
constructor(message: string);
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* An XML part that could not be unmarshalled, naming the part (CR-002 section 27, item 9 of the
|
|
50
|
+
* E4 release). The runtime's own message is specific about *what* is wrong and, since
|
|
51
|
+
* `@docx4j/jsonix` 3.4.0, *where* - `w:sz/@w:val (line 12): Argument [NaN] must be an integer` -
|
|
52
|
+
* but it cannot know which part it was reading, and a person editing a part's XML in an editor needs
|
|
53
|
+
* that first. The location fields are lifted off the runtime's error so a caller does not have to
|
|
54
|
+
* parse the message.
|
|
55
|
+
*/
|
|
56
|
+
export declare class PartUnmarshalException extends Docx4JException {
|
|
57
|
+
/** The part being unmarshalled: `/word/styles.xml`. */
|
|
58
|
+
readonly partName: string;
|
|
59
|
+
constructor(message: string,
|
|
60
|
+
/** The part being unmarshalled: `/word/styles.xml`. */
|
|
61
|
+
partName: string, options?: {
|
|
62
|
+
cause?: unknown;
|
|
63
|
+
/** The element or attribute the runtime was on, when it said. */
|
|
64
|
+
location?: string | undefined;
|
|
65
|
+
/** Its line in the source, when the parser supplied one (Node only: xmldom's locator). */
|
|
66
|
+
line?: number | undefined;
|
|
67
|
+
column?: number | undefined;
|
|
68
|
+
});
|
|
69
|
+
readonly location: string | undefined;
|
|
70
|
+
readonly line: number | undefined;
|
|
71
|
+
readonly column: number | undefined;
|
|
72
|
+
}
|
package/dist/opc/exceptions.mjs
CHANGED
|
@@ -58,3 +58,23 @@ export class PartUnrecognisedException extends Docx4JException {
|
|
|
58
58
|
this.name = 'PartUnrecognisedException';
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* An XML part that could not be unmarshalled, naming the part (CR-002 section 27, item 9 of the
|
|
63
|
+
* E4 release). The runtime's own message is specific about *what* is wrong and, since
|
|
64
|
+
* `@docx4j/jsonix` 3.4.0, *where* - `w:sz/@w:val (line 12): Argument [NaN] must be an integer` -
|
|
65
|
+
* but it cannot know which part it was reading, and a person editing a part's XML in an editor needs
|
|
66
|
+
* that first. The location fields are lifted off the runtime's error so a caller does not have to
|
|
67
|
+
* parse the message.
|
|
68
|
+
*/
|
|
69
|
+
export class PartUnmarshalException extends Docx4JException {
|
|
70
|
+
constructor(message,
|
|
71
|
+
/** The part being unmarshalled: `/word/styles.xml`. */
|
|
72
|
+
partName, options) {
|
|
73
|
+
super(message, { cause: options === null || options === void 0 ? void 0 : options.cause });
|
|
74
|
+
this.partName = partName;
|
|
75
|
+
this.name = 'PartUnmarshalException';
|
|
76
|
+
this.location = options === null || options === void 0 ? void 0 : options.location;
|
|
77
|
+
this.line = options === null || options === void 0 ? void 0 : options.line;
|
|
78
|
+
this.column = options === null || options === void 0 ? void 0 : options.column;
|
|
79
|
+
}
|
|
80
|
+
}
|
package/dist/opc/index.d.mts
CHANGED
|
@@ -8,5 +8,5 @@ export { loadPackage, type LoadOptions } from './Load.mjs';
|
|
|
8
8
|
export { savePackage } from './Save.mjs';
|
|
9
9
|
export { mcePreprocess, createMcePreprocessor, resolveAlternateContent, MCE_NS, type McePreprocessOptions } from './mce/preprocessor.mjs';
|
|
10
10
|
export { UNDERSTOOD_NAMESPACES } from './mce/understood.mjs';
|
|
11
|
-
export { Docx4JException, InvalidFormatException, PartUnrecognisedException, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
|
|
11
|
+
export { Docx4JException, InvalidFormatException, PartUnrecognisedException, PartUnmarshalException, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
|
|
12
12
|
export { parseXml, serializeXml, serializeXmlPart, createDocument, encodeText, decodeXmlText, stripXmlDeclaration, base64Encode, base64Decode, childElements, XML_DECLARATION } from '../xml/dom.mjs';
|
package/dist/opc/index.mjs
CHANGED
|
@@ -9,5 +9,5 @@ export { loadPackage } from './Load.mjs';
|
|
|
9
9
|
export { savePackage } from './Save.mjs';
|
|
10
10
|
export { mcePreprocess, createMcePreprocessor, resolveAlternateContent, MCE_NS } from './mce/preprocessor.mjs';
|
|
11
11
|
export { UNDERSTOOD_NAMESPACES } from './mce/understood.mjs';
|
|
12
|
-
export { Docx4JException, InvalidFormatException, PartUnrecognisedException, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
|
|
12
|
+
export { Docx4JException, InvalidFormatException, PartUnrecognisedException, PartUnmarshalException, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
|
|
13
13
|
export { parseXml, serializeXml, serializeXmlPart, createDocument, encodeText, decodeXmlText, stripXmlDeclaration, base64Encode, base64Decode, childElements, XML_DECLARATION } from '../xml/dom.mjs';
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// What "understanding" an mc:Choice means here: the namespaces whose content survives a load and
|
|
2
|
+
// a save. Word takes the first mc:Choice whose Requires prefixes it all understands (ECMA-376
|
|
3
|
+
// Part 3, 10.2.1), and so does this preprocessor.
|
|
4
|
+
//
|
|
5
|
+
// It is the defaultElementNamespaceURI of every generated module of @docx4j/generated-objects-ts
|
|
6
|
+
// (0.3.0), which `mce.test.mjs` asserts so that the next regeneration announces an addition, plus
|
|
7
|
+
// two groups of hand-kept entries, each marked below: namespaces no module *defaults* to but which
|
|
8
|
+
// the model binds anyway (attributes, or elements a module of another namespace declares), and the
|
|
9
|
+
// slicer namespaces of CR-004 phase B, whose content the model does not bind at all but carries
|
|
10
|
+
// through as DOM.
|
|
5
11
|
export const UNDERSTOOD_NAMESPACES = new Set([
|
|
6
12
|
'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
|
|
7
|
-
'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
|
|
8
13
|
'http://schemas.openxmlformats.org/package/2006/relationships',
|
|
9
14
|
'http://schemas.openxmlformats.org/markup-compatibility/2006',
|
|
10
15
|
'http://schemas.openxmlformats.org/officeDocument/2006/math',
|
|
11
16
|
'http://schemas.openxmlformats.org/officeDocument/2006/bibliography',
|
|
12
17
|
'http://schemas.openxmlformats.org/officeDocument/2006/customXml',
|
|
13
18
|
'http://schemas.openxmlformats.org/schemaLibrary/2006/main',
|
|
14
|
-
'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties',
|
|
15
19
|
'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties',
|
|
16
20
|
'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes',
|
|
17
21
|
'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
|
|
@@ -36,7 +40,6 @@ export const UNDERSTOOD_NAMESPACES = new Set([
|
|
|
36
40
|
'http://schemas.microsoft.com/office/drawing/2010/diagram',
|
|
37
41
|
'http://schemas.microsoft.com/office/drawing/2012/main',
|
|
38
42
|
'http://schemas.microsoft.com/office/drawing/2012/chart',
|
|
39
|
-
'http://schemas.microsoft.com/office/drawing/2012/chartStyle',
|
|
40
43
|
'http://schemas.microsoft.com/office/drawing/2013/main/command',
|
|
41
44
|
'http://schemas.microsoft.com/office/drawing/2014/main',
|
|
42
45
|
'http://schemas.microsoft.com/office/drawing/2014/chart',
|
|
@@ -44,7 +47,6 @@ export const UNDERSTOOD_NAMESPACES = new Set([
|
|
|
44
47
|
'http://schemas.microsoft.com/office/drawing/2014/chartex',
|
|
45
48
|
'http://schemas.microsoft.com/office/drawing/2016/11/main',
|
|
46
49
|
'http://schemas.microsoft.com/office/drawing/2016/12/diagram',
|
|
47
|
-
'http://schemas.microsoft.com/office/drawing/2016/ink',
|
|
48
50
|
'http://schemas.microsoft.com/office/drawing/2016/SVG/main',
|
|
49
51
|
'http://schemas.microsoft.com/office/drawing/2017/03/chart',
|
|
50
52
|
'http://schemas.microsoft.com/office/drawing/2017/decorative',
|
|
@@ -68,6 +70,9 @@ export const UNDERSTOOD_NAMESPACES = new Set([
|
|
|
68
70
|
'http://schemas.microsoft.com/office/word/2012/wordprocessingDrawing',
|
|
69
71
|
'http://schemas.microsoft.com/office/word/2015/wordml/symex',
|
|
70
72
|
'http://schemas.microsoft.com/office/word/2016/wordml/cid',
|
|
73
|
+
'http://schemas.microsoft.com/office/word/2018/wordml',
|
|
74
|
+
'http://schemas.microsoft.com/office/word/2018/wordml/cex',
|
|
75
|
+
'http://schemas.microsoft.com/office/word/2026/wordml/cei',
|
|
71
76
|
'http://schemas.microsoft.com/office/webextensions/taskpanes/2010/11',
|
|
72
77
|
'http://schemas.microsoft.com/office/webextensions/webextension/2010/11',
|
|
73
78
|
'http://schemas.microsoft.com/office/powerpoint/2010/main',
|
|
@@ -89,10 +94,34 @@ export const UNDERSTOOD_NAMESPACES = new Set([
|
|
|
89
94
|
'http://schemas.microsoft.com/office/excel/2006/main',
|
|
90
95
|
'http://schemas.microsoft.com/office/excel/2008/2/main',
|
|
91
96
|
'http://schemas.microsoft.com/office/excel/2010/spreadsheetDrawing',
|
|
97
|
+
'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main',
|
|
98
|
+
'http://schemas.microsoft.com/office/spreadsheetml/2010/11/main',
|
|
99
|
+
'http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac',
|
|
100
|
+
'http://schemas.microsoft.com/office/spreadsheetml/2011/1/ac',
|
|
101
|
+
'http://schemas.microsoft.com/office/spreadsheetml/2014/11/main',
|
|
102
|
+
'http://schemas.microsoft.com/office/spreadsheetml/2014/revision',
|
|
103
|
+
'http://schemas.microsoft.com/office/spreadsheetml/2018/calcfeatures',
|
|
92
104
|
'http://schemas.microsoft.com/ink/2010/main',
|
|
93
105
|
'http://www.w3.org/1998/Math/MathML',
|
|
94
106
|
'http://www.w3.org/2003/InkML',
|
|
95
107
|
'http://schemas.microsoft.com/office/2006/encryption',
|
|
96
108
|
'http://schemas.microsoft.com/office/2006/keyEncryptor/certificate',
|
|
97
109
|
'http://schemas.microsoft.com/office/2006/keyEncryptor/password',
|
|
110
|
+
// Bound by the model without being any module's default element namespace (so the check in
|
|
111
|
+
// mce.test.mjs does not reach them): relationship ids and the custom document properties are
|
|
112
|
+
// attributes and elements other modules' types carry, chartStyle has a module that defaults to
|
|
113
|
+
// the DrawingML main namespace, and the 2016 ink one a module with no default at all.
|
|
114
|
+
'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
|
|
115
|
+
'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties',
|
|
116
|
+
'http://schemas.microsoft.com/office/drawing/2012/chartStyle',
|
|
117
|
+
'http://schemas.microsoft.com/office/drawing/2016/ink',
|
|
118
|
+
// Excel's slicer and timeline drawings (CR-004 phase B). Nothing binds these - docx4j has not
|
|
119
|
+
// bound the schemas either - but the Choice they gate is an xdr:graphicFrame whose a:graphicData
|
|
120
|
+
// holds the one unbound element, and that wildcard is lax (docx4j 8e8f6ea83), so it loads as DOM
|
|
121
|
+
// and re-marshals unchanged. Taking the Choice therefore keeps the slicer or timeline; leaving
|
|
122
|
+
// it would take the Fallback, an "Excel 2010 or higher" placeholder box, and lose the slicer for
|
|
123
|
+
// good. A Choice is only worth taking when everything in it round-trips (docx4j CR-021 8.9).
|
|
124
|
+
'http://schemas.microsoft.com/office/drawing/2010/slicer',
|
|
125
|
+
'http://schemas.microsoft.com/office/drawing/2012/slicer',
|
|
126
|
+
'http://schemas.microsoft.com/office/drawing/2012/timeslicer',
|
|
98
127
|
]);
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { OpcPackage, type PackageSource } from './OpcPackage.mjs';
|
|
2
2
|
import type { LoadOptions } from '../opc/Load.mjs';
|
|
3
3
|
import type { Part } from '../parts/Part.mjs';
|
|
4
|
-
import { MainDocumentPart, type NumberingDefinitionsPart } from '../parts/wml/index.mjs';
|
|
4
|
+
import { MainDocumentPart, StyleDefinitionsPart, type NumberingDefinitionsPart } from '../parts/wml/index.mjs';
|
|
5
5
|
import { type FontSettings, type DefaultThemeValue } from '../model/fonts/defaultTheme.mjs';
|
|
6
6
|
import type { Body, Address, Outline, OutlineParagraph, OutlineTable } from '../model/content/Body.mjs';
|
|
7
7
|
import type { Paragraph } from '../model/content/Paragraph.mjs';
|
|
8
8
|
import type { Author } from '../model/content/comments.mjs';
|
|
9
9
|
import { CustomXmlPartCollection } from '../model/customxml/CustomXmlPartCollection.mjs';
|
|
10
10
|
import { type XPathEngine } from '../model/customxml/xpath.mjs';
|
|
11
|
-
import { ChangeTracker, type ChangeTrackingMode, type TrackingHost } from '../model/content/tracking.mjs';
|
|
11
|
+
import { ChangeTracker, type ChangeTrackingMode, type TrackingHost, type TrackingScope } from '../model/content/tracking.mjs';
|
|
12
12
|
import { NumberingFacade } from '../model/content/List.mjs';
|
|
13
|
+
import { StylesFacade } from '../model/content/stylesFacade.mjs';
|
|
14
|
+
import type { Bound } from '../model/content/binder.mjs';
|
|
13
15
|
import { PropertyResolver } from '../model/properties/PropertyResolver.mjs';
|
|
14
16
|
import type { Emulator } from '../model/listnumbering/Emulator.mjs';
|
|
15
17
|
import type { TrackedChange } from '../model/content/TrackedChange.mjs';
|
|
18
|
+
import { XmlPart } from '../parts/XmlPart.mjs';
|
|
16
19
|
import type { PartSink } from '../opc/PartStore.mjs';
|
|
17
20
|
import '../parts/wml/comments.mjs';
|
|
18
21
|
/** The outline of a document: the body's paragraphs and tables, then each header's and footer's (loaded ones only). */
|
|
@@ -59,6 +62,31 @@ export declare class WordprocessingMLPackage extends OpcPackage implements Track
|
|
|
59
62
|
private tracker;
|
|
60
63
|
/** Set when `changeTrackingMode` was written but the settings part was not unmarshalled yet. */
|
|
61
64
|
private trackingPending;
|
|
65
|
+
/**
|
|
66
|
+
* `withTracking`'s mode for the duration of one call: read by the getter before everything else
|
|
67
|
+
* and **never** written by the setter, so it touches neither the settings part, `trackingPending`
|
|
68
|
+
* nor the cached `trackingMode` (CR-002 section 28.1).
|
|
69
|
+
*/
|
|
70
|
+
private trackingOverride;
|
|
71
|
+
/**
|
|
72
|
+
* The `withTracking` calls still running, oldest first, and what the package said before the
|
|
73
|
+
* first of them. The latest call's markup applies; when it ends, the latest one still running
|
|
74
|
+
* applies again, and when none is left the package is as it was (CR-002 section 31).
|
|
75
|
+
*/
|
|
76
|
+
private trackingScopes;
|
|
77
|
+
private beforeScopes;
|
|
78
|
+
/**
|
|
79
|
+
* Style ids a synchronous setter has given runs, to be defined in the styles part by the time the
|
|
80
|
+
* package is saved: `Range.hyperlink` writes `w:rStyle w:val="Hyperlink"` and cannot await
|
|
81
|
+
* `styles.ensure` (CR-002 section 25). `saveTo` ensures them; nothing is read before then.
|
|
82
|
+
*/
|
|
83
|
+
private requiredStyles;
|
|
84
|
+
/**
|
|
85
|
+
* The parts `seedAnnotationIds()` has read, with what it read: `true` for a part still holding its
|
|
86
|
+
* source, whose bytes cannot change, and otherwise the bytes that were set, which stay the same
|
|
87
|
+
* array until they are set again.
|
|
88
|
+
*/
|
|
89
|
+
private seededParts;
|
|
62
90
|
/**
|
|
63
91
|
* The package's font settings (CR-001 Phase B step 4), docx4j's `docx4j.fonts.*` properties
|
|
64
92
|
* scoped to one package: `defaultTheme` says which Office theme a font reference resolves
|
|
@@ -131,6 +159,30 @@ export declare class WordprocessingMLPackage extends OpcPackage implements Track
|
|
|
131
159
|
*/
|
|
132
160
|
get changeTrackingMode(): ChangeTrackingMode;
|
|
133
161
|
set changeTrackingMode(mode: ChangeTrackingMode);
|
|
162
|
+
/**
|
|
163
|
+
* Runs `fn` with revisions recorded as `markup` says, and the document's own setting untouched:
|
|
164
|
+
* nothing is written to `w:trackRevisions`, no settings part is created, and the mode a later read
|
|
165
|
+
* reports is the one that was there before (CR-002 section 28.1, for an editor whose agent must
|
|
166
|
+
* record its edits as a named author in a room whose tracking setting belongs to the document).
|
|
167
|
+
*
|
|
168
|
+
* The author, the date and the mode are restored in a `finally`, so a throw from `fn` cannot leave
|
|
169
|
+
* the package tracking. It is asynchronous for one reason: it awaits `seedAnnotationIds()` before
|
|
170
|
+
* running `fn`, so a revision written inside it cannot reuse an id from a part nobody has read
|
|
171
|
+
* (section 28.2). `fn` itself may be synchronous.
|
|
172
|
+
*
|
|
173
|
+
* Calls nest, and calls that overlap in time end in whatever order they end without leaving the
|
|
174
|
+
* package tracking. But the markup is the package's for as long as a call runs, not the call's:
|
|
175
|
+
* while two are running, **the later one's author and mode apply to every edit**, the earlier
|
|
176
|
+
* one's included, because nothing here can tell which asynchronous call an edit came from. Await
|
|
177
|
+
* one before starting another when they must be recorded as different authors (section 31).
|
|
178
|
+
*/
|
|
179
|
+
withTracking<T>(markup: TrackingScope, fn: () => T | Promise<T>): Promise<T>;
|
|
180
|
+
/**
|
|
181
|
+
* One `withTracking` call's markup made the package's. The tracker is left alone: the getter makes
|
|
182
|
+
* another when the mode differs, and the id counter it reads is the package's, so a tracker kept
|
|
183
|
+
* across the call cannot reissue an id given out inside it (section 31).
|
|
184
|
+
*/
|
|
185
|
+
private applyTrackingScope;
|
|
134
186
|
/** The mode as the settings part has it, unmarshalling the part (docx4j's async counterpart of the getter). */
|
|
135
187
|
getChangeTrackingMode(): Promise<ChangeTrackingMode>;
|
|
136
188
|
/** Writes `w:trackRevisions`, unmarshalling the settings part, or creating it when there is none. */
|
|
@@ -145,9 +197,50 @@ export declare class WordprocessingMLPackage extends OpcPackage implements Track
|
|
|
145
197
|
getTrackedChanges(): TrackedChange[];
|
|
146
198
|
/** The tracker every content-API mutation asks for; undefined while the mode is `Off`. */
|
|
147
199
|
get changeTracker(): ChangeTracker | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* The objects an XPath selects in a part of this document, through the package's engine
|
|
202
|
+
* (CR-006; docx4j `MainDocumentPart.getJAXBNodesViaXPath`). The part defaults to the main
|
|
203
|
+
* document part, which is what a `//w:p[...]` expression means.
|
|
204
|
+
*/
|
|
205
|
+
selectObjects(xpath: string, options?: {
|
|
206
|
+
part?: XmlPart<unknown>;
|
|
207
|
+
namespaces?: Record<string, string>;
|
|
208
|
+
}): Promise<Bound[]>;
|
|
209
|
+
/**
|
|
210
|
+
* TrackingHost: a floor for the annotation id, from the WordprocessingML parts that were **not**
|
|
211
|
+
* unmarshalled; `seedAnnotationIds()` fills it. 0 until then (CR-002 section 28.2).
|
|
212
|
+
*/
|
|
213
|
+
annotationIdFloor: number;
|
|
214
|
+
/**
|
|
215
|
+
* TrackingHost: the last annotation id issued, shared by every tracker this package makes (CR-002
|
|
216
|
+
* section 31). Forgotten when the mode is set, as the tracker used to be, so that the next id is
|
|
217
|
+
* found by a fresh scan of whatever has arrived since by other routes (`insertOoxml`, `setContents`).
|
|
218
|
+
*/
|
|
219
|
+
annotationIdCounter: number | undefined;
|
|
220
|
+
/**
|
|
221
|
+
* Raises `annotationIdFloor` above every annotation id in the WordprocessingML parts that are not
|
|
222
|
+
* unmarshalled, reading each **privately** (`readContents`, CR-001 Phase D's device), so that a
|
|
223
|
+
* part nobody has touched keeps its byte-for-byte round trip and still cannot have its ids reused.
|
|
224
|
+
*
|
|
225
|
+
* Awaited by `setChangeTrackingMode()` and by `withTracking()`, which is where tracking is turned
|
|
226
|
+
* on; a caller that uses the synchronous `changeTrackingMode` setter on a document with unread
|
|
227
|
+
* parts should await this itself, since `nextId()` cannot (the content API's setters are
|
|
228
|
+
* synchronous, which is why the floor exists at all rather than the scan being made async).
|
|
229
|
+
*
|
|
230
|
+
* A part is read once for the bytes it holds: an agent that wraps every edit in `withTracking`
|
|
231
|
+
* would otherwise re-read every header, footer and note part each time (section 31). Its source
|
|
232
|
+
* bytes cannot change; bytes that were set are read again when they are set again.
|
|
233
|
+
*/
|
|
234
|
+
seedAnnotationIds(): Promise<number>;
|
|
148
235
|
/** TrackingHost: the trees a new revision id must be above, which is every part already unmarshalled. */
|
|
149
236
|
markupRoots(): object[];
|
|
150
|
-
/**
|
|
237
|
+
/**
|
|
238
|
+
* Asks for style definitions a synchronous setter has referenced; they are ensured on save, as
|
|
239
|
+
* `pkg.styles.ensure(ids)` would, and a document that already has them keeps its styles part
|
|
240
|
+
* byte for byte (CR-002 section 25). Await `styles.ensure` instead to have them at once.
|
|
241
|
+
*/
|
|
242
|
+
requireStyles(ids: Iterable<string>): void;
|
|
243
|
+
/** A clone carries the identity, the tracking date, the theme setting, the XPath engine and the styles still to ensure. */
|
|
151
244
|
protected copyPackageSettingsTo(target: OpcPackage): void;
|
|
152
245
|
saveTo<R>(sink: PartSink<R>): Promise<R>;
|
|
153
246
|
/** The paragraph at an address anywhere in the document: 'body/3', 'header:rId5/0', a paraId, or a text match. */
|
|
@@ -162,6 +255,15 @@ export declare class WordprocessingMLPackage extends OpcPackage implements Track
|
|
|
162
255
|
* `customXmlParts.load()`; every node call is synchronous afterwards.
|
|
163
256
|
*/
|
|
164
257
|
xpathEngine: XPathEngine;
|
|
258
|
+
/**
|
|
259
|
+
* The document's style definitions as a verb that needs no `Body`: `ensure(ids)` splices in a
|
|
260
|
+
* style the document lacks, out of the same defaults `createPackage()` writes, with what it is
|
|
261
|
+
* based on and linked to (CR-002 section 22.2).
|
|
262
|
+
*/
|
|
263
|
+
get styles(): StylesFacade;
|
|
264
|
+
private stylesFacade;
|
|
265
|
+
/** The styles part, created with the defaults when the document has none (CR-002 section 22.2). */
|
|
266
|
+
ensureStyleDefinitionsPart(): StyleDefinitionsPart;
|
|
165
267
|
/**
|
|
166
268
|
* The document's list definitions as verbs that need no paragraph: `newList()` and
|
|
167
269
|
* `restart(numId)` (CR-002 section 19). `Paragraph.startNewList()` and `List.restart()` are
|