@docx4j/core-ts 0.4.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.
Files changed (166) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +34 -3
  3. package/dist/html/convert.mjs +40 -15
  4. package/dist/html/elements.mjs +2 -1
  5. package/dist/model/color/ColorMath.d.mts +29 -0
  6. package/dist/model/color/ColorMath.mjs +146 -0
  7. package/dist/model/color/ColorTables.d.mts +6 -0
  8. package/dist/model/color/ColorTables.mjs +83 -0
  9. package/dist/model/color/DrawingMLColors.d.mts +52 -0
  10. package/dist/model/color/DrawingMLColors.mjs +374 -0
  11. package/dist/model/color/ResolvedColor.d.mts +36 -0
  12. package/dist/model/color/ResolvedColor.mjs +65 -0
  13. package/dist/model/color/SpreadsheetColors.d.mts +36 -0
  14. package/dist/model/color/SpreadsheetColors.mjs +84 -0
  15. package/dist/model/color/StyleFill.d.mts +28 -0
  16. package/dist/model/color/StyleFill.mjs +21 -0
  17. package/dist/model/color/ThemeColors.d.mts +86 -0
  18. package/dist/model/color/ThemeColors.mjs +304 -0
  19. package/dist/model/color/WordColors.d.mts +71 -0
  20. package/dist/model/color/WordColors.mjs +121 -0
  21. package/dist/model/color/index.d.mts +6 -0
  22. package/dist/model/color/index.mjs +30 -0
  23. package/dist/model/content/Body.d.mts +153 -19
  24. package/dist/model/content/Body.mjs +570 -131
  25. package/dist/model/content/Comment.d.mts +21 -3
  26. package/dist/model/content/Comment.mjs +202 -19
  27. package/dist/model/content/ContentControl.d.mts +197 -18
  28. package/dist/model/content/ContentControl.mjs +664 -95
  29. package/dist/model/content/Font.d.mts +67 -17
  30. package/dist/model/content/Font.mjs +114 -35
  31. package/dist/model/content/InlinePicture.d.mts +82 -7
  32. package/dist/model/content/InlinePicture.mjs +221 -28
  33. package/dist/model/content/List.mjs +13 -1
  34. package/dist/model/content/Paragraph.d.mts +213 -14
  35. package/dist/model/content/Paragraph.mjs +936 -100
  36. package/dist/model/content/Range.d.mts +242 -11
  37. package/dist/model/content/Range.mjs +975 -119
  38. package/dist/model/content/ResolvedView.d.mts +104 -0
  39. package/dist/model/content/ResolvedView.mjs +596 -0
  40. package/dist/model/content/Table.d.mts +29 -3
  41. package/dist/model/content/Table.mjs +109 -33
  42. package/dist/model/content/TrackedChange.d.mts +301 -16
  43. package/dist/model/content/TrackedChange.mjs +1284 -158
  44. package/dist/model/content/binder.d.mts +2 -1
  45. package/dist/model/content/binder.mjs +48 -1
  46. package/dist/model/content/comments.d.mts +20 -6
  47. package/dist/model/content/comments.mjs +67 -57
  48. package/dist/model/content/generalException.d.mts +18 -0
  49. package/dist/model/content/generalException.mjs +24 -0
  50. package/dist/model/content/index.d.mts +8 -3
  51. package/dist/model/content/index.mjs +7 -2
  52. package/dist/model/content/mathText.d.mts +21 -0
  53. package/dist/model/content/mathText.mjs +267 -0
  54. package/dist/model/content/officeText.d.mts +27 -0
  55. package/dist/model/content/officeText.mjs +74 -0
  56. package/dist/model/content/outline.d.mts +5 -0
  57. package/dist/model/content/outline.mjs +13 -0
  58. package/dist/model/content/placeholders.d.mts +110 -0
  59. package/dist/model/content/placeholders.mjs +253 -0
  60. package/dist/model/content/relationships.d.mts +30 -0
  61. package/dist/model/content/relationships.mjs +133 -0
  62. package/dist/model/content/search.d.mts +72 -0
  63. package/dist/model/content/search.mjs +204 -2
  64. package/dist/model/content/spanEdits.d.mts +159 -0
  65. package/dist/model/content/spanEdits.mjs +728 -0
  66. package/dist/model/content/story.d.mts +44 -0
  67. package/dist/model/content/story.mjs +92 -0
  68. package/dist/model/content/tableColumns.d.mts +1 -1
  69. package/dist/model/content/tableColumns.mjs +108 -80
  70. package/dist/model/content/tableRevisions.d.mts +11 -3
  71. package/dist/model/content/tableRevisions.mjs +72 -42
  72. package/dist/model/content/tableRules.d.mts +30 -0
  73. package/dist/model/content/tableRules.mjs +100 -0
  74. package/dist/model/content/textBoxes.d.mts +18 -0
  75. package/dist/model/content/textBoxes.mjs +105 -0
  76. package/dist/model/content/trackedChangeFilter.d.mts +39 -0
  77. package/dist/model/content/trackedChangeFilter.mjs +81 -0
  78. package/dist/model/content/tracking.d.mts +28 -0
  79. package/dist/model/content/tracking.mjs +149 -10
  80. package/dist/model/content/tree.d.mts +212 -13
  81. package/dist/model/content/tree.mjs +356 -35
  82. package/dist/model/customxml/CustomXmlPartCollection.d.mts +8 -0
  83. package/dist/model/customxml/CustomXmlPartCollection.mjs +34 -11
  84. package/dist/model/customxml/XmlMapping.d.mts +1 -1
  85. package/dist/model/customxml/XmlMapping.mjs +11 -0
  86. package/dist/model/customxml/bindings.d.mts +21 -2
  87. package/dist/model/customxml/bindings.mjs +76 -32
  88. package/dist/model/customxml/kinds.d.mts +8 -3
  89. package/dist/model/customxml/kinds.mjs +26 -5
  90. package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
  91. package/dist/model/customxml/picturePlaceholder.mjs +32 -0
  92. package/dist/model/customxml/pictures.d.mts +9 -5
  93. package/dist/model/customxml/pictures.mjs +31 -13
  94. package/dist/model/customxml/xhtml.mjs +8 -2
  95. package/dist/model/fonts/families.generated.mjs +2 -2
  96. package/dist/model/fonts/registry.mjs +7 -1
  97. package/dist/model/fonts/substitutions.generated.mjs +2 -2
  98. package/dist/model/fonts/themes.generated.mjs +1 -1
  99. package/dist/model/index.d.mts +2 -0
  100. package/dist/model/index.mjs +4 -0
  101. package/dist/model/listnumbering/Emulator.d.mts +37 -5
  102. package/dist/model/listnumbering/Emulator.mjs +63 -9
  103. package/dist/model/listnumbering/definitions.mjs +18 -0
  104. package/dist/model/properties/PropertyResolver.d.mts +87 -7
  105. package/dist/model/properties/PropertyResolver.mjs +197 -17
  106. package/dist/model/properties/catalogue.d.mts +32 -4
  107. package/dist/model/properties/catalogue.mjs +115 -36
  108. package/dist/model/properties/log.d.mts +1 -1
  109. package/dist/model/properties/log.mjs +5 -5
  110. package/dist/model/properties/table.d.mts +16 -2
  111. package/dist/model/properties/table.mjs +17 -5
  112. package/dist/model/text/Extractor.d.mts +289 -0
  113. package/dist/model/text/Extractor.mjs +2162 -0
  114. package/dist/model/text/LinkTargets.d.mts +45 -0
  115. package/dist/model/text/LinkTargets.mjs +170 -0
  116. package/dist/model/text/MarkdownExporter.d.mts +140 -0
  117. package/dist/model/text/MarkdownExporter.mjs +255 -0
  118. package/dist/model/text/PlainText.d.mts +29 -0
  119. package/dist/model/text/PlainText.mjs +539 -0
  120. package/dist/model/text/TextContext.d.mts +161 -0
  121. package/dist/model/text/TextContext.mjs +425 -0
  122. package/dist/model/text/TextOptions.d.mts +150 -0
  123. package/dist/model/text/TextOptions.mjs +278 -0
  124. package/dist/model/text/TextResult.d.mts +504 -0
  125. package/dist/model/text/TextResult.mjs +526 -0
  126. package/dist/model/text/Texts.d.mts +99 -0
  127. package/dist/model/text/Texts.mjs +187 -0
  128. package/dist/model/text/WmlToMarkdown.d.mts +120 -0
  129. package/dist/model/text/WmlToMarkdown.mjs +911 -0
  130. package/dist/model/text/commonmark.d.mts +121 -0
  131. package/dist/model/text/commonmark.mjs +655 -0
  132. package/dist/model/text/index.d.mts +7 -0
  133. package/dist/model/text/index.mjs +8 -0
  134. package/dist/model/text/normalize.d.mts +8 -0
  135. package/dist/model/text/normalize.mjs +13 -0
  136. package/dist/model/text/outline.d.mts +4 -0
  137. package/dist/model/text/outline.mjs +71 -0
  138. package/dist/office-js/fragment.d.mts +7 -5
  139. package/dist/office-js/fragment.mjs +63 -14
  140. package/dist/office-js/proxy.d.mts +8 -0
  141. package/dist/office-js/proxy.mjs +29 -0
  142. package/dist/office-js/run.mjs +2 -0
  143. package/dist/office-js/supported.generated.mjs +16 -0
  144. package/dist/office-js/toApiScript.mjs +21 -5
  145. package/dist/opc/Load.d.mts +9 -2
  146. package/dist/opc/Save.d.mts +17 -0
  147. package/dist/opc/Save.mjs +12 -2
  148. package/dist/opc/index.d.mts +3 -3
  149. package/dist/opc/index.mjs +2 -2
  150. package/dist/opc/mce/preprocessor.d.mts +88 -7
  151. package/dist/opc/mce/preprocessor.mjs +144 -37
  152. package/dist/opc/mce/understood.d.mts +34 -0
  153. package/dist/opc/mce/understood.mjs +55 -3
  154. package/dist/packages/OpcPackage.d.mts +20 -0
  155. package/dist/packages/OpcPackage.mjs +16 -3
  156. package/dist/packages/WordprocessingMLPackage.d.mts +77 -7
  157. package/dist/packages/WordprocessingMLPackage.mjs +242 -11
  158. package/dist/parts/DefaultXmlPart.mjs +2 -2
  159. package/dist/parts/Part.d.mts +10 -2
  160. package/dist/parts/XmlPart.d.mts +35 -32
  161. package/dist/parts/XmlPart.mjs +107 -107
  162. package/dist/parts/wml/comments.mjs +30 -0
  163. package/dist/parts/wml/index.mjs +12 -0
  164. package/dist/xml/dom.d.mts +7 -0
  165. package/dist/xml/dom.mjs +18 -0
  166. 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, textOf, rowsOf, cellsOf } from './tree.mjs';
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`), so `rows` is what Word shows.
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, this.rows.slice(rowIndex, rowIndex + rowCount));
156
+ markRowsDeleted(tracker, rows.map((row) => row.element), this.parentBody);
124
157
  return;
125
158
  }
126
- for (const row of rowsOf(this.tbl).slice(rowIndex, rowIndex + rowCount).reverse()) {
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
- 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((row) => cellsOf(row.element.value).length === 0))
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.rows);
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, as docx4j TextUtils (extension). */
235
+ /** The text of the table: a line per paragraph, each `Paragraph.text` (extension; CR-012 phase 4). */
197
236
  get text() {
198
- return textOf(this.tbl);
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
- /** The cell's text, a line per paragraph. */
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 textOf(this.tc);
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.clear();
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.tr);
485
- for (const cell of row.cells) {
486
- for (const paragraph of cell.paragraphs)
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
  }