@docx4j/core-ts 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +4 -0
- package/README.md +32 -4
- package/dist/html/convert.mjs +2 -1
- package/dist/html/elements.mjs +2 -1
- package/dist/model/color/ColorMath.d.mts +29 -0
- package/dist/model/color/ColorMath.mjs +146 -0
- package/dist/model/color/ColorTables.d.mts +6 -0
- package/dist/model/color/ColorTables.mjs +83 -0
- package/dist/model/color/DrawingMLColors.d.mts +52 -0
- package/dist/model/color/DrawingMLColors.mjs +374 -0
- package/dist/model/color/ResolvedColor.d.mts +36 -0
- package/dist/model/color/ResolvedColor.mjs +65 -0
- package/dist/model/color/SpreadsheetColors.d.mts +36 -0
- package/dist/model/color/SpreadsheetColors.mjs +84 -0
- package/dist/model/color/StyleFill.d.mts +28 -0
- package/dist/model/color/StyleFill.mjs +21 -0
- package/dist/model/color/ThemeColors.d.mts +86 -0
- package/dist/model/color/ThemeColors.mjs +304 -0
- package/dist/model/color/WordColors.d.mts +71 -0
- package/dist/model/color/WordColors.mjs +121 -0
- package/dist/model/color/index.d.mts +6 -0
- package/dist/model/color/index.mjs +30 -0
- package/dist/model/content/Body.d.mts +145 -23
- package/dist/model/content/Body.mjs +509 -141
- package/dist/model/content/Comment.d.mts +21 -3
- package/dist/model/content/Comment.mjs +195 -19
- package/dist/model/content/ContentControl.d.mts +197 -18
- package/dist/model/content/ContentControl.mjs +664 -95
- package/dist/model/content/Font.d.mts +67 -17
- package/dist/model/content/Font.mjs +114 -35
- package/dist/model/content/InlinePicture.d.mts +11 -0
- package/dist/model/content/InlinePicture.mjs +21 -1
- package/dist/model/content/List.mjs +3 -0
- package/dist/model/content/Paragraph.d.mts +189 -13
- package/dist/model/content/Paragraph.mjs +870 -74
- package/dist/model/content/Range.d.mts +227 -12
- package/dist/model/content/Range.mjs +785 -59
- package/dist/model/content/ResolvedView.d.mts +104 -0
- package/dist/model/content/ResolvedView.mjs +596 -0
- package/dist/model/content/Table.d.mts +29 -3
- package/dist/model/content/Table.mjs +109 -33
- package/dist/model/content/TrackedChange.d.mts +172 -13
- package/dist/model/content/TrackedChange.mjs +728 -167
- package/dist/model/content/comments.d.mts +20 -6
- package/dist/model/content/comments.mjs +67 -57
- package/dist/model/content/generalException.d.mts +18 -0
- package/dist/model/content/generalException.mjs +24 -0
- package/dist/model/content/index.d.mts +8 -3
- package/dist/model/content/index.mjs +7 -2
- package/dist/model/content/mathText.d.mts +21 -0
- package/dist/model/content/mathText.mjs +267 -0
- package/dist/model/content/officeText.d.mts +27 -0
- package/dist/model/content/officeText.mjs +74 -0
- package/dist/model/content/outline.d.mts +5 -0
- package/dist/model/content/outline.mjs +13 -0
- package/dist/model/content/placeholders.d.mts +110 -0
- package/dist/model/content/placeholders.mjs +253 -0
- package/dist/model/content/search.d.mts +72 -0
- package/dist/model/content/search.mjs +204 -2
- package/dist/model/content/spanEdits.d.mts +159 -0
- package/dist/model/content/spanEdits.mjs +728 -0
- package/dist/model/content/story.d.mts +44 -0
- package/dist/model/content/story.mjs +92 -0
- package/dist/model/content/tableColumns.d.mts +1 -1
- package/dist/model/content/tableColumns.mjs +108 -80
- package/dist/model/content/tableRevisions.d.mts +11 -3
- package/dist/model/content/tableRevisions.mjs +72 -42
- package/dist/model/content/tableRules.d.mts +30 -0
- package/dist/model/content/tableRules.mjs +100 -0
- package/dist/model/content/textBoxes.d.mts +18 -0
- package/dist/model/content/textBoxes.mjs +105 -0
- package/dist/model/content/trackedChangeFilter.d.mts +39 -0
- package/dist/model/content/trackedChangeFilter.mjs +81 -0
- package/dist/model/content/tracking.d.mts +28 -0
- package/dist/model/content/tracking.mjs +149 -10
- package/dist/model/content/tree.d.mts +171 -22
- package/dist/model/content/tree.mjs +329 -53
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +8 -0
- package/dist/model/customxml/CustomXmlPartCollection.mjs +34 -11
- package/dist/model/customxml/XmlMapping.d.mts +1 -1
- package/dist/model/customxml/XmlMapping.mjs +11 -0
- package/dist/model/customxml/bindings.d.mts +21 -2
- package/dist/model/customxml/bindings.mjs +76 -32
- package/dist/model/customxml/kinds.d.mts +8 -3
- package/dist/model/customxml/kinds.mjs +26 -5
- package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
- package/dist/model/customxml/picturePlaceholder.mjs +32 -0
- package/dist/model/customxml/pictures.d.mts +4 -3
- package/dist/model/customxml/pictures.mjs +18 -6
- package/dist/model/customxml/xhtml.mjs +8 -2
- package/dist/model/index.d.mts +2 -0
- package/dist/model/index.mjs +4 -0
- package/dist/model/listnumbering/Emulator.d.mts +37 -5
- package/dist/model/listnumbering/Emulator.mjs +63 -9
- package/dist/model/properties/PropertyResolver.d.mts +60 -1
- package/dist/model/properties/PropertyResolver.mjs +115 -2
- package/dist/model/properties/catalogue.d.mts +19 -5
- package/dist/model/properties/catalogue.mjs +41 -15
- package/dist/model/properties/log.d.mts +1 -1
- package/dist/model/properties/log.mjs +5 -5
- package/dist/model/properties/table.mjs +4 -2
- package/dist/model/text/Extractor.d.mts +289 -0
- package/dist/model/text/Extractor.mjs +2162 -0
- package/dist/model/text/LinkTargets.d.mts +45 -0
- package/dist/model/text/LinkTargets.mjs +170 -0
- package/dist/model/text/MarkdownExporter.d.mts +140 -0
- package/dist/model/text/MarkdownExporter.mjs +255 -0
- package/dist/model/text/PlainText.d.mts +29 -0
- package/dist/model/text/PlainText.mjs +539 -0
- package/dist/model/text/TextContext.d.mts +161 -0
- package/dist/model/text/TextContext.mjs +425 -0
- package/dist/model/text/TextOptions.d.mts +150 -0
- package/dist/model/text/TextOptions.mjs +278 -0
- package/dist/model/text/TextResult.d.mts +504 -0
- package/dist/model/text/TextResult.mjs +526 -0
- package/dist/model/text/Texts.d.mts +99 -0
- package/dist/model/text/Texts.mjs +187 -0
- package/dist/model/text/WmlToMarkdown.d.mts +120 -0
- package/dist/model/text/WmlToMarkdown.mjs +911 -0
- package/dist/model/text/commonmark.d.mts +121 -0
- package/dist/model/text/commonmark.mjs +655 -0
- package/dist/model/text/index.d.mts +7 -0
- package/dist/model/text/index.mjs +8 -0
- package/dist/model/text/normalize.d.mts +8 -0
- package/dist/model/text/normalize.mjs +13 -0
- package/dist/model/text/outline.d.mts +4 -0
- package/dist/model/text/outline.mjs +71 -0
- package/dist/office-js/fragment.d.mts +7 -5
- package/dist/office-js/fragment.mjs +63 -14
- package/dist/office-js/proxy.d.mts +8 -0
- package/dist/office-js/proxy.mjs +29 -0
- package/dist/office-js/run.mjs +2 -0
- package/dist/office-js/supported.generated.mjs +16 -0
- package/dist/office-js/toApiScript.mjs +21 -5
- package/dist/opc/Save.d.mts +17 -0
- package/dist/opc/Save.mjs +12 -2
- package/dist/opc/index.d.mts +3 -3
- package/dist/opc/index.mjs +1 -1
- package/dist/opc/mce/preprocessor.d.mts +28 -3
- package/dist/opc/mce/preprocessor.mjs +4 -4
- package/dist/opc/mce/understood.d.mts +30 -6
- package/dist/opc/mce/understood.mjs +37 -7
- package/dist/packages/OpcPackage.d.mts +13 -0
- package/dist/packages/OpcPackage.mjs +1 -0
- package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
- package/dist/packages/WordprocessingMLPackage.mjs +155 -20
- package/dist/parts/DefaultXmlPart.mjs +2 -2
- package/dist/parts/Part.d.mts +10 -2
- package/dist/parts/XmlPart.d.mts +12 -30
- package/dist/parts/XmlPart.mjs +44 -93
- package/dist/parts/wml/comments.mjs +30 -0
- package/dist/parts/wml/index.mjs +12 -0
- package/dist/xml/dom.d.mts +7 -0
- package/dist/xml/dom.mjs +18 -0
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as el from '@docx4j/generated-objects-ts/el/org_docx4j_wml';
|
|
2
2
|
import { tr as rowOf } from '@docx4j/generated-objects-ts/builders/wml';
|
|
3
3
|
import { Docx4JException } from '../../opc/exceptions.mjs';
|
|
4
|
-
import { typeNameOf, childrenOf, linkParents,
|
|
4
|
+
import { typeNameOf, childrenOf, linkParents, rowsOf, cellsOf, inBranch, assertOutsideBranch } from './tree.mjs';
|
|
5
5
|
import { builtInOf, idOfBuiltIn, styleNameOf, styleIdOf } from './styles.mjs';
|
|
6
6
|
import { trackInsertedBlocks } from './tracking.mjs';
|
|
7
7
|
import { insertGridColumns, deleteGridColumns, gridRangeOf, textWidthTwips, widthTypeOf, layoutModeOf } from './tableColumns.mjs';
|
|
@@ -10,7 +10,9 @@ const DEFAULT_WIDTH = 9026;
|
|
|
10
10
|
const TWIPS_PER_POINT = 20;
|
|
11
11
|
/**
|
|
12
12
|
* A subset of Office JS `Word.Table` over a `w:tbl`. Rows are read through row-level content
|
|
13
|
-
* controls (an OpenDoPE repeat wraps its `w:tr` in a `w:sdt`),
|
|
13
|
+
* controls (an OpenDoPE repeat wraps its `w:tr` in a `w:sdt`), and through the selected branch of a
|
|
14
|
+
* kept row-level `mc:AlternateContent` (CR-013 phase 2), so `rows` is what Word shows. A table, row or
|
|
15
|
+
* cell in a branch is read-only (D4), and so is a write that would reach one.
|
|
14
16
|
*/
|
|
15
17
|
export class Table {
|
|
16
18
|
constructor(
|
|
@@ -32,17 +34,38 @@ export class Table {
|
|
|
32
34
|
return this.container.indexOf(this.element);
|
|
33
35
|
}
|
|
34
36
|
get rowCount() {
|
|
35
|
-
return rowsOf(this.tbl).length;
|
|
37
|
+
return rowsOf(this.tbl, 'read').length;
|
|
36
38
|
}
|
|
37
39
|
get rows() {
|
|
38
|
-
return rowsOf(this.tbl).map((r) => new TableRow(r.element, r.container, this));
|
|
40
|
+
return rowsOf(this.tbl, 'read').map((r) => new TableRow(r.element, r.container, this));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The table's range (Office JS `Table.getRange`; CR-014 phase 1): 'Whole' from its first cell's start to its
|
|
44
|
+
* last cell's end, its text the table's in `body.text`'s form, every row ended `\r\n` as Word 365 gives it
|
|
45
|
+
* (check 52); 'Start' and 'End' collapsed at those two ends, and 'After' at the start of the paragraph after
|
|
46
|
+
* the table.
|
|
47
|
+
*/
|
|
48
|
+
getRange(location = 'Whole') {
|
|
49
|
+
const paragraphs = this.rows.flatMap((row) => row.cells.flatMap((cell) => cell.paragraphs));
|
|
50
|
+
const first = paragraphs[0];
|
|
51
|
+
if (!first)
|
|
52
|
+
throw new Docx4JException('This table holds no paragraph');
|
|
53
|
+
const last = paragraphs[paragraphs.length - 1];
|
|
54
|
+
if (location === 'Start')
|
|
55
|
+
return first.getRange('Start');
|
|
56
|
+
if (location === 'End')
|
|
57
|
+
return last.getRange('End');
|
|
58
|
+
const whole = first.rangeTo(last, true, '\r\n');
|
|
59
|
+
return location === 'After' ? whole.getRange('After') : whole;
|
|
39
60
|
}
|
|
40
61
|
/** The text of every cell, row by row (Office JS values). */
|
|
41
62
|
get values() {
|
|
42
63
|
return this.rows.map((row) => row.values);
|
|
43
64
|
}
|
|
44
65
|
set values(values) {
|
|
66
|
+
this.assertWritable();
|
|
45
67
|
const rows = this.rows;
|
|
68
|
+
rows.slice(0, values.length).forEach((row, i) => row.assertValuesWritable(values[i].length)); // nothing written before a refusal
|
|
46
69
|
values.forEach((row, i) => { if (i < rows.length)
|
|
47
70
|
rows[i].values = row; });
|
|
48
71
|
}
|
|
@@ -52,6 +75,7 @@ export class Table {
|
|
|
52
75
|
return (_c = (_b = (_a = this.tbl.tblPr) === null || _a === void 0 ? void 0 : _a.tblStyle) === null || _b === void 0 ? void 0 : _b.val) !== null && _c !== void 0 ? _c : '';
|
|
53
76
|
}
|
|
54
77
|
set styleId(id) {
|
|
78
|
+
this.assertWritable();
|
|
55
79
|
if (id === '') {
|
|
56
80
|
if (this.tbl.tblPr)
|
|
57
81
|
delete this.tbl.tblPr.tblStyle;
|
|
@@ -83,6 +107,9 @@ export class Table {
|
|
|
83
107
|
return n;
|
|
84
108
|
}
|
|
85
109
|
set headerRowCount(count) {
|
|
110
|
+
this.assertWritable();
|
|
111
|
+
for (const row of this.rows)
|
|
112
|
+
row.assertWritable();
|
|
86
113
|
this.rows.forEach((row, i) => { row.isHeader = i < count; });
|
|
87
114
|
}
|
|
88
115
|
/** The cell at a row and cell index; throws when there is none, as Office JS's getCell does. */
|
|
@@ -99,13 +126,14 @@ export class Table {
|
|
|
99
126
|
addRows(location, rowCount, values) {
|
|
100
127
|
var _a;
|
|
101
128
|
var _b;
|
|
129
|
+
this.assertWritable();
|
|
102
130
|
const widths = this.columnWidths();
|
|
103
131
|
const added = [];
|
|
104
132
|
for (let i = 0; i < rowCount; i++)
|
|
105
133
|
added.push(rowElement(widths, values === null || values === void 0 ? void 0 : values[i]));
|
|
106
134
|
// New rows go into the table's own content, not into a row-level content control.
|
|
107
135
|
const container = ((_a = (_b = this.tbl).content) !== null && _a !== void 0 ? _a : (_b.content = []));
|
|
108
|
-
const first = rowsOf(this.tbl)[0];
|
|
136
|
+
const first = rowsOf(this.tbl, 'read')[0];
|
|
109
137
|
const at = location === 'Start' && first && first.container === container ? container.indexOf(first.element) : location === 'Start' ? 0 : container.length;
|
|
110
138
|
container.splice(at, 0, ...added);
|
|
111
139
|
for (const row of added)
|
|
@@ -118,12 +146,17 @@ export class Table {
|
|
|
118
146
|
* tracks changes the rows stay and take a `w:trPr/w:del` instead (CR-002 phase F).
|
|
119
147
|
*/
|
|
120
148
|
deleteRows(rowIndex, rowCount = 1) {
|
|
149
|
+
this.assertWritable();
|
|
150
|
+
// indices count the rows a reader sees; a row in a branch is not deleted from here (D4)
|
|
151
|
+
const rows = this.rows.slice(rowIndex, rowIndex + rowCount);
|
|
152
|
+
for (const row of rows)
|
|
153
|
+
row.assertWritable();
|
|
121
154
|
const tracker = this.changeTracker;
|
|
122
155
|
if (tracker) {
|
|
123
|
-
markRowsDeleted(tracker,
|
|
156
|
+
markRowsDeleted(tracker, rows.map((row) => row.element), this.parentBody);
|
|
124
157
|
return;
|
|
125
158
|
}
|
|
126
|
-
for (const row of
|
|
159
|
+
for (const row of rows.reverse()) {
|
|
127
160
|
const i = row.container.indexOf(row.element);
|
|
128
161
|
if (i >= 0)
|
|
129
162
|
row.container.splice(i, 1);
|
|
@@ -140,6 +173,7 @@ export class Table {
|
|
|
140
173
|
* table change is recorded as Office JS records one and the new cells' text is an insertion.
|
|
141
174
|
*/
|
|
142
175
|
addColumns(location, columnCount, values) {
|
|
176
|
+
this.assertWritable();
|
|
143
177
|
const at = location === 'Start' ? 0 : this.columnWidths().length;
|
|
144
178
|
const inserted = insertGridColumns(this.tbl, this.textWidth(), at, columnCount, values, this.changeTracker);
|
|
145
179
|
return this.cellViewsOf(inserted.cells);
|
|
@@ -152,8 +186,11 @@ export class Table {
|
|
|
152
186
|
*/
|
|
153
187
|
deleteColumns(columnIndex, columnCount = 1) {
|
|
154
188
|
var _a, _b, _c;
|
|
189
|
+
this.assertWritable();
|
|
155
190
|
deleteGridColumns(this.tbl, this.textWidth(), columnIndex, columnCount, this.changeTracker);
|
|
156
|
-
|
|
191
|
+
// a cell in any branch of a kept mc:AlternateContent keeps the table (CR-013 phase 2): counted outside
|
|
192
|
+
// the branches alone, a table whose cells were all in one went with them
|
|
193
|
+
if (((_c = (_b = (_a = this.tbl.tblGrid) === null || _a === void 0 ? void 0 : _a.gridCol) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) === 0 || rowsOf(this.tbl, 'every').every((row) => cellsOf(row.element.value, 'every').length === 0))
|
|
157
194
|
this.delete();
|
|
158
195
|
}
|
|
159
196
|
/** Which of Word's three layout modes the table is in: fixed, AutoFit to window, or AutoFit to contents (extension). */
|
|
@@ -176,9 +213,11 @@ export class Table {
|
|
|
176
213
|
}
|
|
177
214
|
/** Removes the table from its container; tracked, every row is marked deleted instead. */
|
|
178
215
|
delete() {
|
|
216
|
+
this.assertWritable();
|
|
179
217
|
const tracker = this.changeTracker;
|
|
218
|
+
// every branch's rows (CR-013 phase 3)
|
|
180
219
|
if (tracker) {
|
|
181
|
-
markRowsDeleted(tracker, this.
|
|
220
|
+
markRowsDeleted(tracker, rowsOf(this.tbl, 'every').map((row) => row.element), this.parentBody);
|
|
182
221
|
return;
|
|
183
222
|
}
|
|
184
223
|
const i = this.index;
|
|
@@ -193,9 +232,9 @@ export class Table {
|
|
|
193
232
|
get parentTableCell() {
|
|
194
233
|
return cellOf(this.tbl, this.parentBody);
|
|
195
234
|
}
|
|
196
|
-
/** The text of the table: a line per paragraph,
|
|
235
|
+
/** The text of the table: a line per paragraph, each `Paragraph.text` (extension; CR-012 phase 4). */
|
|
197
236
|
get text() {
|
|
198
|
-
return
|
|
237
|
+
return this.rows.flatMap((row) => row.cells.flatMap((cell) => cell.paragraphs)).map((p) => p.text).join('\n');
|
|
199
238
|
}
|
|
200
239
|
/** The column widths in twips, from the grid or from the first row (extension). */
|
|
201
240
|
columnWidths() {
|
|
@@ -203,8 +242,8 @@ export class Table {
|
|
|
203
242
|
const grid = (_a = this.tbl.tblGrid) === null || _a === void 0 ? void 0 : _a.gridCol;
|
|
204
243
|
if (grid && grid.length)
|
|
205
244
|
return grid.map((c) => { var _a; return (_a = c.w) !== null && _a !== void 0 ? _a : Math.floor(DEFAULT_WIDTH / grid.length); });
|
|
206
|
-
const first = rowsOf(this.tbl)[0];
|
|
207
|
-
const cells = first ? cellsOf(first.element.value) : [];
|
|
245
|
+
const first = rowsOf(this.tbl, 'read')[0];
|
|
246
|
+
const cells = first ? cellsOf(first.element.value, 'read') : [];
|
|
208
247
|
const n = Math.max(1, cells.length);
|
|
209
248
|
const each = Math.floor(DEFAULT_WIDTH / n);
|
|
210
249
|
return Array.from({ length: n }, (_, i) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = cells[i]) === null || _a === void 0 ? void 0 : _a.element.value.tcPr) === null || _b === void 0 ? void 0 : _b.tcW) === null || _c === void 0 ? void 0 : _c.w) !== null && _d !== void 0 ? _d : each; });
|
|
@@ -214,6 +253,14 @@ export class Table {
|
|
|
214
253
|
var _b;
|
|
215
254
|
return ((_a = (_b = this.tbl).tblPr) !== null && _a !== void 0 ? _a : (_b.tblPr = {}));
|
|
216
255
|
}
|
|
256
|
+
/** True for a table in the selected branch of a kept block-level `mc:AlternateContent` (CR-013 phase 2): read-only (D4). */
|
|
257
|
+
get inBranch() {
|
|
258
|
+
return inBranch(this.tbl);
|
|
259
|
+
}
|
|
260
|
+
/** Refuses a write to a table in a branch (CR-013 D4). Internal: the table's mutators call it first. */
|
|
261
|
+
assertWritable() {
|
|
262
|
+
assertOutsideBranch(this.tbl, 'Table');
|
|
263
|
+
}
|
|
217
264
|
}
|
|
218
265
|
/** A subset of Office JS `Word.TableRow` over a `w:tr`. */
|
|
219
266
|
export class TableRow {
|
|
@@ -229,19 +276,20 @@ export class TableRow {
|
|
|
229
276
|
}
|
|
230
277
|
/** The row's index among the table's rows. */
|
|
231
278
|
get rowIndex() {
|
|
232
|
-
return rowsOf(this.parentTable.tbl).findIndex((r) => r.element === this.element);
|
|
279
|
+
return rowsOf(this.parentTable.tbl, 'read').findIndex((r) => r.element === this.element);
|
|
233
280
|
}
|
|
234
281
|
get cellCount() {
|
|
235
|
-
return cellsOf(this.tr).length;
|
|
282
|
+
return cellsOf(this.tr, 'read').length;
|
|
236
283
|
}
|
|
237
284
|
get cells() {
|
|
238
|
-
return cellsOf(this.tr).map((c) => new TableCell(c.element, c.container, this));
|
|
285
|
+
return cellsOf(this.tr, 'read').map((c) => new TableCell(c.element, c.container, this));
|
|
239
286
|
}
|
|
240
287
|
/** The text of the row's cells. */
|
|
241
288
|
get values() {
|
|
242
289
|
return this.cells.map((c) => c.text);
|
|
243
290
|
}
|
|
244
291
|
set values(values) {
|
|
292
|
+
this.assertValuesWritable(values.length);
|
|
245
293
|
const cells = this.cells;
|
|
246
294
|
values.forEach((v, i) => { if (i < cells.length)
|
|
247
295
|
cells[i].value = v; });
|
|
@@ -254,6 +302,7 @@ export class TableRow {
|
|
|
254
302
|
set isHeader(header) {
|
|
255
303
|
var _a, _b, _c, _d;
|
|
256
304
|
var _e;
|
|
305
|
+
this.assertWritable();
|
|
257
306
|
const items = (_a = this.tr.trPr) === null || _a === void 0 ? void 0 : _a.cnfStyleOrDivIdOrGridBefore;
|
|
258
307
|
const at = (_b = items === null || items === void 0 ? void 0 : items.findIndex((i) => i.name.localPart === 'tblHeader')) !== null && _b !== void 0 ? _b : -1;
|
|
259
308
|
if (!header) {
|
|
@@ -269,6 +318,7 @@ export class TableRow {
|
|
|
269
318
|
/** New rows before or after this one, with this table's columns. */
|
|
270
319
|
insertRows(location, rowCount, values) {
|
|
271
320
|
var _a;
|
|
321
|
+
this.assertWritable();
|
|
272
322
|
const widths = this.parentTable.columnWidths();
|
|
273
323
|
const added = [];
|
|
274
324
|
for (let i = 0; i < rowCount; i++)
|
|
@@ -283,15 +333,30 @@ export class TableRow {
|
|
|
283
333
|
}
|
|
284
334
|
/** Removes the row; tracked, it stays and takes a `w:trPr/w:del` (CR-002 phase F). */
|
|
285
335
|
delete() {
|
|
336
|
+
this.assertWritable();
|
|
286
337
|
const tracker = this.parentTable.changeTracker;
|
|
287
338
|
if (tracker) {
|
|
288
|
-
markRowsDeleted(tracker, [this]);
|
|
339
|
+
markRowsDeleted(tracker, [this.element], this.parentTable.parentBody);
|
|
289
340
|
return;
|
|
290
341
|
}
|
|
291
342
|
const i = this.container.indexOf(this.element);
|
|
292
343
|
if (i >= 0)
|
|
293
344
|
this.container.splice(i, 1);
|
|
294
345
|
}
|
|
346
|
+
/** True for a row in a branch of a kept `mc:AlternateContent`, or in a table in one (CR-013 phase 2): read-only (D4). */
|
|
347
|
+
get inBranch() {
|
|
348
|
+
return inBranch(this.tr);
|
|
349
|
+
}
|
|
350
|
+
/** Refuses a write to a row in a branch (CR-013 D4). Internal. */
|
|
351
|
+
assertWritable() {
|
|
352
|
+
assertOutsideBranch(this.tr, 'TableRow');
|
|
353
|
+
}
|
|
354
|
+
/** Refuses `values` of `count` cells where the row, or one of those cells, is in a branch. Internal. */
|
|
355
|
+
assertValuesWritable(count) {
|
|
356
|
+
this.assertWritable();
|
|
357
|
+
for (const cell of this.cells.slice(0, count))
|
|
358
|
+
cell.assertWritable();
|
|
359
|
+
}
|
|
295
360
|
trPrItem(localPart) {
|
|
296
361
|
var _a, _b;
|
|
297
362
|
return (_b = (_a = this.tr.trPr) === null || _a === void 0 ? void 0 : _a.cnfStyleOrDivIdOrGridBefore) === null || _b === void 0 ? void 0 : _b.find((i) => i.name.localPart === localPart);
|
|
@@ -316,7 +381,7 @@ export class TableCell {
|
|
|
316
381
|
return this.parentRow.rowIndex;
|
|
317
382
|
}
|
|
318
383
|
get cellIndex() {
|
|
319
|
-
return cellsOf(this.parentRow.tr).findIndex((c) => c.element === this.element);
|
|
384
|
+
return cellsOf(this.parentRow.tr, 'read').findIndex((c) => c.element === this.element);
|
|
320
385
|
}
|
|
321
386
|
/**
|
|
322
387
|
* The cell's content as a `Body` (Office JS TableCell.body): the same part and package as the
|
|
@@ -333,16 +398,19 @@ export class TableCell {
|
|
|
333
398
|
get tables() {
|
|
334
399
|
return this.body.tables;
|
|
335
400
|
}
|
|
336
|
-
/**
|
|
401
|
+
/**
|
|
402
|
+
* The cell's text as Office JS's `tableCell.value` gives it: its body's text (`Body.text`), its paragraphs'
|
|
403
|
+
* `Paragraph.text` a mark `\r` apart (check 51: `value`, `values` and `body.text` alike).
|
|
404
|
+
*/
|
|
337
405
|
get text() {
|
|
338
|
-
return
|
|
406
|
+
return this.body.text;
|
|
339
407
|
}
|
|
340
408
|
/** Office JS TableCell.value: the text, replaced as one paragraph when set. */
|
|
341
409
|
get value() {
|
|
342
410
|
return this.text;
|
|
343
411
|
}
|
|
344
412
|
set value(text) {
|
|
345
|
-
this.body.
|
|
413
|
+
this.body.clearContent(false); // its own paragraph ends the cell (CR-002 section 55)
|
|
346
414
|
this.body.insertParagraph(text, 'End');
|
|
347
415
|
}
|
|
348
416
|
insertParagraph(text, location) {
|
|
@@ -365,6 +433,7 @@ export class TableCell {
|
|
|
365
433
|
set width(points) {
|
|
366
434
|
var _a, _b;
|
|
367
435
|
var _c, _d;
|
|
436
|
+
this.assertWritable();
|
|
368
437
|
const twips = Math.round(points * TWIPS_PER_POINT);
|
|
369
438
|
const tcW = ((_b = (_d = ((_a = (_c = this.tc).tcPr) !== null && _a !== void 0 ? _a : (_c.tcPr = {}))).tcW) !== null && _b !== void 0 ? _b : (_d.tcW = {}));
|
|
370
439
|
if (widthTypeOf(this.tc, this.parentTable.tbl) === 'pct') {
|
|
@@ -382,6 +451,7 @@ export class TableCell {
|
|
|
382
451
|
* row (extension).
|
|
383
452
|
*/
|
|
384
453
|
insertColumns(location, columnCount, values) {
|
|
454
|
+
this.assertWritable();
|
|
385
455
|
const range = gridRangeOf(this.parentRow.tr, this.tc);
|
|
386
456
|
if (!range)
|
|
387
457
|
throw new Docx4JException('This cell is not in its row');
|
|
@@ -391,11 +461,20 @@ export class TableCell {
|
|
|
391
461
|
}
|
|
392
462
|
/** Removes the grid columns this cell covers (Office JS `TableCell.deleteColumn`); tracked as `Table.deleteColumns` is. */
|
|
393
463
|
deleteColumn() {
|
|
464
|
+
this.assertWritable();
|
|
394
465
|
const range = gridRangeOf(this.parentRow.tr, this.tc);
|
|
395
466
|
if (!range)
|
|
396
467
|
throw new Docx4JException('This cell is not in its row');
|
|
397
468
|
this.parentTable.deleteColumns(range.start, range.end - range.start);
|
|
398
469
|
}
|
|
470
|
+
/** True for a cell in a branch of a kept `mc:AlternateContent`, or in a row or table in one (CR-013 phase 2): read-only (D4). */
|
|
471
|
+
get inBranch() {
|
|
472
|
+
return inBranch(this.tc);
|
|
473
|
+
}
|
|
474
|
+
/** Refuses a write to a cell in a branch (CR-013 D4); its body's writes refuse too. Internal. */
|
|
475
|
+
assertWritable() {
|
|
476
|
+
assertOutsideBranch(this.tc, 'TableCell');
|
|
477
|
+
}
|
|
399
478
|
/** Office JS TableCell.columnWidth, the same value. */
|
|
400
479
|
get columnWidth() {
|
|
401
480
|
return this.width;
|
|
@@ -452,11 +531,11 @@ export function cellOf(value, parentBody) {
|
|
|
452
531
|
if (!tblElement || !tblContainer)
|
|
453
532
|
return undefined;
|
|
454
533
|
const table = new Table(tblElement, tblContainer, parentBody);
|
|
455
|
-
const row = rowsOf(tbl).find((r) => r.element.value === tr);
|
|
534
|
+
const row = rowsOf(tbl, 'read').find((r) => r.element.value === tr);
|
|
456
535
|
if (!row)
|
|
457
536
|
return undefined;
|
|
458
537
|
const rowView = new TableRow(row.element, row.container, table);
|
|
459
|
-
const cell = cellsOf(tr).find((c) => c.element.value === tc);
|
|
538
|
+
const cell = cellsOf(tr, 'read').find((c) => c.element.value === tc);
|
|
460
539
|
return cell ? new TableCell(cell.element, cell.container, rowView) : undefined;
|
|
461
540
|
}
|
|
462
541
|
/** The w:tbl a row is in, through a row-level content control if there is one. */
|
|
@@ -479,15 +558,12 @@ function ancestorOf(value, typeName, depth) {
|
|
|
479
558
|
* with `w:delText` for its text, and every paragraph mark `w:pPr/w:rPr/w:del` (CR-002 section 13).
|
|
480
559
|
* The mirror of `markRowsInserted`. Rows of a nested table go the same way.
|
|
481
560
|
*/
|
|
482
|
-
function markRowsDeleted(tracker, rows) {
|
|
561
|
+
function markRowsDeleted(tracker, rows, parentBody) {
|
|
562
|
+
// every branch of a kept mc:AlternateContent among the cells and in them (CR-013 phase 3)
|
|
483
563
|
for (const row of rows.slice().reverse()) {
|
|
484
|
-
tracker.markRowDeleted(row.
|
|
485
|
-
for (const cell of row.
|
|
486
|
-
|
|
487
|
-
paragraph.markDeletedInPlace(tracker);
|
|
488
|
-
for (const nested of cell.tables)
|
|
489
|
-
markRowsDeleted(tracker, nested.rows);
|
|
490
|
-
}
|
|
564
|
+
tracker.markRowDeleted(row.value);
|
|
565
|
+
for (const cell of cellsOf(row.value, 'every'))
|
|
566
|
+
parentBody.sub(cell.element.value).markContentDeleted(tracker);
|
|
491
567
|
}
|
|
492
568
|
}
|
|
493
569
|
/** A new row is an insertion: `w:trPr/w:ins` on it and a `w:ins` around every run it holds. */
|
|
@@ -498,8 +574,8 @@ function markRowsInserted(tracker, rows) {
|
|
|
498
574
|
for (const row of rows) {
|
|
499
575
|
if (!((_a = row.value.trPr) === null || _a === void 0 ? void 0 : _a.ins))
|
|
500
576
|
tracker.markRowInserted(row.value);
|
|
501
|
-
// nested tables and block controls in a new row's cells too (CR-002 section 37)
|
|
502
|
-
for (const cell of cellsOf(row.value))
|
|
577
|
+
// nested tables and block controls in a new row's cells too (CR-002 section 37), in every branch
|
|
578
|
+
for (const cell of cellsOf(row.value, 'every'))
|
|
503
579
|
trackInsertedBlocks(tracker, childrenOf(cell.element.value));
|
|
504
580
|
}
|
|
505
581
|
}
|