@docx4j/core-ts 0.1.0 → 0.1.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 +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 +1 -0
- package/dist/opc/ContentTypes.mjs +1 -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/PartRegistry.mjs +1 -0
- 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 +19 -1
- package/dist/parts/sml/index.mjs +60 -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
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
import * as el from '@docx4j/generated-objects-ts/el/org_docx4j_wml';
|
|
2
|
+
import * as w15el from '@docx4j/generated-objects-ts/el/org_docx4j_w15';
|
|
3
|
+
import { Docx4JException } from '../../opc/exceptions.mjs';
|
|
4
|
+
import { marshalString, deepCopy } from '@docx4j/generated-objects-ts';
|
|
5
|
+
// CR-002 phase E: the mapping and the typed kinds live in src/model/customxml/; they import
|
|
6
|
+
// nothing from here at run time (types only), so this direction is the only one.
|
|
7
|
+
import { XmlMapping } from '../customxml/XmlMapping.mjs';
|
|
8
|
+
import { CheckboxContentControl, DatePickerContentControl, ListContentControl, PictureContentControl, RepeatingSectionContentControl, GroupContentControl, checkboxRun, CHECKBOX_FONT, } from '../customxml/kinds.mjs';
|
|
9
|
+
import { runsForValue, updateFromControl, PLACEHOLDER_TEXT } from '../customxml/bindings.mjs';
|
|
10
|
+
import { sdtProperty, sdtKindOf } from '@docx4j/generated-objects-ts/builders/wml';
|
|
11
|
+
import { typeNameOf, childrenOf, textOf, runItemsOf, segmentsOf, linkParents, SDT_TYPES } from './tree.mjs';
|
|
12
|
+
import { Range } from './Range.mjs';
|
|
13
|
+
import { Table } from './Table.mjs';
|
|
14
|
+
/** The namespaces of the Word 2010 and 2012 content-control properties. */
|
|
15
|
+
export const W14_NS = 'http://schemas.microsoft.com/office/word/2010/wordml';
|
|
16
|
+
export const W15_NS = 'http://schemas.microsoft.com/office/word/2012/wordml';
|
|
17
|
+
/** A subset of Office JS `Word.ContentControl` over a `w:sdt`. A view, as Paragraph is. */
|
|
18
|
+
export class ContentControl {
|
|
19
|
+
constructor(
|
|
20
|
+
/** The `w:sdt` element pair (SdtBlock, SdtRun, CTSdtRow or CTSdtCell). */
|
|
21
|
+
element,
|
|
22
|
+
/** The array holding the element. */
|
|
23
|
+
container,
|
|
24
|
+
/** The body the control is in (the part's). */
|
|
25
|
+
parentBody) {
|
|
26
|
+
this.element = element;
|
|
27
|
+
this.container = container;
|
|
28
|
+
this.parentBody = parentBody;
|
|
29
|
+
}
|
|
30
|
+
/** The sdt value. */
|
|
31
|
+
get sdt() {
|
|
32
|
+
return this.element.value;
|
|
33
|
+
}
|
|
34
|
+
/** The control's content array (`w:sdtContent`); empty and detached when the control has none (reads never add one). */
|
|
35
|
+
get content() {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
return (_b = (_a = this.sdt.sdtContent) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : [];
|
|
38
|
+
}
|
|
39
|
+
/** Which of the four forms this is: block, run, row or cell content. */
|
|
40
|
+
get form() {
|
|
41
|
+
switch (typeNameOf(this.element)) {
|
|
42
|
+
case 'org_docx4j_wml.CTSdtRow': return 'Row';
|
|
43
|
+
case 'org_docx4j_wml.CTSdtCell': return 'Cell';
|
|
44
|
+
case 'org_docx4j_wml.SdtRun': return 'Run';
|
|
45
|
+
default: {
|
|
46
|
+
// objects CR-002: a run-level control parsed at body level is typed SdtBlock; what it
|
|
47
|
+
// holds decides.
|
|
48
|
+
const first = this.content.find((e) => typeNameOf(e) !== undefined);
|
|
49
|
+
const tn = first ? typeNameOf(first) : undefined;
|
|
50
|
+
return tn === 'org_docx4j_wml.R' ? 'Run' : 'Block';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The type Word reports (w:sdtPr's kind element); RichText when none is given, as Word does. */
|
|
55
|
+
get type() {
|
|
56
|
+
return sdtKindOf(this.sdt.sdtPr);
|
|
57
|
+
}
|
|
58
|
+
/** w:tag. */
|
|
59
|
+
get tag() {
|
|
60
|
+
return this.property('tag');
|
|
61
|
+
}
|
|
62
|
+
set tag(value) {
|
|
63
|
+
this.setProperty('tag', value, (v) => el.tag({ val: v }));
|
|
64
|
+
}
|
|
65
|
+
/** w:alias, which is what Word's user interface calls the title. */
|
|
66
|
+
get title() {
|
|
67
|
+
return this.property('alias');
|
|
68
|
+
}
|
|
69
|
+
set title(value) {
|
|
70
|
+
this.setProperty('alias', value, (v) => el.alias({ val: v }));
|
|
71
|
+
}
|
|
72
|
+
/** w:id, the number Word gives a control; 0 when it has none. */
|
|
73
|
+
get id() {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
const item = (_b = (_a = this.sdt.sdtPr) === null || _a === void 0 ? void 0 : _a.rPrOrAliasOrLock) === null || _b === void 0 ? void 0 : _b.find((i) => i.name.localPart === 'id');
|
|
76
|
+
const val = (_c = item === null || item === void 0 ? void 0 : item.value) === null || _c === void 0 ? void 0 : _c.val;
|
|
77
|
+
return typeof val === 'number' ? val : 0;
|
|
78
|
+
}
|
|
79
|
+
/** The control's text, a line per paragraph (docx4j TextUtils). */
|
|
80
|
+
get text() {
|
|
81
|
+
var _a;
|
|
82
|
+
return textOf((_a = this.sdt.sdtContent) !== null && _a !== void 0 ? _a : {});
|
|
83
|
+
}
|
|
84
|
+
/** Every paragraph in the control; for a run-level control, the paragraph it is in. */
|
|
85
|
+
get paragraphs() {
|
|
86
|
+
if (this.form === 'Run') {
|
|
87
|
+
const p = this.parentParagraph();
|
|
88
|
+
return p ? [p] : [];
|
|
89
|
+
}
|
|
90
|
+
return this.body().paragraphs;
|
|
91
|
+
}
|
|
92
|
+
/** The tables directly in the control; for a row or cell control, the table it is part of. */
|
|
93
|
+
get tables() {
|
|
94
|
+
if (this.form === 'Block')
|
|
95
|
+
return this.body().tables;
|
|
96
|
+
if (this.form === 'Row' || this.form === 'Cell') {
|
|
97
|
+
const table = this.ancestorTable();
|
|
98
|
+
return table ? [table] : [];
|
|
99
|
+
}
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
/** The controls nested in this one, in document order. */
|
|
103
|
+
get contentControls() {
|
|
104
|
+
const out = [];
|
|
105
|
+
collectControls(this.content, this.parentBody, out);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Text at the start, the end, or replacing the control's text. On a **bound** control the value
|
|
110
|
+
* is written through to the custom XML node as well when the mapping resolves (CR-002 phase E):
|
|
111
|
+
* Word refreshes a bound control from the custom XML part when it opens the document, so an edit
|
|
112
|
+
* that only touched `w:sdtContent` would not show. When the XPath engine is not warm yet the
|
|
113
|
+
* write is left to `pkg.customXmlParts.updateFromContentControls()`.
|
|
114
|
+
*/
|
|
115
|
+
insertText(text, location) {
|
|
116
|
+
const range = this.insertTextInto(text, location);
|
|
117
|
+
this.syncBoundNode();
|
|
118
|
+
return range;
|
|
119
|
+
}
|
|
120
|
+
insertTextInto(text, location) {
|
|
121
|
+
const form = this.form;
|
|
122
|
+
if ((form === 'Row' || form === 'Cell') && location === 'Replace') {
|
|
123
|
+
throw new Docx4JException(`A ${form.toLowerCase()}-level content control holds ${form === 'Row' ? 'rows' : 'cells'}; replace the text of its cells instead`);
|
|
124
|
+
}
|
|
125
|
+
if (form !== 'Run')
|
|
126
|
+
return this.body().insertText(text, location);
|
|
127
|
+
const span = this.runSpan();
|
|
128
|
+
if (!span)
|
|
129
|
+
throw new Docx4JException('This content control is not in a paragraph');
|
|
130
|
+
const { paragraph, start, end } = span;
|
|
131
|
+
if (location === 'Start')
|
|
132
|
+
return paragraph.splice(start, start, text);
|
|
133
|
+
if (location === 'End')
|
|
134
|
+
return paragraph.splice(end, end, text);
|
|
135
|
+
return paragraph.splice(start, end, text);
|
|
136
|
+
}
|
|
137
|
+
/** A paragraph at the start or end of a block control; before or after the paragraph of a run control. */
|
|
138
|
+
insertParagraph(text, location) {
|
|
139
|
+
const form = this.form;
|
|
140
|
+
if ((form === 'Row' || form === 'Cell') && (location === 'Start' || location === 'End')) {
|
|
141
|
+
throw new Docx4JException(`A ${form.toLowerCase()}-level content control holds ${form === 'Row' ? 'rows' : 'cells'}, not paragraphs; insert into a cell's body`);
|
|
142
|
+
}
|
|
143
|
+
if (form === 'Run' || location === 'Before' || location === 'After') {
|
|
144
|
+
const p = this.parentParagraph();
|
|
145
|
+
if (p)
|
|
146
|
+
return p.insertParagraph(text, location === 'Before' ? 'Before' : 'After');
|
|
147
|
+
return this.parentBody.insertElement(paragraphElement(text), location === 'Before' ? 'Before' : 'After', { element: this.element, container: this.container });
|
|
148
|
+
}
|
|
149
|
+
return this.body().insertParagraph(text, location);
|
|
150
|
+
}
|
|
151
|
+
/** Matches within the control. */
|
|
152
|
+
search(text, options) {
|
|
153
|
+
if (this.form !== 'Run')
|
|
154
|
+
return this.body().search(text, options);
|
|
155
|
+
const range = this.getRange();
|
|
156
|
+
return range ? range.search(text, options) : [];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The control's range. For a run-level control, exactly the text it holds; for the other forms,
|
|
160
|
+
* the first paragraph (departure: a Range here is within one paragraph, CR-002 section 7).
|
|
161
|
+
*/
|
|
162
|
+
getRange(location = 'Whole') {
|
|
163
|
+
if (this.form === 'Run') {
|
|
164
|
+
const span = this.runSpan();
|
|
165
|
+
if (!span)
|
|
166
|
+
throw new Docx4JException('This content control is not in a paragraph');
|
|
167
|
+
const { paragraph, start, end } = span;
|
|
168
|
+
if (location === 'Start')
|
|
169
|
+
return new Range(paragraph, start, start);
|
|
170
|
+
if (location === 'End')
|
|
171
|
+
return new Range(paragraph, end, end);
|
|
172
|
+
return new Range(paragraph, start, end);
|
|
173
|
+
}
|
|
174
|
+
const first = this.paragraphs[0];
|
|
175
|
+
if (!first)
|
|
176
|
+
throw new Docx4JException('This content control holds no paragraph');
|
|
177
|
+
return first.getRange(location);
|
|
178
|
+
}
|
|
179
|
+
/** Removes the control; `keepContent` puts what it held in its place, as Office JS. */
|
|
180
|
+
delete(keepContent = false) {
|
|
181
|
+
const at = this.container.indexOf(this.element);
|
|
182
|
+
if (at < 0)
|
|
183
|
+
return;
|
|
184
|
+
const content = keepContent ? [...this.content] : [];
|
|
185
|
+
this.container.splice(at, 1, ...content);
|
|
186
|
+
if (keepContent) {
|
|
187
|
+
const owner = ownerOf(this.container, this.parentBody);
|
|
188
|
+
for (const item of content)
|
|
189
|
+
linkParents(item, owner);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/** The XML of the control (extension). */
|
|
193
|
+
getXml() {
|
|
194
|
+
return marshalString(this.element);
|
|
195
|
+
}
|
|
196
|
+
// --- internals ---
|
|
197
|
+
/** A Body view over the control's content, for the block form; the `w:sdtContent` is created if the control has none. */
|
|
198
|
+
body() {
|
|
199
|
+
var _a, _b;
|
|
200
|
+
const sdt = this.sdt;
|
|
201
|
+
(_a = sdt.sdtContent) !== null && _a !== void 0 ? _a : (sdt.sdtContent = {});
|
|
202
|
+
const prefix = (_b = this.parentBody.addressOf({ element: this.element, container: this.container })) !== null && _b !== void 0 ? _b : this.parentBody.prefix;
|
|
203
|
+
return this.parentBody.sub(sdt.sdtContent, prefix);
|
|
204
|
+
}
|
|
205
|
+
property(localPart) {
|
|
206
|
+
var _a, _b, _c, _d;
|
|
207
|
+
const item = (_b = (_a = this.sdt.sdtPr) === null || _a === void 0 ? void 0 : _a.rPrOrAliasOrLock) === null || _b === void 0 ? void 0 : _b.find((i) => i.name.localPart === localPart);
|
|
208
|
+
return (_d = (_c = item === null || item === void 0 ? void 0 : item.value) === null || _c === void 0 ? void 0 : _c.val) !== null && _d !== void 0 ? _d : '';
|
|
209
|
+
}
|
|
210
|
+
setProperty(localPart, value, make) {
|
|
211
|
+
var _a, _b;
|
|
212
|
+
var _c;
|
|
213
|
+
const sdt = this.sdt;
|
|
214
|
+
(_a = sdt.sdtPr) !== null && _a !== void 0 ? _a : (sdt.sdtPr = {});
|
|
215
|
+
const items = ((_b = (_c = sdt.sdtPr).rPrOrAliasOrLock) !== null && _b !== void 0 ? _b : (_c.rPrOrAliasOrLock = []));
|
|
216
|
+
const at = items.findIndex((i) => i.name.localPart === localPart);
|
|
217
|
+
if (value === '') {
|
|
218
|
+
if (at >= 0)
|
|
219
|
+
items.splice(at, 1);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const element = make(value);
|
|
223
|
+
if (at >= 0)
|
|
224
|
+
items[at] = element;
|
|
225
|
+
else
|
|
226
|
+
items.push(element);
|
|
227
|
+
}
|
|
228
|
+
/** The paragraph a run-level control is in. */
|
|
229
|
+
parentParagraph() {
|
|
230
|
+
let current = this.element.value;
|
|
231
|
+
for (let guard = 0; current && guard < 64; guard++) {
|
|
232
|
+
if (typeNameOf(current) === 'org_docx4j_wml.P')
|
|
233
|
+
return this.parentBody.paragraphFor(current);
|
|
234
|
+
current = current.PARENT;
|
|
235
|
+
}
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
/** The offsets a run-level control covers in its paragraph. */
|
|
239
|
+
runSpan() {
|
|
240
|
+
const paragraph = this.parentParagraph();
|
|
241
|
+
if (!paragraph)
|
|
242
|
+
return undefined;
|
|
243
|
+
const inside = (run) => {
|
|
244
|
+
let current = run;
|
|
245
|
+
for (let guard = 0; current && guard < 32; guard++) {
|
|
246
|
+
if (current === this.element.value)
|
|
247
|
+
return true;
|
|
248
|
+
current = current.PARENT;
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
};
|
|
252
|
+
let start;
|
|
253
|
+
let end = 0;
|
|
254
|
+
for (const seg of segmentsOf(paragraph.p)) {
|
|
255
|
+
if (!inside(seg.run))
|
|
256
|
+
continue;
|
|
257
|
+
if (start === undefined)
|
|
258
|
+
start = seg.start;
|
|
259
|
+
end = seg.end;
|
|
260
|
+
}
|
|
261
|
+
if (start === undefined) {
|
|
262
|
+
// an empty control: its position is where its runs would be
|
|
263
|
+
return { paragraph, start: 0, end: 0 };
|
|
264
|
+
}
|
|
265
|
+
return { paragraph, start, end };
|
|
266
|
+
}
|
|
267
|
+
// --- CR-002 phase E: the XML mapping, the typed kinds and the w:sdtPr properties ---
|
|
268
|
+
/** The control's data binding (Office JS `xmlMapping`), backed by `w:dataBinding`. */
|
|
269
|
+
get xmlMapping() {
|
|
270
|
+
const pkg = this.parentBody.package_;
|
|
271
|
+
return new XmlMapping(this, pkg === null || pkg === void 0 ? void 0 : pkg.customXmlParts);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The placeholder Word shows for an empty control: the control's own text while it is showing
|
|
275
|
+
* the placeholder (`w:showingPlcHdr`), else '' — Word keeps the text itself in a glossary
|
|
276
|
+
* document part, which this phase does not create (CR-002 section 12). Setting writes the text
|
|
277
|
+
* as the control's content and sets `w:showingPlcHdr`, which is refused when the control holds
|
|
278
|
+
* content of its own, so that a value is never lost.
|
|
279
|
+
*/
|
|
280
|
+
get placeholderText() {
|
|
281
|
+
return this.isShowingPlaceholder ? this.text : '';
|
|
282
|
+
}
|
|
283
|
+
set placeholderText(text) {
|
|
284
|
+
var _a;
|
|
285
|
+
if (!this.isShowingPlaceholder && this.text !== '') {
|
|
286
|
+
throw new Docx4JException('This content control holds content; clear it before setting its placeholder text');
|
|
287
|
+
}
|
|
288
|
+
this.setBoundContent(runsForValue('', this.runProperties, false), true);
|
|
289
|
+
if (text !== '' && text !== PLACEHOLDER_TEXT) {
|
|
290
|
+
const run = this.firstRunOfContent();
|
|
291
|
+
const t = (_a = run === null || run === void 0 ? void 0 : run.content) === null || _a === void 0 ? void 0 : _a[0];
|
|
292
|
+
if (t === null || t === void 0 ? void 0 : t.value)
|
|
293
|
+
t.value.value = text;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/** Office JS `appearance`: how Word draws the control (`w15:appearance`). */
|
|
297
|
+
get appearance() {
|
|
298
|
+
var _a, _b;
|
|
299
|
+
const val = (_b = (_a = sdtProperty(this.sdt.sdtPr, 'appearance', W15_NS)) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.val;
|
|
300
|
+
return val === 'tags' ? 'Tags' : val === 'hidden' ? 'Hidden' : 'BoundingBox';
|
|
301
|
+
}
|
|
302
|
+
set appearance(value) {
|
|
303
|
+
const val = value === 'Tags' ? 'tags' : value === 'Hidden' ? 'hidden' : 'boundingBox';
|
|
304
|
+
this.putProperty(w15el.appearance({ val }));
|
|
305
|
+
}
|
|
306
|
+
/** Office JS `color`: the control's colour as '#RRGGBB' (`w15:color`). */
|
|
307
|
+
get color() {
|
|
308
|
+
var _a, _b;
|
|
309
|
+
const val = (_b = (_a = sdtProperty(this.sdt.sdtPr, 'color', W15_NS)) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.val;
|
|
310
|
+
return val === undefined || val === 'auto' ? '' : `#${val.replace(/^#/, '')}`;
|
|
311
|
+
}
|
|
312
|
+
set color(value) {
|
|
313
|
+
if (value === '') {
|
|
314
|
+
this.removeProperty('color');
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
this.putProperty(w15el.color({ val: value.replace(/^#/, '').toUpperCase() }));
|
|
318
|
+
}
|
|
319
|
+
/** Office JS `cannotDelete`: `w:lock` sdtLocked or sdtContentLocked. */
|
|
320
|
+
get cannotDelete() {
|
|
321
|
+
const val = this.lockValue();
|
|
322
|
+
return val === 'sdtLocked' || val === 'sdtContentLocked';
|
|
323
|
+
}
|
|
324
|
+
set cannotDelete(value) {
|
|
325
|
+
this.setLock(value, this.cannotEdit);
|
|
326
|
+
}
|
|
327
|
+
/** Office JS `cannotEdit`: `w:lock` contentLocked or sdtContentLocked. */
|
|
328
|
+
get cannotEdit() {
|
|
329
|
+
const val = this.lockValue();
|
|
330
|
+
return val === 'contentLocked' || val === 'sdtContentLocked';
|
|
331
|
+
}
|
|
332
|
+
set cannotEdit(value) {
|
|
333
|
+
this.setLock(this.cannotDelete, value);
|
|
334
|
+
}
|
|
335
|
+
/** Office JS `removeWhenEdited`: `w:temporary`, the control Word drops once it is filled in. */
|
|
336
|
+
get removeWhenEdited() {
|
|
337
|
+
var _a;
|
|
338
|
+
const item = sdtProperty(this.sdt.sdtPr, 'temporary');
|
|
339
|
+
return item !== undefined && ((_a = item.value) === null || _a === void 0 ? void 0 : _a.val) !== false;
|
|
340
|
+
}
|
|
341
|
+
set removeWhenEdited(value) {
|
|
342
|
+
if (!value) {
|
|
343
|
+
this.removeProperty('temporary');
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
this.putProperty(el.temporary({ val: true }));
|
|
347
|
+
}
|
|
348
|
+
/** The checkbox view, for a `w14:checkbox` control; undefined for every other kind, as Office JS. */
|
|
349
|
+
get checkboxContentControl() {
|
|
350
|
+
var _a;
|
|
351
|
+
const value = (_a = sdtProperty(this.sdt.sdtPr, 'checkbox', W14_NS)) === null || _a === void 0 ? void 0 : _a.value;
|
|
352
|
+
return value ? new CheckboxContentControl(this, value) : undefined;
|
|
353
|
+
}
|
|
354
|
+
/** The date view, for a `w:date` control. */
|
|
355
|
+
get datePickerContentControl() {
|
|
356
|
+
var _a;
|
|
357
|
+
const value = (_a = sdtProperty(this.sdt.sdtPr, 'date')) === null || _a === void 0 ? void 0 : _a.value;
|
|
358
|
+
return value ? new DatePickerContentControl(value) : undefined;
|
|
359
|
+
}
|
|
360
|
+
/** The list view, for a `w:dropDownList` control. */
|
|
361
|
+
get dropDownListContentControl() {
|
|
362
|
+
var _a;
|
|
363
|
+
const value = (_a = sdtProperty(this.sdt.sdtPr, 'dropDownList')) === null || _a === void 0 ? void 0 : _a.value;
|
|
364
|
+
return value ? new ListContentControl(value) : undefined;
|
|
365
|
+
}
|
|
366
|
+
/** The list view, for a `w:comboBox` control. */
|
|
367
|
+
get comboBoxContentControl() {
|
|
368
|
+
var _a;
|
|
369
|
+
const value = (_a = sdtProperty(this.sdt.sdtPr, 'comboBox')) === null || _a === void 0 ? void 0 : _a.value;
|
|
370
|
+
return value ? new ListContentControl(value) : undefined;
|
|
371
|
+
}
|
|
372
|
+
/** The picture view, for a `w:picture` control. */
|
|
373
|
+
get pictureContentControl() {
|
|
374
|
+
return sdtProperty(this.sdt.sdtPr, 'picture') ? new PictureContentControl(this) : undefined;
|
|
375
|
+
}
|
|
376
|
+
/** The repeating-section view, for a `w15:repeatingSection` control. */
|
|
377
|
+
get repeatingSectionContentControl() {
|
|
378
|
+
var _a;
|
|
379
|
+
const value = (_a = sdtProperty(this.sdt.sdtPr, 'repeatingSection', W15_NS)) === null || _a === void 0 ? void 0 : _a.value;
|
|
380
|
+
return value ? new RepeatingSectionContentControl(this, value) : undefined;
|
|
381
|
+
}
|
|
382
|
+
/** The group view, for a `w:group` control (Office JS: an object with no members of its own). */
|
|
383
|
+
get groupContentControl() {
|
|
384
|
+
return sdtProperty(this.sdt.sdtPr, 'group') ? new GroupContentControl() : undefined;
|
|
385
|
+
}
|
|
386
|
+
/** Adds or replaces a `w:sdtPr` child (extension). */
|
|
387
|
+
putProperty(element) {
|
|
388
|
+
var _a, _b;
|
|
389
|
+
var _c;
|
|
390
|
+
const sdt = this.sdt;
|
|
391
|
+
(_a = sdt.sdtPr) !== null && _a !== void 0 ? _a : (sdt.sdtPr = {});
|
|
392
|
+
const items = ((_b = (_c = sdt.sdtPr).rPrOrAliasOrLock) !== null && _b !== void 0 ? _b : (_c.rPrOrAliasOrLock = []));
|
|
393
|
+
const at = items.findIndex((i) => i.name.localPart === element.name.localPart && i.name.namespaceURI === element.name.namespaceURI);
|
|
394
|
+
if (at >= 0)
|
|
395
|
+
items[at] = element;
|
|
396
|
+
else
|
|
397
|
+
items.push(element);
|
|
398
|
+
}
|
|
399
|
+
/** Removes a `w:sdtPr` child (extension). */
|
|
400
|
+
removeProperty(localPart, namespaceURI) {
|
|
401
|
+
var _a;
|
|
402
|
+
const items = (_a = this.sdt.sdtPr) === null || _a === void 0 ? void 0 : _a.rPrOrAliasOrLock;
|
|
403
|
+
if (!items)
|
|
404
|
+
return;
|
|
405
|
+
const at = items.findIndex((i) => i.name.localPart === localPart && (namespaceURI === undefined || i.name.namespaceURI === namespaceURI));
|
|
406
|
+
if (at >= 0)
|
|
407
|
+
items.splice(at, 1);
|
|
408
|
+
}
|
|
409
|
+
/** The run properties `w:sdtPr/w:rPr` a bound value is written with (docx4j does the same). */
|
|
410
|
+
get runProperties() {
|
|
411
|
+
var _a;
|
|
412
|
+
return (_a = sdtProperty(this.sdt.sdtPr, 'rPr')) === null || _a === void 0 ? void 0 : _a.value;
|
|
413
|
+
}
|
|
414
|
+
/** Whether a plain-text control accepts several lines (`w:text/@w:multiLine`). */
|
|
415
|
+
get isMultiLine() {
|
|
416
|
+
var _a, _b;
|
|
417
|
+
return ((_b = (_a = sdtProperty(this.sdt.sdtPr, 'text')) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.multiLine) === true;
|
|
418
|
+
}
|
|
419
|
+
/** Whether the control is showing its placeholder rather than a value (`w:showingPlcHdr`). */
|
|
420
|
+
get isShowingPlaceholder() {
|
|
421
|
+
var _a;
|
|
422
|
+
const item = sdtProperty(this.sdt.sdtPr, 'showingPlcHdr');
|
|
423
|
+
return item !== undefined && ((_a = item.value) === null || _a === void 0 ? void 0 : _a.val) !== false;
|
|
424
|
+
}
|
|
425
|
+
set isShowingPlaceholder(value) {
|
|
426
|
+
if (!value) {
|
|
427
|
+
this.removeProperty('showingPlcHdr');
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
this.putProperty(el.showingPlcHdr({ val: true }));
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Replaces what the control shows with these runs (docx4j BindingHandler's applyBoundContent):
|
|
434
|
+
* into the first paragraph of a block, row or cell control, keeping its `w:pPr`, and in place of
|
|
435
|
+
* the runs of a run-level one.
|
|
436
|
+
*/
|
|
437
|
+
setBoundContent(runs, showingPlaceholder = false) {
|
|
438
|
+
var _a, _b;
|
|
439
|
+
var _c;
|
|
440
|
+
const sdt = this.sdt;
|
|
441
|
+
(_a = sdt.sdtContent) !== null && _a !== void 0 ? _a : (sdt.sdtContent = {});
|
|
442
|
+
const content = ((_b = (_c = sdt.sdtContent).content) !== null && _b !== void 0 ? _b : (_c.content = []));
|
|
443
|
+
const first = content.find((e) => typeNameOf(e) !== undefined);
|
|
444
|
+
if (this.form === 'Run' || (first && typeNameOf(first) === 'org_docx4j_wml.R')) {
|
|
445
|
+
content.length = 0;
|
|
446
|
+
content.push(...runs);
|
|
447
|
+
linkParents(content, sdt.sdtContent);
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
const paragraph = this.paragraphs[0];
|
|
451
|
+
if (paragraph) {
|
|
452
|
+
paragraph.p.content = runs;
|
|
453
|
+
linkParents(paragraph.p.content, paragraph.p);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
const p = paragraphElementOf(runs);
|
|
457
|
+
content.push(p);
|
|
458
|
+
linkParents(p, sdt.sdtContent);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
this.isShowingPlaceholder = showingPlaceholder;
|
|
462
|
+
}
|
|
463
|
+
/** Shows a checkbox's glyph, as Word writes it: one run in the checkbox font (docx4j checkboxRun). */
|
|
464
|
+
setCheckboxGlyph(symbol) {
|
|
465
|
+
var _a;
|
|
466
|
+
const checkbox = this.checkboxContentControl;
|
|
467
|
+
this.setBoundContent([checkboxRun(symbol, (_a = checkbox === null || checkbox === void 0 ? void 0 : checkbox.font) !== null && _a !== void 0 ? _a : CHECKBOX_FONT, this.runProperties)]);
|
|
468
|
+
}
|
|
469
|
+
/** A copy of this control right after it, as Word's repeating-section + button does (extension). */
|
|
470
|
+
insertCopyAfter() {
|
|
471
|
+
const at = this.container.indexOf(this.element);
|
|
472
|
+
if (at < 0)
|
|
473
|
+
throw new Docx4JException('This content control is not in its container any more');
|
|
474
|
+
const copy = { name: this.element.name, value: deepCopy(this.element.value) };
|
|
475
|
+
this.container.splice(at + 1, 0, copy);
|
|
476
|
+
linkParents(copy, ownerOf(this.container, this.parentBody));
|
|
477
|
+
return new ContentControl(copy, this.container, this.parentBody);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Writes the control's text into the node it is bound to, when there is one and the XPath engine
|
|
481
|
+
* is warm. Silent when it is not: reading a custom XML part is `pkg.customXmlParts.load()`'s job,
|
|
482
|
+
* and `updateFromContentControls()` is the explicit form of this write.
|
|
483
|
+
*/
|
|
484
|
+
syncBoundNode() {
|
|
485
|
+
try {
|
|
486
|
+
if (this.xmlMapping.isMapped)
|
|
487
|
+
updateFromControl(this);
|
|
488
|
+
}
|
|
489
|
+
catch {
|
|
490
|
+
// the part is not parsed, or the engine is not ready: leave it to updateFromContentControls()
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
firstRunOfContent() {
|
|
494
|
+
var _a, _b, _c, _d;
|
|
495
|
+
const runs = this.form === 'Run' ? (_b = runItemsOf((_a = this.sdt.sdtContent) !== null && _a !== void 0 ? _a : {})) !== null && _b !== void 0 ? _b : [] : (_d = (_c = this.paragraphs[0]) === null || _c === void 0 ? void 0 : _c.runs) !== null && _d !== void 0 ? _d : [];
|
|
496
|
+
for (const item of runs)
|
|
497
|
+
if (typeNameOf(item) === 'org_docx4j_wml.R')
|
|
498
|
+
return item.value;
|
|
499
|
+
return undefined;
|
|
500
|
+
}
|
|
501
|
+
lockValue() {
|
|
502
|
+
var _a, _b;
|
|
503
|
+
return (_b = (_a = sdtProperty(this.sdt.sdtPr, 'lock')) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.val;
|
|
504
|
+
}
|
|
505
|
+
setLock(cannotDelete, cannotEdit) {
|
|
506
|
+
const val = cannotDelete && cannotEdit ? 'sdtContentLocked'
|
|
507
|
+
: cannotDelete ? 'sdtLocked'
|
|
508
|
+
: cannotEdit ? 'contentLocked'
|
|
509
|
+
: undefined;
|
|
510
|
+
if (val === undefined) {
|
|
511
|
+
this.removeProperty('lock');
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
this.putProperty(el.lock({ val }));
|
|
515
|
+
}
|
|
516
|
+
/** The table a row-level or cell-level control belongs to. */
|
|
517
|
+
ancestorTable() {
|
|
518
|
+
var _a;
|
|
519
|
+
let current = this.element.value.PARENT;
|
|
520
|
+
for (let guard = 0; current && guard < 8; guard++) {
|
|
521
|
+
if (typeNameOf(current) === 'org_docx4j_wml.Tbl') {
|
|
522
|
+
const tbl = current;
|
|
523
|
+
const container = childrenOf(((_a = tbl.PARENT) !== null && _a !== void 0 ? _a : {}));
|
|
524
|
+
const element = container === null || container === void 0 ? void 0 : container.find((e) => e.value === tbl);
|
|
525
|
+
return element && container ? new Table(element, container, this.parentBody) : undefined;
|
|
526
|
+
}
|
|
527
|
+
current = current.PARENT;
|
|
528
|
+
}
|
|
529
|
+
return undefined;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/** Every content control under a list of block-level items, in document order, nested ones included. */
|
|
533
|
+
export function collectControls(items, body, out) {
|
|
534
|
+
var _a;
|
|
535
|
+
for (const element of items) {
|
|
536
|
+
const tn = typeNameOf(element);
|
|
537
|
+
if (tn === undefined)
|
|
538
|
+
continue;
|
|
539
|
+
if (SDT_TYPES.has(tn)) {
|
|
540
|
+
const control = new ContentControl(element, items, body);
|
|
541
|
+
out.push(control);
|
|
542
|
+
collectControls(control.content, body, out);
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
if (tn === 'org_docx4j_wml.P') {
|
|
546
|
+
collectRunControls(element.value, body, out);
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
if (tn === 'org_docx4j_wml.Tbl') {
|
|
550
|
+
collectInRows((_a = childrenOf(element.value)) !== null && _a !== void 0 ? _a : [], body, out);
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const children = childrenOf(element.value);
|
|
554
|
+
if (children)
|
|
555
|
+
collectControls(children, body, out);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
/** Row-level controls and the controls inside the rows of a table. */
|
|
559
|
+
function collectInRows(items, body, out) {
|
|
560
|
+
var _a;
|
|
561
|
+
for (const element of items) {
|
|
562
|
+
const tn = typeNameOf(element);
|
|
563
|
+
if (tn === undefined)
|
|
564
|
+
continue;
|
|
565
|
+
if (SDT_TYPES.has(tn)) {
|
|
566
|
+
const control = new ContentControl(element, items, body);
|
|
567
|
+
out.push(control);
|
|
568
|
+
collectInRows(control.content, body, out);
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
if (tn === 'org_docx4j_wml.Tr')
|
|
572
|
+
collectInCells((_a = childrenOf(element.value)) !== null && _a !== void 0 ? _a : [], body, out);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
/** Cell-level controls and the controls inside the cells of a row. */
|
|
576
|
+
function collectInCells(items, body, out) {
|
|
577
|
+
var _a;
|
|
578
|
+
for (const element of items) {
|
|
579
|
+
const tn = typeNameOf(element);
|
|
580
|
+
if (tn === undefined)
|
|
581
|
+
continue;
|
|
582
|
+
if (SDT_TYPES.has(tn)) {
|
|
583
|
+
const control = new ContentControl(element, items, body);
|
|
584
|
+
out.push(control);
|
|
585
|
+
collectInCells(control.content, body, out);
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
if (tn === 'org_docx4j_wml.Tc')
|
|
589
|
+
collectControls((_a = childrenOf(element.value)) !== null && _a !== void 0 ? _a : [], body, out);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
/** The run-level controls in a paragraph (or any run holder), in order, nested ones included. */
|
|
593
|
+
export function collectRunControls(holder, body, out) {
|
|
594
|
+
const items = runItemsOf(holder);
|
|
595
|
+
if (!items)
|
|
596
|
+
return;
|
|
597
|
+
for (const element of items) {
|
|
598
|
+
const tn = typeNameOf(element);
|
|
599
|
+
if (tn === undefined)
|
|
600
|
+
continue;
|
|
601
|
+
if (SDT_TYPES.has(tn)) {
|
|
602
|
+
const control = new ContentControl(element, items, body);
|
|
603
|
+
out.push(control);
|
|
604
|
+
collectRunControls(element.value, body, out);
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
if (tn !== 'org_docx4j_wml.R')
|
|
608
|
+
collectRunControls(element.value, body, out);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function paragraphElement(text) {
|
|
612
|
+
return el.p({ content: text === '' ? [] : [el.r({ content: [el.t({ value: text })] })] });
|
|
613
|
+
}
|
|
614
|
+
/** A `w:p` holding these run-level items (CR-002 phase E: the bound content of an empty control). */
|
|
615
|
+
function paragraphElementOf(runs) {
|
|
616
|
+
return el.p({ content: runs });
|
|
617
|
+
}
|
|
618
|
+
function ownerOf(container, body) {
|
|
619
|
+
var _a;
|
|
620
|
+
// the container is a live array of the body's tree; PARENT is set from whatever holds it
|
|
621
|
+
const seek = (value) => {
|
|
622
|
+
const children = childrenOf(value);
|
|
623
|
+
if (children === container)
|
|
624
|
+
return value;
|
|
625
|
+
if (!children)
|
|
626
|
+
return undefined;
|
|
627
|
+
for (const child of children) {
|
|
628
|
+
const v = child.value;
|
|
629
|
+
if (typeof v !== 'object' || v === null)
|
|
630
|
+
continue;
|
|
631
|
+
const found = seek(v);
|
|
632
|
+
if (found)
|
|
633
|
+
return found;
|
|
634
|
+
}
|
|
635
|
+
return undefined;
|
|
636
|
+
};
|
|
637
|
+
return (_a = seek(body.container)) !== null && _a !== void 0 ? _a : body.container;
|
|
638
|
+
}
|