superdoc 0.29.0-RC.1 → 0.29.0-RC.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/chunks/{PdfViewer-DOGqT5aX.es.js → PdfViewer-CH7xPqiQ.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-N5tA7e4Y.cjs → PdfViewer-Dlcx3g-l.cjs} +1 -1
  3. package/dist/chunks/{editor-B2o3f2Zc-1PF7k2LU.cjs → editor-EfXZ6xB6-Ckfqr3sG.cjs} +1672 -1663
  4. package/dist/chunks/{editor-B2o3f2Zc-B6yLcUx-.es.js → editor-EfXZ6xB6-VJn78MZE.es.js} +1672 -1663
  5. package/dist/chunks/{index-DQ-TaQYY.es.js → index-BTT4BNXs.es.js} +15 -4
  6. package/dist/chunks/{index-D0Jr4Zet.cjs → index-FikaCO2P.cjs} +29 -18
  7. package/dist/components/CommentsLayer/use-comment.d.ts.map +1 -1
  8. package/dist/core/types/index.d.ts.map +1 -1
  9. package/dist/stores/comments-store.d.ts.map +1 -1
  10. package/dist/super-editor/ai-writer.es.js +2 -2
  11. package/dist/super-editor/chunks/{converter-BY1BQynB.js → converter-BK9AD8UY.js} +1840 -1914
  12. package/dist/super-editor/chunks/{docx-zipper-I2NRno-n.js → docx-zipper-QhU8I-YW.js} +1 -1
  13. package/dist/super-editor/chunks/{editor-B2o3f2Zc.js → editor-EfXZ6xB6.js} +88 -5
  14. package/dist/super-editor/chunks/{super-input-zEOSF0Zl.js → super-input-DWpAmOmi.js} +3 -3
  15. package/dist/super-editor/converter.es.js +1 -1
  16. package/dist/super-editor/docx-zipper.es.js +2 -2
  17. package/dist/super-editor/editor.es.js +3 -3
  18. package/dist/super-editor/file-zipper.es.js +1 -1
  19. package/dist/super-editor/super-editor/src/core/commands/getSelectionMarks.d.ts +1 -0
  20. package/dist/super-editor/super-editor/src/core/commands/index.d.ts +2 -0
  21. package/dist/super-editor/super-editor/src/core/commands/setTextSelection.d.ts +4 -0
  22. package/dist/super-editor/super-editor/src/core/super-converter/v2/importer/tableImporter.d.ts +0 -16
  23. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/tc/helpers/legacy-handle-table-cell-node.d.ts +1 -1
  24. package/dist/super-editor/super-editor/src/extensions/comment/comments-plugin.d.ts +2 -1
  25. package/dist/super-editor/super-editor.es.js +4 -4
  26. package/dist/super-editor/toolbar.es.js +1 -1
  27. package/dist/super-editor.cjs +26 -26
  28. package/dist/super-editor.es.js +1 -1
  29. package/dist/superdoc.cjs +13 -13
  30. package/dist/superdoc.es.js +2 -2
  31. package/dist/superdoc.umd.js +1685 -1665
  32. package/dist/superdoc.umd.js.map +1 -1
  33. package/package.json +4 -1
@@ -15270,6 +15270,9 @@ const getArrayBufferFromUrl = async (input) => {
15270
15270
  const view = input;
15271
15271
  return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
15272
15272
  }
15273
+ if (typeof Blob !== "undefined" && input instanceof Blob) {
15274
+ return await input.arrayBuffer();
15275
+ }
15273
15276
  if (typeof input !== "string") {
15274
15277
  throw new TypeError("Unsupported media input type");
15275
15278
  }
@@ -15396,13 +15399,9 @@ const deobfuscateFont = (arrayBuffer, guidHex) => {
15396
15399
  return dta.buffer;
15397
15400
  };
15398
15401
  function generateDocxRandomId(length2 = 8) {
15399
- const characters = "0123456789abcdef";
15400
- let id = [];
15401
- for (let i = 0; i < length2; i++) {
15402
- const randomIndex = Math.floor(Math.random() * characters.length);
15403
- id.push(characters[randomIndex]);
15404
- }
15405
- return id.join("");
15402
+ const max2 = 2147483647;
15403
+ const value = Math.floor(Math.random() * (max2 + 1));
15404
+ return value.toString(16).padStart(length2, "0").slice(0, length2);
15406
15405
  }
15407
15406
  function generateRandomSigned32BitIntStrId() {
15408
15407
  const val = Math.floor(Math.random() * 2147483647);
@@ -27013,53 +27012,7 @@ const config$h = {
27013
27012
  attributes: validXmlAttributes$c
27014
27013
  };
27015
27014
  const translator$1b = NodeTranslator.from(config$h);
27016
- function preProcessVerticalMergeCells(table, { editorSchema }) {
27017
- if (!table || !Array.isArray(table.content)) {
27018
- return table;
27019
- }
27020
- const rows = table.content;
27021
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
27022
- const row = rows[rowIndex];
27023
- if (!row) continue;
27024
- if (!Array.isArray(row.content)) {
27025
- row.content = [];
27026
- }
27027
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
27028
- const cell = row.content[cellIndex];
27029
- if (!cell) continue;
27030
- const attrs = cell.attrs || {};
27031
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
27032
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
27033
- for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
27034
- const rowToChange = rows[rowIndex + offset2];
27035
- if (!rowToChange) continue;
27036
- if (!Array.isArray(rowToChange.content)) {
27037
- rowToChange.content = [];
27038
- }
27039
- const existingCell = rowToChange.content[cellIndex];
27040
- if (existingCell?.attrs?.continueMerge) continue;
27041
- const mergedCell = {
27042
- type: cell.type,
27043
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
27044
- attrs: {
27045
- ...cell.attrs,
27046
- rowspan: null,
27047
- continueMerge: true
27048
- }
27049
- };
27050
- rowToChange.content.splice(cellIndex, 0, mergedCell);
27051
- }
27052
- }
27053
- }
27054
- return table;
27055
- }
27056
27015
  const translator$1a = NodeTranslator.from({
27057
- xmlName: "w:cantSplit",
27058
- sdNodeOrKeyName: "cantSplit",
27059
- encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
27060
- decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
27061
- });
27062
- const translator$19 = NodeTranslator.from({
27063
27016
  xmlName: "w:cnfStyle",
27064
27017
  sdNodeOrKeyName: "cnfStyle",
27065
27018
  attributes: [
@@ -27085,299 +27038,7 @@ const translator$19 = NodeTranslator.from({
27085
27038
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27086
27039
  }
27087
27040
  });
27088
- const translator$18 = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
27089
- const translator$17 = NodeTranslator.from(
27090
- createSingleAttrPropertyHandler(
27091
- "w:gridAfter",
27092
- null,
27093
- "w:val",
27094
- (v2) => parseInteger(v2) ?? void 0,
27095
- (v2) => integerToString(v2)
27096
- )
27097
- );
27098
- const translator$16 = NodeTranslator.from(
27099
- createSingleAttrPropertyHandler(
27100
- "w:gridBefore",
27101
- null,
27102
- "w:val",
27103
- (v2) => parseInteger(v2) ?? void 0,
27104
- (v2) => integerToString(v2)
27105
- )
27106
- );
27107
- const translator$15 = NodeTranslator.from({
27108
- xmlName: "w:hidden",
27109
- sdNodeOrKeyName: "hidden",
27110
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27111
- decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
27112
- });
27113
- const translator$14 = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
27114
- const translator$13 = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
27115
- const translator$12 = NodeTranslator.from({
27116
- xmlName: "w:tblHeader",
27117
- sdNodeOrKeyName: "repeatHeader",
27118
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27119
- decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
27120
- });
27121
- const translator$11 = NodeTranslator.from({
27122
- xmlName: "w:trHeight",
27123
- sdNodeOrKeyName: "rowHeight",
27124
- encode: ({ nodes }) => {
27125
- const heightAttrs = {};
27126
- const val = nodes[0].attributes["w:val"];
27127
- if (val) {
27128
- heightAttrs["value"] = parseInt(val, 10);
27129
- }
27130
- const rule = nodes[0].attributes["w:hRule"];
27131
- if (rule) {
27132
- heightAttrs["rule"] = rule;
27133
- }
27134
- return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
27135
- },
27136
- decode: ({ node }) => {
27137
- if (!node.attrs?.rowHeight) return;
27138
- const heightAttrs = {};
27139
- if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
27140
- heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
27141
- }
27142
- if (node.attrs.rowHeight.rule) {
27143
- heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
27144
- }
27145
- return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
27146
- }
27147
- });
27148
- const translator$10 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
27149
- const translator$$ = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
27150
- const propertyTranslators$6 = [
27151
- translator$1a,
27152
- translator$19,
27153
- translator$18,
27154
- translator$17,
27155
- translator$16,
27156
- translator$15,
27157
- translator$14,
27158
- translator$13,
27159
- translator$12,
27160
- translator$11,
27161
- translator$10,
27162
- translator$$
27163
- ];
27164
- const translator$_ = NodeTranslator.from(
27165
- createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$6, {
27166
- cantSplit: false,
27167
- hidden: false,
27168
- repeatHeader: false
27169
- })
27170
- );
27171
- const createPlaceholderCell = (gridWidth, reason) => {
27172
- const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
27173
- const noBorder = { val: "none", size: 0 };
27174
- return {
27175
- type: "tableCell",
27176
- attrs: {
27177
- colspan: 1,
27178
- rowspan: 1,
27179
- colwidth: [safeWidth],
27180
- __placeholder: reason,
27181
- borders: {
27182
- top: { ...noBorder },
27183
- right: { ...noBorder },
27184
- bottom: { ...noBorder },
27185
- left: { ...noBorder }
27186
- }
27187
- },
27188
- content: [{ type: "paragraph", content: [] }]
27189
- };
27190
- };
27191
- const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
27192
- let index2 = startIndex;
27193
- while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
27194
- pendingRowSpans[index2] -= 1;
27195
- index2 += 1;
27196
- }
27197
- return index2;
27198
- };
27199
- const fillPlaceholderColumns = ({
27200
- content,
27201
- pendingRowSpans,
27202
- currentIndex,
27203
- targetIndex,
27204
- totalColumns,
27205
- gridColumnWidths,
27206
- reason
27207
- }) => {
27208
- let index2 = currentIndex;
27209
- while (index2 < targetIndex && index2 < totalColumns) {
27210
- if (pendingRowSpans[index2] > 0) {
27211
- pendingRowSpans[index2] -= 1;
27212
- index2 += 1;
27213
- continue;
27214
- }
27215
- const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
27216
- content.push(createPlaceholderCell(width, reason));
27217
- index2 += 1;
27218
- }
27219
- return index2;
27220
- };
27221
- const isPlaceholderCell = (cell) => {
27222
- if (!cell) return false;
27223
- if (cell.attrs?.__placeholder) return true;
27224
- const widths = cell.attrs?.colwidth;
27225
- if (Array.isArray(widths) && widths.length > 0) {
27226
- const hasMeaningfulWidth = widths.some(
27227
- (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
27228
- );
27229
- if (!hasMeaningfulWidth) return true;
27230
- }
27231
- return false;
27232
- };
27233
- const XML_NODE_NAME$h = "w:tr";
27234
- const SD_NODE_NAME$d = "tableRow";
27235
- const validXmlAttributes$b = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
27236
- (xmlName) => createAttributeHandler(xmlName)
27237
- );
27238
- const encode$n = (params2, encodedAttrs) => {
27239
- const { row } = params2.extraParams;
27240
- let tableRowProperties = {};
27241
- const tPr = row.elements.find((el) => el.name === "w:trPr");
27242
- if (tPr) {
27243
- tableRowProperties = translator$_.encode({
27244
- ...params2,
27245
- nodes: [tPr]
27246
- });
27247
- }
27248
- const gridBeforeRaw = tableRowProperties?.["gridBefore"];
27249
- const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
27250
- encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
27251
- encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
27252
- encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
27253
- const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params2.extraParams;
27254
- const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
27255
- const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
27256
- while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
27257
- const cellNodes = row.elements.filter((el) => el.name === "w:tc");
27258
- const content = [];
27259
- let currentColumnIndex = 0;
27260
- const fillUntil = (target, reason) => {
27261
- currentColumnIndex = fillPlaceholderColumns({
27262
- content,
27263
- pendingRowSpans,
27264
- currentIndex: currentColumnIndex,
27265
- targetIndex: target,
27266
- totalColumns,
27267
- gridColumnWidths,
27268
- reason
27269
- });
27270
- };
27271
- const skipOccupiedColumns = () => {
27272
- currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
27273
- };
27274
- fillUntil(safeGridBefore, "gridBefore");
27275
- skipOccupiedColumns();
27276
- cellNodes?.forEach((node) => {
27277
- skipOccupiedColumns();
27278
- const startColumn = currentColumnIndex;
27279
- const columnWidth = gridColumnWidths?.[startColumn] || null;
27280
- const result = translator$c.encode({
27281
- ...params2,
27282
- extraParams: {
27283
- ...params2.extraParams,
27284
- node,
27285
- columnIndex: startColumn,
27286
- columnWidth
27287
- }
27288
- });
27289
- if (result) {
27290
- content.push(result);
27291
- const colspan = Math.max(1, result.attrs?.colspan || 1);
27292
- const rowspan = Math.max(1, result.attrs?.rowspan || 1);
27293
- if (rowspan > 1) {
27294
- for (let offset2 = 0; offset2 < colspan; offset2 += 1) {
27295
- const target = startColumn + offset2;
27296
- if (target < pendingRowSpans.length) {
27297
- pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
27298
- }
27299
- }
27300
- }
27301
- currentColumnIndex = startColumn + colspan;
27302
- }
27303
- });
27304
- skipOccupiedColumns();
27305
- fillUntil(totalColumns, "gridAfter");
27306
- const newNode = {
27307
- type: "tableRow",
27308
- content,
27309
- attrs: encodedAttrs
27310
- };
27311
- return newNode;
27312
- };
27313
- const decode$p = (params2, decodedAttrs) => {
27314
- const { node } = params2;
27315
- const cells = node.content || [];
27316
- let leadingPlaceholders = 0;
27317
- while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
27318
- leadingPlaceholders += 1;
27319
- }
27320
- let trailingPlaceholders = 0;
27321
- while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
27322
- trailingPlaceholders += 1;
27323
- }
27324
- const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
27325
- const sanitizedCells = trimmedSlice.map((cell) => {
27326
- if (cell?.attrs && "__placeholder" in cell.attrs) {
27327
- const { __placeholder, ...rest } = cell.attrs;
27328
- return { ...cell, attrs: rest };
27329
- }
27330
- return cell;
27331
- });
27332
- const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
27333
- const translateParams = {
27334
- ...params2,
27335
- node: { ...node, content: trimmedContent }
27336
- };
27337
- const elements = translateChildNodes(translateParams);
27338
- if (node.attrs?.tableRowProperties) {
27339
- const tableRowProperties = { ...node.attrs.tableRowProperties };
27340
- if (leadingPlaceholders > 0) {
27341
- tableRowProperties.gridBefore = leadingPlaceholders;
27342
- }
27343
- if (trailingPlaceholders > 0) {
27344
- tableRowProperties.gridAfter = trailingPlaceholders;
27345
- }
27346
- if (node.attrs.rowHeight != null) {
27347
- const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
27348
- if (rowHeightPixels !== node.attrs.rowHeight) {
27349
- tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
27350
- }
27351
- }
27352
- tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
27353
- const trPr = translator$_.decode({
27354
- ...params2,
27355
- node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
27356
- });
27357
- if (trPr) elements.unshift(trPr);
27358
- }
27359
- return {
27360
- name: "w:tr",
27361
- attributes: decodedAttrs || {},
27362
- elements
27363
- };
27364
- };
27365
- const config$g = {
27366
- xmlName: XML_NODE_NAME$h,
27367
- sdNodeOrKeyName: SD_NODE_NAME$d,
27368
- type: NodeTranslator.translatorTypes.NODE,
27369
- encode: encode$n,
27370
- decode: decode$p,
27371
- attributes: validXmlAttributes$b
27372
- };
27373
- const translator$Z = NodeTranslator.from(config$g);
27374
- const translator$Y = NodeTranslator.from({
27375
- xmlName: "w:bidiVisual",
27376
- sdNodeOrKeyName: "rightToLeft",
27377
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27378
- decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
27379
- });
27380
- const translator$X = NodeTranslator.from({
27041
+ const translator$19 = NodeTranslator.from({
27381
27042
  xmlName: "w:shd",
27382
27043
  sdNodeOrKeyName: "shading",
27383
27044
  attributes: [
@@ -27399,895 +27060,284 @@ const translator$X = NodeTranslator.from({
27399
27060
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27400
27061
  }
27401
27062
  });
27402
- const translator$W = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
27403
- const translator$V = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
27404
- const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
27405
- const translator$T = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
27406
- const translator$S = NodeTranslator.from({
27407
- xmlName: "w:tblLook",
27408
- sdNodeOrKeyName: "tblLook",
27409
- attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
27410
- encode: (params2, encodedAttrs) => {
27411
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27412
- },
27413
- decode: function({ node }, context) {
27414
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
27415
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27416
- }
27417
- });
27418
- const translator$R = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
27419
- const translator$Q = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
27420
- const translator$P = NodeTranslator.from(
27421
- createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
27422
- );
27423
- const translator$O = NodeTranslator.from(
27424
- createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
27063
+ const translator$18 = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
27064
+ const translator$17 = NodeTranslator.from(
27065
+ createSingleAttrPropertyHandler(
27066
+ "w:gridSpan",
27067
+ null,
27068
+ "w:val",
27069
+ (v2) => parseInteger(v2) ?? void 0,
27070
+ (v2) => integerToString(v2)
27071
+ )
27425
27072
  );
27426
- const translator$N = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
27427
- const translator$M = NodeTranslator.from({
27428
- xmlName: "w:tblpPr",
27429
- sdNodeOrKeyName: "floatingTableProperties",
27430
- attributes: ["w:leftFromText", "w:rightFromText", "w:topFromText", "w:bottomFromText", "w:tblpX", "w:tblpY"].map((attr) => createAttributeHandler(attr, null, parseInteger, integerToString)).concat(["w:horzAnchor", "w:vertAnchor", "w:tblpXSpec", "w:tblpYSpec"].map((attr) => createAttributeHandler(attr))),
27431
- encode: (params2, encodedAttrs) => {
27432
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27433
- },
27434
- decode: function({ node }, context) {
27435
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
27436
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27437
- }
27438
- });
27439
- const translator$L = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
27440
- const translator$K = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
27441
- const translator$J = NodeTranslator.from(createBorderPropertyHandler("w:end"));
27442
- const translator$I = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
27443
- const translator$H = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
27444
- const translator$G = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
27445
- const translator$F = NodeTranslator.from(createBorderPropertyHandler("w:left"));
27446
- const translator$E = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
27447
- const translator$D = NodeTranslator.from(createBorderPropertyHandler("w:right"));
27448
- const translator$C = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
27449
- const translator$B = NodeTranslator.from(createBorderPropertyHandler("w:start"));
27450
- const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
27451
- const translator$z = NodeTranslator.from(createBorderPropertyHandler("w:top"));
27452
- const translator$y = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
27453
- const propertyTranslators$5 = [
27454
- translator$L,
27455
- translator$J,
27456
- translator$H,
27457
- translator$G,
27458
- translator$F,
27459
- translator$D,
27460
- translator$B,
27461
- translator$z
27073
+ const translator$16 = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
27074
+ const translator$15 = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
27075
+ const translator$14 = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
27076
+ const translator$13 = NodeTranslator.from(createBorderPropertyHandler("w:end"));
27077
+ const translator$12 = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
27078
+ const translator$11 = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
27079
+ const translator$10 = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
27080
+ const translator$$ = NodeTranslator.from(createBorderPropertyHandler("w:left"));
27081
+ const translator$_ = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
27082
+ const translator$Z = NodeTranslator.from(createBorderPropertyHandler("w:right"));
27083
+ const translator$Y = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
27084
+ const translator$X = NodeTranslator.from(createBorderPropertyHandler("w:start"));
27085
+ const translator$W = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
27086
+ const translator$V = NodeTranslator.from(createBorderPropertyHandler("w:top"));
27087
+ const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
27088
+ const translator$T = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
27089
+ const translator$S = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
27090
+ const propertyTranslators$6 = [
27091
+ translator$V,
27092
+ translator$X,
27093
+ translator$$,
27094
+ translator$15,
27095
+ translator$13,
27096
+ translator$Z,
27097
+ translator$11,
27098
+ translator$10,
27099
+ translator$T,
27100
+ translator$S
27462
27101
  ];
27463
- const translator$x = NodeTranslator.from(
27464
- createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$5)
27102
+ const translator$R = NodeTranslator.from(
27103
+ createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$6)
27465
27104
  );
27466
- const propertyTranslators$4 = [
27467
- translator$K,
27468
- translator$I,
27469
- translator$E,
27470
- translator$C,
27471
- translator$A,
27472
- translator$y
27473
- ];
27474
- const translator$w = NodeTranslator.from(
27475
- createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$4)
27105
+ const translator$Q = NodeTranslator.from(
27106
+ createSingleAttrPropertyHandler(
27107
+ "w:noWrap",
27108
+ null,
27109
+ "w:val",
27110
+ (v2) => parseBoolean(v2 ?? "true"),
27111
+ (v2) => booleanToString(v2)
27112
+ )
27476
27113
  );
27477
- const propertyTranslators$3 = [
27478
- translator$Y,
27114
+ const propertyTranslators$5 = [
27479
27115
  translator$14,
27480
- translator$X,
27116
+ translator$12,
27117
+ translator$_,
27118
+ translator$Y,
27481
27119
  translator$W,
27482
- translator$13,
27483
- translator$V,
27484
- translator$U,
27485
- translator$T,
27486
- translator$S,
27487
- translator$R,
27488
- translator$Q,
27489
- translator$P,
27490
- translator$O,
27491
- translator$N,
27492
- translator$M,
27493
- translator$x,
27494
- translator$w
27120
+ translator$U
27495
27121
  ];
27496
- const translator$v = NodeTranslator.from(
27497
- createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators$3)
27122
+ const translator$P = NodeTranslator.from(
27123
+ createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$5)
27498
27124
  );
27499
- const translator$u = NodeTranslator.from(
27500
- createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
27125
+ const translator$O = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
27126
+ const translator$N = NodeTranslator.from(
27127
+ createSingleAttrPropertyHandler(
27128
+ "w:tcFitText",
27129
+ null,
27130
+ "w:val",
27131
+ (v2) => parseBoolean(v2 ?? "true"),
27132
+ (v2) => booleanToString(v2)
27133
+ )
27501
27134
  );
27502
- const DEFAULT_COLUMN_WIDTH_PX = 100;
27503
- const normalizeTwipWidth = (value) => {
27504
- if (value == null) return null;
27505
- const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
27506
- if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
27507
- return null;
27508
- }
27509
- return numericValue;
27510
- };
27511
- const getSchemaDefaultColumnWidthPx = (params2) => {
27512
- const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
27513
- if (Array.isArray(defaultValue)) {
27514
- const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
27515
- if (numericWidth != null) return numericWidth;
27516
- } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
27517
- return defaultValue;
27518
- }
27519
- return DEFAULT_COLUMN_WIDTH_PX;
27520
- };
27521
- const getTableWidthPx = (params2) => {
27522
- const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
27523
- if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
27524
- const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
27525
- if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
27526
- const { value, type: type2 } = tableWidth;
27527
- if (!type2 || type2 === "auto" || type2 === "dxa") {
27528
- return twipsToPixels(value);
27529
- }
27530
- }
27531
- return null;
27532
- };
27533
- const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
27534
- const columnCount = Math.max(totalColumns, 1);
27535
- const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
27536
- const tableWidthPx = getTableWidthPx(params2);
27537
- const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
27538
- let fallbackWidthPx = safeDefaultPx;
27539
- if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
27540
- fallbackWidthPx = tableWidthPx / columnCount;
27541
- }
27542
- const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
27543
- if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
27544
- const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
27545
- return safeDefault;
27546
- }
27547
- return Math.max(fallbackWidthTwips, cellMinWidthTwips);
27548
- };
27549
- const XML_NODE_NAME$g = "w:tblGrid";
27550
- const SD_ATTR_KEY$3 = "grid";
27551
- const cellMinWidth = pixelsToTwips(10);
27552
- const encode$m = (params2) => {
27135
+ const translator$M = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
27136
+ const translator$L = NodeTranslator.from(
27137
+ createSingleAttrPropertyHandler(
27138
+ "w:hideMark",
27139
+ null,
27140
+ "w:val",
27141
+ (v2) => parseBoolean(v2 ?? "true"),
27142
+ (v2) => booleanToString(v2)
27143
+ )
27144
+ );
27145
+ const translator$K = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
27146
+ const XML_NODE_NAME$h = "w:headers";
27147
+ const SD_ATTR_KEY$3 = "headers";
27148
+ const encode$n = (params2) => {
27553
27149
  const { nodes } = params2;
27554
27150
  const node = nodes[0];
27555
- const attributes = encodeProperties(node, { [translator$u.xmlName]: translator$u }, true);
27151
+ const attributes = encodeProperties(node, { [translator$K.xmlName]: translator$K }, true);
27556
27152
  return {
27557
- xmlName: XML_NODE_NAME$g,
27153
+ xmlName: XML_NODE_NAME$h,
27558
27154
  sdNodeOrKeyName: SD_ATTR_KEY$3,
27559
27155
  attributes
27560
27156
  };
27561
27157
  };
27562
- const decode$o = (params2) => {
27563
- const { grid: rawGrid } = params2.node.attrs || {};
27564
- const grid = Array.isArray(rawGrid) ? rawGrid : [];
27565
- const { firstRow = {} } = params2.extraParams || {};
27566
- const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
27567
- const columnCountFromCells = cellNodes.reduce((count, cell) => {
27568
- const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
27569
- return count + spanCount;
27570
- }, 0);
27571
- const totalColumns = Math.max(columnCountFromCells, grid.length);
27572
- const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
27573
- const elements = [];
27574
- let columnIndex = 0;
27575
- const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
27576
- let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
27577
- let shouldEnforceMinimum = enforceMinimum;
27578
- if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
27579
- numericWidth = fallbackColumnWidthTwips;
27580
- shouldEnforceMinimum = true;
27581
- }
27582
- const roundedWidth = Math.round(numericWidth);
27583
- const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
27584
- const safeWidth = Math.max(roundedWidth, minimumWidth);
27585
- const decoded = translator$u.decode({
27586
- node: { type: (
27587
- /** @type {string} */
27588
- translator$u.sdNodeOrKeyName
27589
- ), attrs: { col: safeWidth } }
27590
- });
27591
- if (decoded) elements.push(decoded);
27592
- };
27593
- cellNodes.forEach((cell) => {
27594
- const { colspan = 1, colwidth } = cell?.attrs || {};
27595
- const spanCount = Math.max(1, colspan);
27596
- for (let span = 0; span < spanCount; span++) {
27597
- const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
27598
- const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
27599
- const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
27600
- const colGridAttrs = grid?.[columnIndex] || {};
27601
- const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
27602
- const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
27603
- let cellWidthTwips;
27604
- let enforceMinimum = false;
27605
- if (hasCellWidth) {
27606
- const tolerance = 0.5;
27607
- if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
27608
- cellWidthTwips = gridWidthTwips;
27609
- } else {
27610
- cellWidthTwips = pixelsToTwips(cellWidthPixels);
27611
- }
27612
- } else if (gridWidthTwips != null) {
27613
- cellWidthTwips = gridWidthTwips;
27614
- } else {
27615
- cellWidthTwips = fallbackColumnWidthTwips;
27616
- enforceMinimum = true;
27617
- }
27618
- pushColumn(cellWidthTwips, { enforceMinimum });
27619
- columnIndex++;
27620
- }
27621
- });
27622
- while (columnIndex < grid.length) {
27623
- const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
27624
- pushColumn(gridWidthTwips);
27625
- columnIndex++;
27626
- }
27158
+ const decode$p = (params2) => {
27159
+ const { headers = [] } = params2.node.attrs || {};
27627
27160
  const newNode = {
27628
- name: XML_NODE_NAME$g,
27161
+ name: XML_NODE_NAME$h,
27629
27162
  attributes: {},
27630
- elements
27163
+ elements: headers.map(
27164
+ (header) => translator$K.decode({
27165
+ node: { type: "header", attrs: header }
27166
+ })
27167
+ )
27631
27168
  };
27632
27169
  return newNode;
27633
27170
  };
27634
- const config$f = {
27635
- xmlName: XML_NODE_NAME$g,
27171
+ const config$g = {
27172
+ xmlName: XML_NODE_NAME$h,
27636
27173
  sdNodeOrKeyName: SD_ATTR_KEY$3,
27637
- encode: encode$m,
27638
- decode: decode$o
27639
- };
27640
- const translator$t = NodeTranslator.from(config$f);
27641
- const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
27642
- const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
27643
- const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
27644
- const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
27645
- const pctToPercent = (value) => {
27646
- if (value == null) return null;
27647
- return value / 50;
27174
+ encode: encode$n,
27175
+ decode: decode$p
27648
27176
  };
27649
- const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27650
- const resolveMeasurementWidthPx = (measurement) => {
27651
- if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27652
- const { value, type: type2 } = measurement;
27653
- if (!type2 || type2 === "auto") return null;
27654
- if (type2 === "dxa") return twipsToPixels(value);
27655
- if (type2 === "pct") {
27656
- const percent2 = pctToPercent(value);
27657
- if (percent2 == null || percent2 <= 0) return null;
27658
- const widthTwips = resolveContentWidthTwips() * percent2 / 100;
27659
- return twipsToPixels(widthTwips);
27177
+ const translator$J = NodeTranslator.from(config$g);
27178
+ const propertyTranslators$4 = [
27179
+ translator$1a,
27180
+ translator$18,
27181
+ translator$17,
27182
+ translator$16,
27183
+ translator$R,
27184
+ translator$19,
27185
+ translator$Q,
27186
+ translator$P,
27187
+ translator$O,
27188
+ translator$N,
27189
+ translator$M,
27190
+ translator$L,
27191
+ translator$J
27192
+ ];
27193
+ const translator$I = NodeTranslator.from(
27194
+ createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators$4)
27195
+ );
27196
+ function handleTableCellNode({
27197
+ params: params2,
27198
+ node,
27199
+ table,
27200
+ row,
27201
+ rowBorders,
27202
+ columnIndex,
27203
+ columnWidth = null,
27204
+ allColumnWidths = [],
27205
+ _referencedStyles
27206
+ }) {
27207
+ const { nodeListHandler } = params2;
27208
+ const attributes = {};
27209
+ const referencedStyles = _referencedStyles ?? { fontSize: null, fonts: {}, cellMargins: {} };
27210
+ const tcPr = node.elements.find((el) => el.name === "w:tcPr");
27211
+ const tableCellProperties = tcPr ? translator$I.encode({ ...params2, nodes: [tcPr] }) ?? {} : {};
27212
+ attributes["tableCellProperties"] = tableCellProperties;
27213
+ if (rowBorders?.insideH) {
27214
+ rowBorders["bottom"] = rowBorders.insideH;
27215
+ delete rowBorders.insideH;
27660
27216
  }
27661
- return null;
27662
- };
27663
- const countColumnsInRow = (row) => {
27664
- if (!row?.elements?.length) return 0;
27665
- return row.elements.reduce((count, element) => {
27666
- if (element.name !== "w:tc") return count;
27667
- const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
27668
- const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27669
- const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27670
- return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27671
- }, 0);
27672
- };
27673
- const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27674
- const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27675
- const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
27676
- const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
27677
- const columnCount = countColumnsInRow(firstRow);
27678
- if (!columnCount) return null;
27679
- const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
27680
- /** @type {any} */
27681
- params2
27682
- );
27683
- const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
27684
- let totalWidthPx;
27685
- if (tableWidthMeasurement) {
27686
- const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27687
- if (resolved != null) totalWidthPx = resolved;
27217
+ if (rowBorders?.insideV) {
27218
+ rowBorders["right"] = rowBorders.insideV;
27219
+ delete rowBorders?.insideV;
27688
27220
  }
27689
- if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
27690
- totalWidthPx = tableWidth.width;
27221
+ if (rowBorders) attributes["borders"] = { ...rowBorders };
27222
+ const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
27223
+ if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
27224
+ const colspan = tableCellProperties.gridSpan;
27225
+ if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
27226
+ let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
27227
+ const widthType = tableCellProperties.cellWidth?.type;
27228
+ if (widthType) attributes["widthType"] = widthType;
27229
+ if (!width && columnWidth) width = columnWidth;
27230
+ if (width) {
27231
+ attributes["colwidth"] = [width];
27232
+ attributes["widthUnit"] = "px";
27233
+ const defaultColWidths = allColumnWidths;
27234
+ const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
27235
+ const colspanNum = parseInt(colspan || 1, 10);
27236
+ if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
27237
+ let colwidth = [];
27238
+ for (let i = 0; i < colspanNum; i++) {
27239
+ let colwidthValue = defaultColWidths[columnIndex + i];
27240
+ let defaultColwidth = 100;
27241
+ if (typeof colwidthValue !== "undefined") {
27242
+ colwidth.push(colwidthValue);
27243
+ } else {
27244
+ colwidth.push(defaultColwidth);
27245
+ }
27246
+ }
27247
+ if (colwidth.length) {
27248
+ attributes["colwidth"] = [...colwidth];
27249
+ }
27250
+ }
27691
27251
  }
27692
- if (totalWidthPx == null) {
27693
- totalWidthPx = minimumColumnWidthPx * columnCount;
27252
+ const background = {
27253
+ color: tableCellProperties.shading?.fill
27254
+ };
27255
+ if (background.color) attributes["background"] = background;
27256
+ const verticalAlign = tableCellProperties.vAlign;
27257
+ if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
27258
+ attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
27259
+ const { fontSize: fontSize2, fonts = {} } = referencedStyles;
27260
+ const fontFamily2 = fonts["ascii"];
27261
+ if (fontSize2) attributes["fontSize"] = fontSize2;
27262
+ if (fontFamily2) attributes["fontFamily"] = fontFamily2;
27263
+ if (tableCellProperties.vMerge === "restart") {
27264
+ const rows = table.elements.filter((el) => el.name === "w:tr");
27265
+ const currentRowIndex = rows.findIndex((r2) => r2 === row);
27266
+ const remainingRows = rows.slice(currentRowIndex + 1);
27267
+ const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
27268
+ let cellIndex = cellsInRow.findIndex((el) => el === node);
27269
+ let rowspan = 1;
27270
+ for (let remainingRow of remainingRows) {
27271
+ const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
27272
+ const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
27273
+ if (!cellAtIndex) break;
27274
+ const vMerge = getTableCellVMerge(cellAtIndex);
27275
+ if (!vMerge || vMerge === "restart") {
27276
+ break;
27277
+ }
27278
+ rowspan++;
27279
+ remainingRow.elements.splice(firstCell + cellIndex, 1);
27280
+ }
27281
+ attributes["rowspan"] = rowspan;
27694
27282
  }
27695
- const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
27696
- const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
27697
- const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
27698
27283
  return {
27699
- grid: createFallbackGrid(columnCount, columnWidthTwips),
27700
- columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27284
+ type: "tableCell",
27285
+ content: normalizeTableCellContent(
27286
+ nodeListHandler.handler({
27287
+ ...params2,
27288
+ nodes: node.elements,
27289
+ path: [...params2.path || [], node]
27290
+ }),
27291
+ params2.editor
27292
+ ),
27293
+ attrs: attributes
27701
27294
  };
27702
- };
27703
- const XML_NODE_NAME$f = "w:tbl";
27704
- const SD_NODE_NAME$c = "table";
27705
- const encode$l = (params2, encodedAttrs) => {
27706
- const { nodes } = params2;
27707
- const node = nodes[0];
27708
- const tblPr = node.elements.find((el) => el.name === "w:tblPr");
27709
- if (tblPr) {
27710
- const encodedProperties = translator$v.encode({ ...params2, nodes: [tblPr] });
27711
- encodedAttrs["tableProperties"] = encodedProperties || {};
27712
- }
27713
- const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
27714
- if (tblGrid) {
27715
- encodedAttrs["grid"] = translator$t.encode({ ...params2, nodes: [tblGrid] }).attributes;
27716
- }
27717
- [
27718
- "tableStyleId",
27719
- "justification",
27720
- "tableLayout",
27721
- ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27722
- ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
27723
- ].forEach((prop) => {
27724
- let key2;
27725
- let transform;
27726
- if (Array.isArray(prop)) {
27727
- [key2, transform] = prop;
27728
- } else {
27729
- key2 = prop;
27730
- transform = (v2) => v2;
27295
+ }
27296
+ function normalizeTableCellContent(content, editor) {
27297
+ if (!Array.isArray(content) || content.length === 0) return content;
27298
+ const normalized = [];
27299
+ const pendingForNextBlock = [];
27300
+ const schema = editor?.schema;
27301
+ const cloneBlock = (node) => {
27302
+ if (!node) return node;
27303
+ const cloned = { ...node };
27304
+ if (Array.isArray(node.content)) {
27305
+ cloned.content = [...node.content];
27731
27306
  }
27732
- if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
27733
- encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
27307
+ return cloned;
27308
+ };
27309
+ const ensureArray = (node) => {
27310
+ if (!Array.isArray(node.content)) {
27311
+ node.content = [];
27734
27312
  }
27735
- });
27736
- if (encodedAttrs.tableCellSpacing) {
27737
- encodedAttrs["borderCollapse"] = "separate";
27738
- }
27739
- if (encodedAttrs.tableProperties?.tableWidth) {
27740
- const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
27741
- const widthPx = twipsToPixels(tableWidthMeasurement.value);
27742
- if (widthPx != null) {
27743
- encodedAttrs.tableWidth = {
27744
- width: widthPx,
27745
- type: tableWidthMeasurement.type
27746
- };
27747
- } else if (tableWidthMeasurement.type === "auto") {
27748
- encodedAttrs.tableWidth = {
27749
- width: 0,
27750
- type: tableWidthMeasurement.type
27751
- };
27313
+ return node.content;
27314
+ };
27315
+ const isInlineNode = (node) => {
27316
+ if (!node || typeof node.type !== "string") return false;
27317
+ if (node.type === "text") return true;
27318
+ if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
27319
+ const nodeType = schema?.nodes?.[node.type];
27320
+ if (nodeType) {
27321
+ if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
27322
+ if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
27323
+ return nodeType.spec.group.split(" ").includes("inline");
27324
+ }
27752
27325
  }
27753
- }
27754
- const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
27755
- const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
27756
- if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
27757
- encodedAttrs.tableProperties = {
27758
- ...encodedAttrs.tableProperties || {},
27759
- cellMargins: referencedStyles.cellMargins
27760
- };
27761
- }
27762
- const rows = node.elements.filter((el) => el.name === "w:tr");
27763
- const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
27764
- const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
27765
- encodedAttrs["borders"] = borderData;
27766
- const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
27767
- let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
27768
- if (!columnWidths.length) {
27769
- const fallback = buildFallbackGridForTable({
27770
- params: params2,
27771
- rows,
27772
- tableWidth: encodedAttrs.tableWidth,
27773
- tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
27774
- });
27775
- if (fallback) {
27776
- encodedAttrs.grid = fallback.grid;
27777
- columnWidths = fallback.columnWidths;
27326
+ return false;
27327
+ };
27328
+ for (const node of content) {
27329
+ if (!node || typeof node.type !== "string") {
27330
+ normalized.push(node);
27331
+ continue;
27778
27332
  }
27779
- }
27780
- const content = [];
27781
- const totalColumns = columnWidths.length;
27782
- const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
27783
- rows.forEach((row, rowIndex) => {
27784
- const result = translator$Z.encode({
27785
- ...params2,
27786
- nodes: [row],
27787
- extraParams: {
27788
- row,
27789
- table: node,
27790
- rowBorders: borderRowData,
27791
- styleTag: tblStyleTag,
27792
- columnWidths,
27793
- activeRowSpans: activeRowSpans.slice(),
27794
- rowIndex
27795
- }
27796
- });
27797
- if (result) {
27798
- content.push(result);
27799
- if (totalColumns > 0) {
27800
- const activeRowSpansForCurrentRow = activeRowSpans.slice();
27801
- for (let col = 0; col < totalColumns; col++) {
27802
- if (activeRowSpans[col] > 0) {
27803
- activeRowSpans[col] -= 1;
27804
- }
27805
- }
27806
- let columnIndex = 0;
27807
- const advanceColumnIndex = () => {
27808
- while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
27809
- columnIndex += 1;
27810
- }
27811
- };
27812
- advanceColumnIndex();
27813
- result.content?.forEach((cell) => {
27814
- advanceColumnIndex();
27815
- const colspan = Math.max(1, cell.attrs?.colspan || 1);
27816
- const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
27817
- if (rowspan > 1) {
27818
- for (let offset2 = 0; offset2 < colspan && columnIndex + offset2 < totalColumns; offset2++) {
27819
- const targetIndex = columnIndex + offset2;
27820
- const remainingRows = rowspan - 1;
27821
- if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
27822
- activeRowSpans[targetIndex] = remainingRows;
27823
- }
27824
- }
27825
- }
27826
- columnIndex += colspan;
27827
- advanceColumnIndex();
27828
- });
27829
- }
27830
- }
27831
- });
27832
- return {
27833
- type: "table",
27834
- content,
27835
- attrs: encodedAttrs
27836
- };
27837
- };
27838
- const decode$n = (params2, decodedAttrs) => {
27839
- params2.node = preProcessVerticalMergeCells(params2.node, params2);
27840
- const { node } = params2;
27841
- const elements = translateChildNodes(params2);
27842
- const firstRow = node.content?.find((n) => n.type === "tableRow");
27843
- const properties = node.attrs.grid;
27844
- const element = translator$t.decode({
27845
- ...params2,
27846
- node: { ...node, attrs: { ...node.attrs, grid: properties } },
27847
- extraParams: {
27848
- firstRow
27849
- }
27850
- });
27851
- if (element) elements.unshift(element);
27852
- if (node.attrs?.tableProperties) {
27853
- const properties2 = { ...node.attrs.tableProperties };
27854
- const element2 = translator$v.decode({
27855
- ...params2,
27856
- node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
27857
- });
27858
- if (element2) elements.unshift(element2);
27859
- }
27860
- return {
27861
- name: "w:tbl",
27862
- attributes: decodedAttrs || {},
27863
- elements
27864
- };
27865
- };
27866
- function _processTableBorders(rawBorders) {
27867
- const borders = {};
27868
- const rowBorders = {};
27869
- Object.entries(rawBorders).forEach(([name, attributes]) => {
27870
- const attrs = {};
27871
- const color = attributes.color;
27872
- const size2 = attributes.size;
27873
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
27874
- if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
27875
- const rowBorderNames = ["insideH", "insideV"];
27876
- if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
27877
- borders[name] = attrs;
27878
- });
27879
- return {
27880
- borders,
27881
- rowBorders
27882
- };
27883
- }
27884
- function _getReferencedTableStyles(tableStyleReference, params2) {
27885
- if (!tableStyleReference) return null;
27886
- const stylesToReturn = {};
27887
- const { docx } = params2;
27888
- const styles = docx["word/styles.xml"];
27889
- const { elements } = styles.elements[0];
27890
- const styleElements = elements.filter((el) => el.name === "w:style");
27891
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
27892
- if (!styleTag) return null;
27893
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
27894
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
27895
- let baseTblPr;
27896
- if (basedOn?.attributes) {
27897
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
27898
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
27899
- }
27900
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
27901
- if (pPr) {
27902
- const justification = pPr.elements.find((el) => el.name === "w:jc");
27903
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
27904
- }
27905
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
27906
- if (rPr) {
27907
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
27908
- if (fonts) {
27909
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
27910
- stylesToReturn.fonts = { ascii, hAnsi, cs };
27911
- }
27912
- const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
27913
- if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
27914
- }
27915
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
27916
- if (tblPr && tblPr.elements) {
27917
- if (baseTblPr && baseTblPr.elements) {
27918
- tblPr.elements.push(...baseTblPr.elements);
27919
- }
27920
- const tableProperties = translator$v.encode({ ...params2, nodes: [tblPr] });
27921
- const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
27922
- if (borders) stylesToReturn.borders = borders;
27923
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
27924
- const cellMargins = {};
27925
- Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
27926
- if (attrs?.value != null) {
27927
- cellMargins[key2] = {
27928
- value: attrs.value,
27929
- type: attrs.type || "dxa"
27930
- };
27931
- }
27932
- });
27933
- if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
27934
- }
27935
- return stylesToReturn;
27936
- }
27937
- const config$e = {
27938
- xmlName: XML_NODE_NAME$f,
27939
- sdNodeOrKeyName: SD_NODE_NAME$c,
27940
- type: NodeTranslator.translatorTypes.NODE,
27941
- encode: encode$l,
27942
- decode: decode$n,
27943
- attributes: []
27944
- };
27945
- const translator$s = NodeTranslator.from(config$e);
27946
- const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$s);
27947
- function getReferencedTableStyles(tblStyleTag, docx) {
27948
- if (!tblStyleTag) return null;
27949
- const stylesToReturn = {};
27950
- const { attributes = {} } = tblStyleTag;
27951
- const tableStyleReference = attributes["w:val"];
27952
- if (!tableStyleReference) return null;
27953
- const styles = docx["word/styles.xml"];
27954
- const { elements } = styles.elements[0];
27955
- const styleElements = elements.filter((el) => el.name === "w:style");
27956
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
27957
- if (!styleTag) return null;
27958
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
27959
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
27960
- let baseTblPr;
27961
- if (basedOn?.attributes) {
27962
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
27963
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
27964
- }
27965
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
27966
- if (pPr) {
27967
- const justification = pPr.elements.find((el) => el.name === "w:jc");
27968
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
27969
- }
27970
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
27971
- if (rPr) {
27972
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
27973
- if (fonts) {
27974
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
27975
- stylesToReturn.fonts = { ascii, hAnsi, cs };
27976
- }
27977
- const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
27978
- if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
27979
- }
27980
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
27981
- if (tblPr && tblPr.elements) {
27982
- if (baseTblPr && baseTblPr.elements) {
27983
- tblPr.elements.push(...baseTblPr.elements);
27984
- }
27985
- const tableBorders = tblPr?.elements?.find((el) => el.name === "w:tblBorders");
27986
- const { elements: borderElements = [] } = tableBorders || {};
27987
- const { borders, rowBorders } = processTableBorders(borderElements);
27988
- if (borders) stylesToReturn.borders = borders;
27989
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
27990
- const tableCellMargin = tblPr?.elements.find((el) => el.name === "w:tblCellMar");
27991
- if (tableCellMargin) {
27992
- const marginLeft = tableCellMargin.elements.find((el) => el.name === "w:left");
27993
- const marginRight = tableCellMargin.elements.find((el) => el.name === "w:right");
27994
- const marginTop = tableCellMargin.elements.find((el) => el.name === "w:top");
27995
- const marginBottom = tableCellMargin.elements.find((el) => el.name === "w:bottom");
27996
- stylesToReturn.cellMargins = {
27997
- marginLeft: marginLeft?.attributes["w:w"],
27998
- marginRight: marginRight?.attributes["w:w"],
27999
- marginTop: marginTop?.attributes["w:w"],
28000
- marginBottom: marginBottom?.attributes["w:w"]
28001
- };
28002
- }
28003
- }
28004
- return stylesToReturn;
28005
- }
28006
- function processTableBorders(borderElements) {
28007
- const borders = {};
28008
- const rowBorders = {};
28009
- borderElements.forEach((borderElement) => {
28010
- const { name } = borderElement;
28011
- const borderName = name.split("w:")[1];
28012
- const { attributes } = borderElement;
28013
- const attrs = {};
28014
- const color = attributes["w:color"];
28015
- const size2 = attributes["w:sz"];
28016
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
28017
- if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
28018
- const rowBorderNames = ["insideH", "insideV"];
28019
- if (rowBorderNames.includes(borderName)) rowBorders[borderName] = attrs;
28020
- borders[borderName] = attrs;
28021
- });
28022
- return {
28023
- borders,
28024
- rowBorders
28025
- };
28026
- }
28027
- const translator$r = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
28028
- const translator$q = NodeTranslator.from(
28029
- createSingleAttrPropertyHandler(
28030
- "w:gridSpan",
28031
- null,
28032
- "w:val",
28033
- (v2) => parseInteger(v2) ?? void 0,
28034
- (v2) => integerToString(v2)
28035
- )
28036
- );
28037
- const translator$p = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
28038
- const translator$o = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
28039
- const translator$n = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
28040
- const propertyTranslators$2 = [
28041
- translator$z,
28042
- translator$B,
28043
- translator$F,
28044
- translator$L,
28045
- translator$J,
28046
- translator$D,
28047
- translator$H,
28048
- translator$G,
28049
- translator$o,
28050
- translator$n
28051
- ];
28052
- const translator$m = NodeTranslator.from(
28053
- createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$2)
28054
- );
28055
- const translator$l = NodeTranslator.from(
28056
- createSingleAttrPropertyHandler(
28057
- "w:noWrap",
28058
- null,
28059
- "w:val",
28060
- (v2) => parseBoolean(v2 ?? "true"),
28061
- (v2) => booleanToString(v2)
28062
- )
28063
- );
28064
- const propertyTranslators$1 = [
28065
- translator$K,
28066
- translator$I,
28067
- translator$E,
28068
- translator$C,
28069
- translator$A,
28070
- translator$y
28071
- ];
28072
- const translator$k = NodeTranslator.from(
28073
- createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$1)
28074
- );
28075
- const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
28076
- const translator$i = NodeTranslator.from(
28077
- createSingleAttrPropertyHandler(
28078
- "w:tcFitText",
28079
- null,
28080
- "w:val",
28081
- (v2) => parseBoolean(v2 ?? "true"),
28082
- (v2) => booleanToString(v2)
28083
- )
28084
- );
28085
- const translator$h = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
28086
- const translator$g = NodeTranslator.from(
28087
- createSingleAttrPropertyHandler(
28088
- "w:hideMark",
28089
- null,
28090
- "w:val",
28091
- (v2) => parseBoolean(v2 ?? "true"),
28092
- (v2) => booleanToString(v2)
28093
- )
28094
- );
28095
- const translator$f = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
28096
- const XML_NODE_NAME$e = "w:headers";
28097
- const SD_ATTR_KEY$2 = "headers";
28098
- const encode$k = (params2) => {
28099
- const { nodes } = params2;
28100
- const node = nodes[0];
28101
- const attributes = encodeProperties(node, { [translator$f.xmlName]: translator$f }, true);
28102
- return {
28103
- xmlName: XML_NODE_NAME$e,
28104
- sdNodeOrKeyName: SD_ATTR_KEY$2,
28105
- attributes
28106
- };
28107
- };
28108
- const decode$m = (params2) => {
28109
- const { headers = [] } = params2.node.attrs || {};
28110
- const newNode = {
28111
- name: XML_NODE_NAME$e,
28112
- attributes: {},
28113
- elements: headers.map(
28114
- (header) => translator$f.decode({
28115
- node: { type: "header", attrs: header }
28116
- })
28117
- )
28118
- };
28119
- return newNode;
28120
- };
28121
- const config$d = {
28122
- xmlName: XML_NODE_NAME$e,
28123
- sdNodeOrKeyName: SD_ATTR_KEY$2,
28124
- encode: encode$k,
28125
- decode: decode$m
28126
- };
28127
- const translator$e = NodeTranslator.from(config$d);
28128
- const propertyTranslators = [
28129
- translator$19,
28130
- translator$r,
28131
- translator$q,
28132
- translator$p,
28133
- translator$m,
28134
- translator$X,
28135
- translator$l,
28136
- translator$k,
28137
- translator$j,
28138
- translator$i,
28139
- translator$h,
28140
- translator$g,
28141
- translator$e
28142
- ];
28143
- const translator$d = NodeTranslator.from(
28144
- createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators)
28145
- );
28146
- function handleTableCellNode({
28147
- params: params2,
28148
- node,
28149
- table,
28150
- row,
28151
- rowBorders,
28152
- styleTag,
28153
- columnIndex,
28154
- columnWidth = null,
28155
- allColumnWidths = []
28156
- }) {
28157
- const { docx, nodeListHandler } = params2;
28158
- const attributes = {};
28159
- const tcPr = node.elements.find((el) => el.name === "w:tcPr");
28160
- const tableCellProperties = tcPr ? translator$d.encode({ ...params2, nodes: [tcPr] }) ?? {} : {};
28161
- attributes["tableCellProperties"] = tableCellProperties;
28162
- if (rowBorders?.insideH) {
28163
- rowBorders["bottom"] = rowBorders.insideH;
28164
- delete rowBorders.insideH;
28165
- }
28166
- if (rowBorders?.insideV) {
28167
- rowBorders["right"] = rowBorders.insideV;
28168
- delete rowBorders?.insideV;
28169
- }
28170
- if (rowBorders) attributes["borders"] = { ...rowBorders };
28171
- const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
28172
- if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
28173
- const colspan = tableCellProperties.gridSpan;
28174
- if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
28175
- let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
28176
- const widthType = tableCellProperties.cellWidth?.type;
28177
- if (widthType) attributes["widthType"] = widthType;
28178
- if (!width && columnWidth) width = columnWidth;
28179
- if (width) {
28180
- attributes["colwidth"] = [width];
28181
- attributes["widthUnit"] = "px";
28182
- const defaultColWidths = allColumnWidths;
28183
- const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
28184
- const colspanNum = parseInt(colspan || 1, 10);
28185
- if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
28186
- let colwidth = [];
28187
- for (let i = 0; i < colspanNum; i++) {
28188
- let colwidthValue = defaultColWidths[columnIndex + i];
28189
- let defaultColwidth = 100;
28190
- if (typeof colwidthValue !== "undefined") {
28191
- colwidth.push(colwidthValue);
28192
- } else {
28193
- colwidth.push(defaultColwidth);
28194
- }
28195
- }
28196
- if (colwidth.length) {
28197
- attributes["colwidth"] = [...colwidth];
28198
- }
28199
- }
28200
- }
28201
- const background = {
28202
- color: tableCellProperties.shading?.fill
28203
- };
28204
- if (background.color) attributes["background"] = background;
28205
- const verticalAlign = tableCellProperties.vAlign;
28206
- if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
28207
- const referencedStyles = getReferencedTableStyles(styleTag, docx) || { fontSize: null, fonts: {}, cellMargins: {} };
28208
- attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
28209
- const { fontSize: fontSize2, fonts = {} } = referencedStyles;
28210
- const fontFamily2 = fonts["ascii"];
28211
- if (fontSize2) attributes["fontSize"] = fontSize2;
28212
- if (fontFamily2) attributes["fontFamily"] = fontFamily2;
28213
- if (tableCellProperties.vMerge === "restart") {
28214
- const rows = table.elements.filter((el) => el.name === "w:tr");
28215
- const currentRowIndex = rows.findIndex((r2) => r2 === row);
28216
- const remainingRows = rows.slice(currentRowIndex + 1);
28217
- const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
28218
- let cellIndex = cellsInRow.findIndex((el) => el === node);
28219
- let rowspan = 1;
28220
- for (let remainingRow of remainingRows) {
28221
- const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
28222
- const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
28223
- if (!cellAtIndex) break;
28224
- const vMerge = getTableCellVMerge(cellAtIndex);
28225
- if (!vMerge || vMerge === "restart") {
28226
- break;
28227
- }
28228
- rowspan++;
28229
- remainingRow.elements.splice(firstCell + cellIndex, 1);
28230
- }
28231
- attributes["rowspan"] = rowspan;
28232
- }
28233
- return {
28234
- type: "tableCell",
28235
- content: normalizeTableCellContent(
28236
- nodeListHandler.handler({
28237
- ...params2,
28238
- nodes: node.elements,
28239
- path: [...params2.path || [], node]
28240
- }),
28241
- params2.editor
28242
- ),
28243
- attrs: attributes
28244
- };
28245
- }
28246
- function normalizeTableCellContent(content, editor) {
28247
- if (!Array.isArray(content) || content.length === 0) return content;
28248
- const normalized = [];
28249
- const pendingForNextBlock = [];
28250
- const schema = editor?.schema;
28251
- const cloneBlock = (node) => {
28252
- if (!node) return node;
28253
- const cloned = { ...node };
28254
- if (Array.isArray(node.content)) {
28255
- cloned.content = [...node.content];
28256
- }
28257
- return cloned;
28258
- };
28259
- const ensureArray = (node) => {
28260
- if (!Array.isArray(node.content)) {
28261
- node.content = [];
28262
- }
28263
- return node.content;
28264
- };
28265
- const isInlineNode = (node) => {
28266
- if (!node || typeof node.type !== "string") return false;
28267
- if (node.type === "text") return true;
28268
- if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
28269
- const nodeType = schema?.nodes?.[node.type];
28270
- if (nodeType) {
28271
- if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
28272
- if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
28273
- return nodeType.spec.group.split(" ").includes("inline");
28274
- }
28275
- }
28276
- return false;
28277
- };
28278
- for (const node of content) {
28279
- if (!node || typeof node.type !== "string") {
28280
- normalized.push(node);
28281
- continue;
28282
- }
28283
- if (!isInlineNode(node)) {
28284
- const blockNode = cloneBlock(node);
28285
- if (pendingForNextBlock.length) {
28286
- const blockContent = ensureArray(blockNode);
28287
- const leadingInline = pendingForNextBlock.splice(0);
28288
- blockNode.content = [...leadingInline, ...blockContent];
28289
- } else if (Array.isArray(blockNode.content)) {
28290
- blockNode.content = [...blockNode.content];
27333
+ if (!isInlineNode(node)) {
27334
+ const blockNode = cloneBlock(node);
27335
+ if (pendingForNextBlock.length) {
27336
+ const blockContent = ensureArray(blockNode);
27337
+ const leadingInline = pendingForNextBlock.splice(0);
27338
+ blockNode.content = [...leadingInline, ...blockContent];
27339
+ } else if (Array.isArray(blockNode.content)) {
27340
+ blockNode.content = [...blockNode.content];
28291
27341
  }
28292
27342
  normalized.push(blockNode);
28293
27343
  continue;
@@ -28470,22 +27520,22 @@ function generateTableCellProperties(node) {
28470
27520
  } else if (tableCellProperties?.borders) {
28471
27521
  delete tableCellProperties.borders;
28472
27522
  }
28473
- const result = translator$d.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
27523
+ const result = translator$I.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
28474
27524
  return result;
28475
27525
  }
28476
- const XML_NODE_NAME$d = "w:tc";
28477
- const SD_NODE_NAME$b = "tableCell";
28478
- const validXmlAttributes$a = [];
28479
- function encode$j(params2, encodedAttrs) {
27526
+ const XML_NODE_NAME$g = "w:tc";
27527
+ const SD_NODE_NAME$d = "tableCell";
27528
+ const validXmlAttributes$b = [];
27529
+ function encode$m(params2, encodedAttrs) {
28480
27530
  const {
28481
27531
  node,
28482
27532
  table,
28483
27533
  row,
28484
27534
  rowBorders,
28485
- styleTag,
28486
27535
  columnIndex,
28487
27536
  columnWidth,
28488
- columnWidths: allColumnWidths
27537
+ columnWidths: allColumnWidths,
27538
+ _referencedStyles
28489
27539
  } = params2.extraParams;
28490
27540
  const schemaNode = handleTableCellNode({
28491
27541
  params: params2,
@@ -28493,96 +27543,388 @@ function encode$j(params2, encodedAttrs) {
28493
27543
  table,
28494
27544
  row,
28495
27545
  rowBorders,
28496
- styleTag,
28497
27546
  columnIndex,
28498
27547
  columnWidth,
28499
- allColumnWidths
27548
+ allColumnWidths,
27549
+ _referencedStyles
28500
27550
  });
28501
27551
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
28502
27552
  schemaNode.attrs = { ...schemaNode.attrs, ...encodedAttrs };
28503
27553
  }
28504
27554
  return schemaNode;
28505
27555
  }
28506
- function decode$l(params2, decodedAttrs) {
27556
+ function decode$o(params2, decodedAttrs) {
28507
27557
  const translated = translateTableCell(params2);
28508
27558
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
28509
27559
  translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
28510
27560
  }
28511
27561
  return translated;
28512
27562
  }
28513
- const config$c = {
28514
- xmlName: XML_NODE_NAME$d,
28515
- sdNodeOrKeyName: SD_NODE_NAME$b,
27563
+ const config$f = {
27564
+ xmlName: XML_NODE_NAME$g,
27565
+ sdNodeOrKeyName: SD_NODE_NAME$d,
28516
27566
  type: NodeTranslator.translatorTypes.NODE,
28517
- encode: encode$j,
28518
- decode: decode$l,
28519
- attributes: validXmlAttributes$a
27567
+ encode: encode$m,
27568
+ decode: decode$o,
27569
+ attributes: validXmlAttributes$b
28520
27570
  };
28521
- const translator$c = NodeTranslator.from(config$c);
28522
- function parseTagValueJSON(json) {
28523
- if (typeof json !== "string") {
28524
- return {};
28525
- }
28526
- const trimmed = json.trim();
28527
- if (!trimmed) {
28528
- return {};
28529
- }
28530
- try {
28531
- return JSON.parse(trimmed);
28532
- } catch {
28533
- return {};
28534
- }
28535
- }
28536
- function handleAnnotationNode(params2) {
28537
- const { nodes } = params2;
28538
- if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
28539
- return null;
28540
- }
28541
- const node = nodes[0];
28542
- const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
28543
- const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
28544
- const sdtId = sdtPr?.elements?.find((el) => el.name === "w:id");
28545
- const alias = sdtPr?.elements.find((el) => el.name === "w:alias");
28546
- const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
28547
- const tagValue = tag?.attributes["w:val"];
28548
- const shouldProcessAsJson = tagValue?.startsWith("{") && tagValue?.endsWith("}");
28549
- let attrs = {};
28550
- const aliasLabel = getSafeString(alias?.attributes?.["w:val"]);
28551
- if (shouldProcessAsJson) {
28552
- const parsedAttrs = parseTagValueJSON(tagValue);
28553
- attrs = {
28554
- type: parsedAttrs.fieldTypeShort,
28555
- fieldId: parsedAttrs.fieldId,
28556
- displayLabel: parsedAttrs.displayLabel,
28557
- defaultDisplayLabel: parsedAttrs.defaultDisplayLabel,
28558
- fieldType: parsedAttrs.fieldType,
28559
- fieldColor: parsedAttrs.fieldColor,
28560
- multipleImage: parsedAttrs.fieldMultipleImage,
28561
- fontFamily: parsedAttrs.fieldFontFamily,
28562
- fontSize: parsedAttrs.fieldFontSize,
28563
- textColor: parsedAttrs.fieldTextColor,
28564
- textHighlight: parsedAttrs.fieldTextHighlight,
28565
- hash: parsedAttrs.hash
28566
- };
28567
- } else {
28568
- attrs = getAttrsFromElements({ sdtPr, tag, alias, sdtId });
28569
- }
28570
- const initialDisplayLabel = getSafeString(attrs.displayLabel);
28571
- const extractedContent = getTextFromSdtContent(sdtContent);
28572
- if (!attrs.defaultDisplayLabel) {
28573
- if (initialDisplayLabel) {
28574
- attrs.defaultDisplayLabel = initialDisplayLabel;
28575
- } else if (aliasLabel) {
28576
- attrs.defaultDisplayLabel = aliasLabel;
27571
+ const translator$H = NodeTranslator.from(config$f);
27572
+ const translator$G = NodeTranslator.from({
27573
+ xmlName: "w:cantSplit",
27574
+ sdNodeOrKeyName: "cantSplit",
27575
+ encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
27576
+ decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
27577
+ });
27578
+ const translator$F = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
27579
+ const translator$E = NodeTranslator.from(
27580
+ createSingleAttrPropertyHandler(
27581
+ "w:gridAfter",
27582
+ null,
27583
+ "w:val",
27584
+ (v2) => parseInteger(v2) ?? void 0,
27585
+ (v2) => integerToString(v2)
27586
+ )
27587
+ );
27588
+ const translator$D = NodeTranslator.from(
27589
+ createSingleAttrPropertyHandler(
27590
+ "w:gridBefore",
27591
+ null,
27592
+ "w:val",
27593
+ (v2) => parseInteger(v2) ?? void 0,
27594
+ (v2) => integerToString(v2)
27595
+ )
27596
+ );
27597
+ const translator$C = NodeTranslator.from({
27598
+ xmlName: "w:hidden",
27599
+ sdNodeOrKeyName: "hidden",
27600
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27601
+ decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
27602
+ });
27603
+ const translator$B = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
27604
+ const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
27605
+ const translator$z = NodeTranslator.from({
27606
+ xmlName: "w:tblHeader",
27607
+ sdNodeOrKeyName: "repeatHeader",
27608
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27609
+ decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
27610
+ });
27611
+ const translator$y = NodeTranslator.from({
27612
+ xmlName: "w:trHeight",
27613
+ sdNodeOrKeyName: "rowHeight",
27614
+ encode: ({ nodes }) => {
27615
+ const heightAttrs = {};
27616
+ const val = nodes[0].attributes["w:val"];
27617
+ if (val) {
27618
+ heightAttrs["value"] = parseInt(val, 10);
28577
27619
  }
28578
- }
28579
- const placeholderLabel = getPlaceholderLabel(attrs, aliasLabel);
28580
- const placeholderText = ensurePlaceholderFormat(placeholderLabel);
28581
- const isAnnotationsEnabled = Boolean(params2.editor?.options?.annotations);
28582
- const contentIsDistinct = shouldUseSdtContent(extractedContent, placeholderText);
28583
- const shouldUseContent = !isAnnotationsEnabled && contentIsDistinct && (hasMoustache(extractedContent) || !placeholderText);
28584
- if (contentIsDistinct) {
28585
- attrs.displayLabel = extractedContent;
27620
+ const rule = nodes[0].attributes["w:hRule"];
27621
+ if (rule) {
27622
+ heightAttrs["rule"] = rule;
27623
+ }
27624
+ return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
27625
+ },
27626
+ decode: ({ node }) => {
27627
+ if (!node.attrs?.rowHeight) return;
27628
+ const heightAttrs = {};
27629
+ if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
27630
+ heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
27631
+ }
27632
+ if (node.attrs.rowHeight.rule) {
27633
+ heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
27634
+ }
27635
+ return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
27636
+ }
27637
+ });
27638
+ const translator$x = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
27639
+ const translator$w = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
27640
+ const propertyTranslators$3 = [
27641
+ translator$G,
27642
+ translator$1a,
27643
+ translator$F,
27644
+ translator$E,
27645
+ translator$D,
27646
+ translator$C,
27647
+ translator$B,
27648
+ translator$A,
27649
+ translator$z,
27650
+ translator$y,
27651
+ translator$x,
27652
+ translator$w
27653
+ ];
27654
+ const translator$v = NodeTranslator.from(
27655
+ createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$3, {
27656
+ cantSplit: false,
27657
+ hidden: false,
27658
+ repeatHeader: false
27659
+ })
27660
+ );
27661
+ const createPlaceholderCell = (gridWidth, reason) => {
27662
+ const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
27663
+ const noBorder = { val: "none", size: 0 };
27664
+ return {
27665
+ type: "tableCell",
27666
+ attrs: {
27667
+ colspan: 1,
27668
+ rowspan: 1,
27669
+ colwidth: [safeWidth],
27670
+ __placeholder: reason,
27671
+ borders: {
27672
+ top: { ...noBorder },
27673
+ right: { ...noBorder },
27674
+ bottom: { ...noBorder },
27675
+ left: { ...noBorder }
27676
+ }
27677
+ },
27678
+ content: [{ type: "paragraph", content: [] }]
27679
+ };
27680
+ };
27681
+ const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
27682
+ let index2 = startIndex;
27683
+ while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
27684
+ pendingRowSpans[index2] -= 1;
27685
+ index2 += 1;
27686
+ }
27687
+ return index2;
27688
+ };
27689
+ const fillPlaceholderColumns = ({
27690
+ content,
27691
+ pendingRowSpans,
27692
+ currentIndex,
27693
+ targetIndex,
27694
+ totalColumns,
27695
+ gridColumnWidths,
27696
+ reason
27697
+ }) => {
27698
+ let index2 = currentIndex;
27699
+ while (index2 < targetIndex && index2 < totalColumns) {
27700
+ if (pendingRowSpans[index2] > 0) {
27701
+ pendingRowSpans[index2] -= 1;
27702
+ index2 += 1;
27703
+ continue;
27704
+ }
27705
+ const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
27706
+ content.push(createPlaceholderCell(width, reason));
27707
+ index2 += 1;
27708
+ }
27709
+ return index2;
27710
+ };
27711
+ const isPlaceholderCell = (cell) => {
27712
+ if (!cell) return false;
27713
+ if (cell.attrs?.__placeholder) return true;
27714
+ const widths = cell.attrs?.colwidth;
27715
+ if (Array.isArray(widths) && widths.length > 0) {
27716
+ const hasMeaningfulWidth = widths.some(
27717
+ (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
27718
+ );
27719
+ if (!hasMeaningfulWidth) return true;
27720
+ }
27721
+ return false;
27722
+ };
27723
+ const XML_NODE_NAME$f = "w:tr";
27724
+ const SD_NODE_NAME$c = "tableRow";
27725
+ const validXmlAttributes$a = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
27726
+ (xmlName) => createAttributeHandler(xmlName)
27727
+ );
27728
+ const encode$l = (params2, encodedAttrs) => {
27729
+ const { row } = params2.extraParams;
27730
+ let tableRowProperties = {};
27731
+ const tPr = row.elements.find((el) => el.name === "w:trPr");
27732
+ if (tPr) {
27733
+ tableRowProperties = translator$v.encode({
27734
+ ...params2,
27735
+ nodes: [tPr]
27736
+ });
27737
+ }
27738
+ const gridBeforeRaw = tableRowProperties?.["gridBefore"];
27739
+ const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
27740
+ encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
27741
+ encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
27742
+ encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
27743
+ const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params2.extraParams;
27744
+ const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
27745
+ const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
27746
+ while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
27747
+ const cellNodes = row.elements.filter((el) => el.name === "w:tc");
27748
+ const content = [];
27749
+ let currentColumnIndex = 0;
27750
+ const fillUntil = (target, reason) => {
27751
+ currentColumnIndex = fillPlaceholderColumns({
27752
+ content,
27753
+ pendingRowSpans,
27754
+ currentIndex: currentColumnIndex,
27755
+ targetIndex: target,
27756
+ totalColumns,
27757
+ gridColumnWidths,
27758
+ reason
27759
+ });
27760
+ };
27761
+ const skipOccupiedColumns = () => {
27762
+ currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
27763
+ };
27764
+ fillUntil(safeGridBefore, "gridBefore");
27765
+ skipOccupiedColumns();
27766
+ cellNodes?.forEach((node) => {
27767
+ skipOccupiedColumns();
27768
+ const startColumn = currentColumnIndex;
27769
+ const columnWidth = gridColumnWidths?.[startColumn] || null;
27770
+ const result = translator$H.encode({
27771
+ ...params2,
27772
+ extraParams: {
27773
+ ...params2.extraParams,
27774
+ node,
27775
+ columnIndex: startColumn,
27776
+ columnWidth
27777
+ }
27778
+ });
27779
+ if (result) {
27780
+ content.push(result);
27781
+ const colspan = Math.max(1, result.attrs?.colspan || 1);
27782
+ const rowspan = Math.max(1, result.attrs?.rowspan || 1);
27783
+ if (rowspan > 1) {
27784
+ for (let offset2 = 0; offset2 < colspan; offset2 += 1) {
27785
+ const target = startColumn + offset2;
27786
+ if (target < pendingRowSpans.length) {
27787
+ pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
27788
+ }
27789
+ }
27790
+ }
27791
+ currentColumnIndex = startColumn + colspan;
27792
+ }
27793
+ });
27794
+ skipOccupiedColumns();
27795
+ fillUntil(totalColumns, "gridAfter");
27796
+ const newNode = {
27797
+ type: "tableRow",
27798
+ content,
27799
+ attrs: encodedAttrs
27800
+ };
27801
+ return newNode;
27802
+ };
27803
+ const decode$n = (params2, decodedAttrs) => {
27804
+ const { node } = params2;
27805
+ const cells = node.content || [];
27806
+ let leadingPlaceholders = 0;
27807
+ while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
27808
+ leadingPlaceholders += 1;
27809
+ }
27810
+ let trailingPlaceholders = 0;
27811
+ while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
27812
+ trailingPlaceholders += 1;
27813
+ }
27814
+ const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
27815
+ const sanitizedCells = trimmedSlice.map((cell) => {
27816
+ if (cell?.attrs && "__placeholder" in cell.attrs) {
27817
+ const { __placeholder, ...rest } = cell.attrs;
27818
+ return { ...cell, attrs: rest };
27819
+ }
27820
+ return cell;
27821
+ });
27822
+ const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
27823
+ const translateParams = {
27824
+ ...params2,
27825
+ node: { ...node, content: trimmedContent }
27826
+ };
27827
+ const elements = translateChildNodes(translateParams);
27828
+ if (node.attrs?.tableRowProperties) {
27829
+ const tableRowProperties = { ...node.attrs.tableRowProperties };
27830
+ if (leadingPlaceholders > 0) {
27831
+ tableRowProperties.gridBefore = leadingPlaceholders;
27832
+ }
27833
+ if (trailingPlaceholders > 0) {
27834
+ tableRowProperties.gridAfter = trailingPlaceholders;
27835
+ }
27836
+ if (node.attrs.rowHeight != null) {
27837
+ const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
27838
+ if (rowHeightPixels !== node.attrs.rowHeight) {
27839
+ tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
27840
+ }
27841
+ }
27842
+ tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
27843
+ const trPr = translator$v.decode({
27844
+ ...params2,
27845
+ node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
27846
+ });
27847
+ if (trPr) elements.unshift(trPr);
27848
+ }
27849
+ return {
27850
+ name: "w:tr",
27851
+ attributes: decodedAttrs || {},
27852
+ elements
27853
+ };
27854
+ };
27855
+ const config$e = {
27856
+ xmlName: XML_NODE_NAME$f,
27857
+ sdNodeOrKeyName: SD_NODE_NAME$c,
27858
+ type: NodeTranslator.translatorTypes.NODE,
27859
+ encode: encode$l,
27860
+ decode: decode$n,
27861
+ attributes: validXmlAttributes$a
27862
+ };
27863
+ const translator$u = NodeTranslator.from(config$e);
27864
+ function parseTagValueJSON(json) {
27865
+ if (typeof json !== "string") {
27866
+ return {};
27867
+ }
27868
+ const trimmed = json.trim();
27869
+ if (!trimmed) {
27870
+ return {};
27871
+ }
27872
+ try {
27873
+ return JSON.parse(trimmed);
27874
+ } catch {
27875
+ return {};
27876
+ }
27877
+ }
27878
+ function handleAnnotationNode(params2) {
27879
+ const { nodes } = params2;
27880
+ if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
27881
+ return null;
27882
+ }
27883
+ const node = nodes[0];
27884
+ const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
27885
+ const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
27886
+ const sdtId = sdtPr?.elements?.find((el) => el.name === "w:id");
27887
+ const alias = sdtPr?.elements.find((el) => el.name === "w:alias");
27888
+ const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
27889
+ const tagValue = tag?.attributes["w:val"];
27890
+ const shouldProcessAsJson = tagValue?.startsWith("{") && tagValue?.endsWith("}");
27891
+ let attrs = {};
27892
+ const aliasLabel = getSafeString(alias?.attributes?.["w:val"]);
27893
+ if (shouldProcessAsJson) {
27894
+ const parsedAttrs = parseTagValueJSON(tagValue);
27895
+ attrs = {
27896
+ type: parsedAttrs.fieldTypeShort,
27897
+ fieldId: parsedAttrs.fieldId,
27898
+ displayLabel: parsedAttrs.displayLabel,
27899
+ defaultDisplayLabel: parsedAttrs.defaultDisplayLabel,
27900
+ fieldType: parsedAttrs.fieldType,
27901
+ fieldColor: parsedAttrs.fieldColor,
27902
+ multipleImage: parsedAttrs.fieldMultipleImage,
27903
+ fontFamily: parsedAttrs.fieldFontFamily,
27904
+ fontSize: parsedAttrs.fieldFontSize,
27905
+ textColor: parsedAttrs.fieldTextColor,
27906
+ textHighlight: parsedAttrs.fieldTextHighlight,
27907
+ hash: parsedAttrs.hash
27908
+ };
27909
+ } else {
27910
+ attrs = getAttrsFromElements({ sdtPr, tag, alias, sdtId });
27911
+ }
27912
+ const initialDisplayLabel = getSafeString(attrs.displayLabel);
27913
+ const extractedContent = getTextFromSdtContent(sdtContent);
27914
+ if (!attrs.defaultDisplayLabel) {
27915
+ if (initialDisplayLabel) {
27916
+ attrs.defaultDisplayLabel = initialDisplayLabel;
27917
+ } else if (aliasLabel) {
27918
+ attrs.defaultDisplayLabel = aliasLabel;
27919
+ }
27920
+ }
27921
+ const placeholderLabel = getPlaceholderLabel(attrs, aliasLabel);
27922
+ const placeholderText = ensurePlaceholderFormat(placeholderLabel);
27923
+ const isAnnotationsEnabled = Boolean(params2.editor?.options?.annotations);
27924
+ const contentIsDistinct = shouldUseSdtContent(extractedContent, placeholderText);
27925
+ const shouldUseContent = !isAnnotationsEnabled && contentIsDistinct && (hasMoustache(extractedContent) || !placeholderText);
27926
+ if (contentIsDistinct) {
27927
+ attrs.displayLabel = extractedContent;
28586
27928
  } else if (!attrs.displayLabel && placeholderLabel) {
28587
27929
  attrs.displayLabel = placeholderLabel;
28588
27930
  }
@@ -28924,11 +28266,11 @@ function applyColorModifier(hexColor, modifier, value) {
28924
28266
  } else {
28925
28267
  return hexColor;
28926
28268
  }
28927
- const clamp = (n) => Math.max(0, Math.min(255, Math.round(n)));
28269
+ const clamp2 = (n) => Math.max(0, Math.min(255, Math.round(n)));
28928
28270
  const toHex2 = (n) => n.toString(16).padStart(2, "0");
28929
- newR = clamp(newR);
28930
- newG = clamp(newG);
28931
- newB = clamp(newB);
28271
+ newR = clamp2(newR);
28272
+ newG = clamp2(newG);
28273
+ newB = clamp2(newB);
28932
28274
  const result = `#${toHex2(newR)}${toHex2(newG)}${toHex2(newB)}`;
28933
28275
  return result;
28934
28276
  }
@@ -29841,32 +29183,32 @@ function translateAnchorNode(params2) {
29841
29183
  elements: [...anchorElements, ...elementsWithWrap]
29842
29184
  };
29843
29185
  }
29844
- const XML_NODE_NAME$c = "wp:anchor";
29845
- const SD_NODE_NAME$a = ["image"];
29186
+ const XML_NODE_NAME$e = "wp:anchor";
29187
+ const SD_NODE_NAME$b = ["image"];
29846
29188
  const validXmlAttributes$9 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
29847
- function encode$i(params2) {
29189
+ function encode$k(params2) {
29848
29190
  const { node } = params2.extraParams;
29849
29191
  if (!node || !node.type) {
29850
29192
  return null;
29851
29193
  }
29852
29194
  return handleAnchorNode(params2);
29853
29195
  }
29854
- function decode$k(params2) {
29196
+ function decode$m(params2) {
29855
29197
  const { node } = params2;
29856
29198
  if (!node || !node.type) {
29857
29199
  return null;
29858
29200
  }
29859
29201
  return translateAnchorNode(params2);
29860
29202
  }
29861
- const config$b = {
29862
- xmlName: XML_NODE_NAME$c,
29863
- sdNodeOrKeyName: SD_NODE_NAME$a,
29203
+ const config$d = {
29204
+ xmlName: XML_NODE_NAME$e,
29205
+ sdNodeOrKeyName: SD_NODE_NAME$b,
29864
29206
  type: NodeTranslator.translatorTypes.NODE,
29865
- encode: encode$i,
29866
- decode: decode$k,
29207
+ encode: encode$k,
29208
+ decode: decode$m,
29867
29209
  attributes: validXmlAttributes$9
29868
29210
  };
29869
- const translator$b = NodeTranslator.from(config$b);
29211
+ const translator$t = NodeTranslator.from(config$d);
29870
29212
  function handleInlineNode(params2) {
29871
29213
  const { node } = params2.extraParams;
29872
29214
  if (node.name !== "wp:inline") {
@@ -29882,41 +29224,41 @@ function translateInlineNode(params2) {
29882
29224
  elements: nodeElements.elements
29883
29225
  };
29884
29226
  }
29885
- const XML_NODE_NAME$b = "wp:inline";
29886
- const SD_NODE_NAME$9 = ["image"];
29227
+ const XML_NODE_NAME$d = "wp:inline";
29228
+ const SD_NODE_NAME$a = ["image"];
29887
29229
  const validXmlAttributes$8 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
29888
- function encode$h(params2) {
29230
+ function encode$j(params2) {
29889
29231
  const { node } = params2.extraParams;
29890
29232
  if (!node || !node.type) {
29891
29233
  return null;
29892
29234
  }
29893
29235
  return handleInlineNode(params2);
29894
29236
  }
29895
- function decode$j(params2) {
29237
+ function decode$l(params2) {
29896
29238
  const { node } = params2;
29897
29239
  if (!node || !node.type) {
29898
29240
  return null;
29899
29241
  }
29900
29242
  return translateInlineNode(params2);
29901
29243
  }
29902
- const config$a = {
29903
- xmlName: XML_NODE_NAME$b,
29904
- sdNodeOrKeyName: SD_NODE_NAME$9,
29244
+ const config$c = {
29245
+ xmlName: XML_NODE_NAME$d,
29246
+ sdNodeOrKeyName: SD_NODE_NAME$a,
29905
29247
  type: NodeTranslator.translatorTypes.NODE,
29906
- encode: encode$h,
29907
- decode: decode$j,
29248
+ encode: encode$j,
29249
+ decode: decode$l,
29908
29250
  attributes: validXmlAttributes$8
29909
29251
  };
29910
- const translator$a = NodeTranslator.from(config$a);
29911
- const XML_NODE_NAME$a = "w:drawing";
29912
- const SD_NODE_NAME$8 = [];
29252
+ const translator$s = NodeTranslator.from(config$c);
29253
+ const XML_NODE_NAME$c = "w:drawing";
29254
+ const SD_NODE_NAME$9 = [];
29913
29255
  const validXmlAttributes$7 = [];
29914
- function encode$g(params2) {
29256
+ function encode$i(params2) {
29915
29257
  const nodes = params2.nodes;
29916
29258
  const node = nodes[0];
29917
29259
  const translatorByChildName = {
29918
- "wp:anchor": translator$b,
29919
- "wp:inline": translator$a
29260
+ "wp:anchor": translator$t,
29261
+ "wp:inline": translator$s
29920
29262
  };
29921
29263
  return node.elements.reduce((acc, child) => {
29922
29264
  if (acc) return acc;
@@ -29925,12 +29267,12 @@ function encode$g(params2) {
29925
29267
  return translator2.encode({ ...params2, extraParams: { node: child } }) || acc;
29926
29268
  }, null);
29927
29269
  }
29928
- function decode$i(params2) {
29270
+ function decode$k(params2) {
29929
29271
  const { node } = params2;
29930
29272
  if (!node || !node.type) {
29931
29273
  return null;
29932
29274
  }
29933
- const childTranslator = node.attrs.isAnchor ? translator$b : translator$a;
29275
+ const childTranslator = node.attrs.isAnchor ? translator$t : translator$s;
29934
29276
  const resultNode = childTranslator.decode(params2);
29935
29277
  return wrapTextInRun(
29936
29278
  {
@@ -29940,15 +29282,15 @@ function decode$i(params2) {
29940
29282
  []
29941
29283
  );
29942
29284
  }
29943
- const config$9 = {
29944
- xmlName: XML_NODE_NAME$a,
29945
- sdNodeOrKeyName: SD_NODE_NAME$8,
29285
+ const config$b = {
29286
+ xmlName: XML_NODE_NAME$c,
29287
+ sdNodeOrKeyName: SD_NODE_NAME$9,
29946
29288
  type: NodeTranslator.translatorTypes.NODE,
29947
- encode: encode$g,
29948
- decode: decode$i,
29289
+ encode: encode$i,
29290
+ decode: decode$k,
29949
29291
  attributes: validXmlAttributes$7
29950
29292
  };
29951
- const translator$9 = NodeTranslator.from(config$9);
29293
+ const translator$r = NodeTranslator.from(config$b);
29952
29294
  class CommandService {
29953
29295
  /**
29954
29296
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -31296,7 +30638,7 @@ function prepareTextAnnotation(params2) {
31296
30638
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params2);
31297
30639
  }
31298
30640
  function prepareImageAnnotation(params2, imageSize) {
31299
- return translator$9.decode({
30641
+ return translator$r.decode({
31300
30642
  ...params2,
31301
30643
  imageSize
31302
30644
  });
@@ -31360,287 +30702,864 @@ function prepareUrlAnnotation(params2) {
31360
30702
  const linkTextNode = getTextNodeForExport(attrs.linkUrl, marks, params2);
31361
30703
  const contentNode = processLinkContentNode(linkTextNode);
31362
30704
  return {
31363
- name: "w:hyperlink",
31364
- type: "element",
31365
- attributes: {
31366
- "r:id": newId,
31367
- "w:history": 1
31368
- },
31369
- elements: [contentNode]
30705
+ name: "w:hyperlink",
30706
+ type: "element",
30707
+ attributes: {
30708
+ "r:id": newId,
30709
+ "w:history": 1
30710
+ },
30711
+ elements: [contentNode]
30712
+ };
30713
+ }
30714
+ function translateFieldAttrsToMarks(attrs = {}) {
30715
+ const { fontFamily: fontFamily2, fontSize: fontSize2, bold, underline, italic, textColor, textHighlight } = attrs;
30716
+ const marks = [];
30717
+ if (fontFamily2) marks.push({ type: "fontFamily", attrs: { fontFamily: fontFamily2 } });
30718
+ if (fontSize2) marks.push({ type: "fontSize", attrs: { fontSize: fontSize2 } });
30719
+ if (bold) marks.push({ type: "bold", attrs: {} });
30720
+ if (underline) marks.push({ type: "underline", attrs: {} });
30721
+ if (italic) marks.push({ type: "italic", attrs: {} });
30722
+ if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
30723
+ if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
30724
+ return marks;
30725
+ }
30726
+ function applyMarksToHtmlAnnotation(state2, marks) {
30727
+ const { tr, doc: doc2, schema } = state2;
30728
+ const allowedMarks = ["fontFamily", "fontSize", "highlight"];
30729
+ if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
30730
+ return state2;
30731
+ }
30732
+ const fontFamily2 = marks.find((m2) => m2.type === "fontFamily");
30733
+ const fontSize2 = marks.find((m2) => m2.type === "fontSize");
30734
+ const highlight = marks.find((m2) => m2.type === "highlight");
30735
+ const textStyleType = schema.marks.textStyle;
30736
+ const highlightType = schema.marks.highlight;
30737
+ doc2.descendants((node, pos) => {
30738
+ if (!node.isText) return;
30739
+ const foundTextStyle = node.marks.find((m2) => m2.type.name === "textStyle");
30740
+ const foundHighlight = node.marks.find((m2) => m2.type.name === "highlight");
30741
+ if (!foundTextStyle) {
30742
+ tr.addMark(
30743
+ pos,
30744
+ pos + node.nodeSize,
30745
+ textStyleType.create({
30746
+ ...fontFamily2?.attrs,
30747
+ ...fontSize2?.attrs
30748
+ })
30749
+ );
30750
+ } else if (!foundTextStyle?.attrs.fontFamily && fontFamily2) {
30751
+ tr.addMark(
30752
+ pos,
30753
+ pos + node.nodeSize,
30754
+ textStyleType.create({
30755
+ ...foundTextStyle?.attrs,
30756
+ ...fontFamily2.attrs
30757
+ })
30758
+ );
30759
+ } else if (!foundTextStyle?.attrs.fontSize && fontSize2) {
30760
+ tr.addMark(
30761
+ pos,
30762
+ pos + node.nodeSize,
30763
+ textStyleType.create({
30764
+ ...foundTextStyle?.attrs,
30765
+ ...fontSize2.attrs
30766
+ })
30767
+ );
30768
+ }
30769
+ if (!foundHighlight) {
30770
+ tr.addMark(
30771
+ pos,
30772
+ pos + node.nodeSize,
30773
+ highlightType.create({
30774
+ ...highlight?.attrs
30775
+ })
30776
+ );
30777
+ }
30778
+ });
30779
+ return state2.apply(tr);
30780
+ }
30781
+ function getFieldHighlightJson(fieldsHighlightColor) {
30782
+ if (!fieldsHighlightColor) return null;
30783
+ let parsedColor = fieldsHighlightColor.trim();
30784
+ const hexRegex2 = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
30785
+ if (!hexRegex2.test(parsedColor)) {
30786
+ console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
30787
+ return null;
30788
+ }
30789
+ if (parsedColor.startsWith("#")) {
30790
+ parsedColor = parsedColor.slice(1);
30791
+ }
30792
+ return {
30793
+ name: "w:rPr",
30794
+ elements: [
30795
+ {
30796
+ name: "w:shd",
30797
+ attributes: {
30798
+ "w:fill": `#${parsedColor}`,
30799
+ "w:color": "auto",
30800
+ "w:val": "clear"
30801
+ }
30802
+ }
30803
+ ]
30804
+ };
30805
+ }
30806
+ function translateDocumentSection(params2) {
30807
+ const { node } = params2;
30808
+ const { attrs = {} } = node;
30809
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
30810
+ const nodeElements = [
30811
+ {
30812
+ name: "w:sdtContent",
30813
+ elements: childContent
30814
+ }
30815
+ ];
30816
+ const exportedTag = JSON.stringify({
30817
+ type: "documentSection",
30818
+ description: attrs.description
30819
+ });
30820
+ const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
30821
+ const { isLocked } = attrs;
30822
+ if (isLocked) {
30823
+ sdtPr.elements.push({
30824
+ name: "w:lock",
30825
+ attributes: {
30826
+ "w:val": "sdtContentLocked"
30827
+ }
30828
+ });
30829
+ }
30830
+ nodeElements.unshift(sdtPr);
30831
+ const result = {
30832
+ name: "w:sdt",
30833
+ elements: nodeElements
30834
+ };
30835
+ return result;
30836
+ }
30837
+ const generateSdtPrTagForDocumentSection = (id, title, tag) => {
30838
+ return {
30839
+ name: "w:sdtPr",
30840
+ elements: [
30841
+ {
30842
+ name: "w:id",
30843
+ attributes: {
30844
+ "w:val": id
30845
+ }
30846
+ },
30847
+ {
30848
+ name: "w:alias",
30849
+ attributes: {
30850
+ "w:val": title
30851
+ }
30852
+ },
30853
+ {
30854
+ name: "w:tag",
30855
+ attributes: {
30856
+ "w:val": tag
30857
+ }
30858
+ }
30859
+ ]
30860
+ };
30861
+ };
30862
+ function translateDocumentPartObj(params2) {
30863
+ const { node } = params2;
30864
+ const { attrs = {} } = node;
30865
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
30866
+ const nodeElements = [
30867
+ {
30868
+ name: "w:sdtPr",
30869
+ elements: [
30870
+ {
30871
+ name: "w:id",
30872
+ attributes: {
30873
+ "w:val": attrs.id
30874
+ }
30875
+ },
30876
+ {
30877
+ name: "w:docPartObj",
30878
+ elements: [
30879
+ {
30880
+ name: "w:docPartGallery",
30881
+ attributes: {
30882
+ "w:val": attrs.docPartGallery
30883
+ }
30884
+ },
30885
+ ...attrs.docPartUnique ? [
30886
+ {
30887
+ name: "w:docPartUnique"
30888
+ }
30889
+ ] : []
30890
+ ]
30891
+ }
30892
+ ]
30893
+ },
30894
+ {
30895
+ name: "w:sdtContent",
30896
+ elements: childContent
30897
+ }
30898
+ ];
30899
+ const result = {
30900
+ name: "w:sdt",
30901
+ elements: nodeElements
30902
+ };
30903
+ return result;
30904
+ }
30905
+ function translateStructuredContent(params2) {
30906
+ const { node } = params2;
30907
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
30908
+ const sdtContent = { name: "w:sdtContent", elements: childContent };
30909
+ const sdtPr = generateSdtPrTagForStructuredContent({ node });
30910
+ const nodeElements = [sdtPr, sdtContent];
30911
+ const result = {
30912
+ name: "w:sdt",
30913
+ elements: nodeElements
30914
+ };
30915
+ return result;
30916
+ }
30917
+ function generateSdtPrTagForStructuredContent({ node }) {
30918
+ const { attrs = {} } = node;
30919
+ const id = {
30920
+ name: "w:id",
30921
+ type: "element",
30922
+ attributes: { "w:val": attrs.id }
30923
+ };
30924
+ const alias = {
30925
+ name: "w:alias",
30926
+ type: "element",
30927
+ attributes: { "w:val": attrs.alias }
30928
+ };
30929
+ const tag = {
30930
+ name: "w:tag",
30931
+ type: "element",
30932
+ attributes: { "w:val": attrs.tag }
30933
+ };
30934
+ const resultElements = [];
30935
+ if (attrs.id) resultElements.push(id);
30936
+ if (attrs.alias) resultElements.push(alias);
30937
+ if (attrs.tag) resultElements.push(tag);
30938
+ if (attrs.sdtPr) {
30939
+ const elements = attrs.sdtPr.elements || [];
30940
+ const elementsToExclude = ["w:id", "w:alias", "w:tag"];
30941
+ const restElements = elements.filter((el) => !elementsToExclude.includes(el.name));
30942
+ const result2 = {
30943
+ name: "w:sdtPr",
30944
+ type: "element",
30945
+ elements: [...resultElements, ...restElements]
30946
+ };
30947
+ return result2;
30948
+ }
30949
+ const result = {
30950
+ name: "w:sdtPr",
30951
+ type: "element",
30952
+ elements: resultElements
30953
+ };
30954
+ return result;
30955
+ }
30956
+ const XML_NODE_NAME$b = "w:sdt";
30957
+ const SD_NODE_NAME$8 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
30958
+ const validXmlAttributes$6 = [];
30959
+ function encode$h(params2) {
30960
+ const nodes = params2.nodes;
30961
+ const node = nodes[0];
30962
+ const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
30963
+ if (!handler2 || sdtType === "unknown") {
30964
+ return void 0;
30965
+ }
30966
+ const result = handler2(params2);
30967
+ return result;
30968
+ }
30969
+ function decode$j(params2) {
30970
+ const { node } = params2;
30971
+ if (!node || !node.type) {
30972
+ return null;
30973
+ }
30974
+ const types2 = {
30975
+ fieldAnnotation: () => translateFieldAnnotation(params2),
30976
+ structuredContent: () => translateStructuredContent(params2),
30977
+ structuredContentBlock: () => translateStructuredContent(params2),
30978
+ documentSection: () => translateDocumentSection(params2),
30979
+ documentPartObject: () => translateDocumentPartObj(params2),
30980
+ // Handled in doc-part-obj translator
30981
+ default: () => null
30982
+ };
30983
+ const decoder = types2[node.type] ?? types2.default;
30984
+ const result = decoder();
30985
+ return result;
30986
+ }
30987
+ const config$a = {
30988
+ xmlName: XML_NODE_NAME$b,
30989
+ sdNodeOrKeyName: SD_NODE_NAME$8,
30990
+ type: NodeTranslator.translatorTypes.NODE,
30991
+ encode: encode$h,
30992
+ decode: decode$j,
30993
+ attributes: validXmlAttributes$6
30994
+ };
30995
+ const translator$q = NodeTranslator.from(config$a);
30996
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
30997
+ if (!table || !Array.isArray(table.content)) {
30998
+ return table;
30999
+ }
31000
+ const rows = table.content;
31001
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
31002
+ const row = rows[rowIndex];
31003
+ if (!row) continue;
31004
+ if (!Array.isArray(row.content)) {
31005
+ row.content = [];
31006
+ }
31007
+ for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
31008
+ const cell = row.content[cellIndex];
31009
+ if (!cell) continue;
31010
+ const attrs = cell.attrs || {};
31011
+ if (!attrs.rowspan || attrs.rowspan <= 1) continue;
31012
+ const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
31013
+ for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
31014
+ const rowToChange = rows[rowIndex + offset2];
31015
+ if (!rowToChange) continue;
31016
+ if (!Array.isArray(rowToChange.content)) {
31017
+ rowToChange.content = [];
31018
+ }
31019
+ const existingCell = rowToChange.content[cellIndex];
31020
+ if (existingCell?.attrs?.continueMerge) continue;
31021
+ const mergedCell = {
31022
+ type: cell.type,
31023
+ content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
31024
+ attrs: {
31025
+ ...cell.attrs,
31026
+ rowspan: null,
31027
+ continueMerge: true
31028
+ }
31029
+ };
31030
+ rowToChange.content.splice(cellIndex, 0, mergedCell);
31031
+ }
31032
+ }
31033
+ }
31034
+ return table;
31035
+ }
31036
+ const translator$p = NodeTranslator.from({
31037
+ xmlName: "w:bidiVisual",
31038
+ sdNodeOrKeyName: "rightToLeft",
31039
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
31040
+ decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
31041
+ });
31042
+ const translator$o = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
31043
+ const translator$n = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
31044
+ const translator$m = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
31045
+ const translator$l = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
31046
+ const translator$k = NodeTranslator.from({
31047
+ xmlName: "w:tblLook",
31048
+ sdNodeOrKeyName: "tblLook",
31049
+ attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
31050
+ encode: (params2, encodedAttrs) => {
31051
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
31052
+ },
31053
+ decode: function({ node }, context) {
31054
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
31055
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
31056
+ }
31057
+ });
31058
+ const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
31059
+ const translator$i = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
31060
+ const translator$h = NodeTranslator.from(
31061
+ createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
31062
+ );
31063
+ const translator$g = NodeTranslator.from(
31064
+ createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
31065
+ );
31066
+ const translator$f = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
31067
+ const translator$e = NodeTranslator.from({
31068
+ xmlName: "w:tblpPr",
31069
+ sdNodeOrKeyName: "floatingTableProperties",
31070
+ attributes: ["w:leftFromText", "w:rightFromText", "w:topFromText", "w:bottomFromText", "w:tblpX", "w:tblpY"].map((attr) => createAttributeHandler(attr, null, parseInteger, integerToString)).concat(["w:horzAnchor", "w:vertAnchor", "w:tblpXSpec", "w:tblpYSpec"].map((attr) => createAttributeHandler(attr))),
31071
+ encode: (params2, encodedAttrs) => {
31072
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
31073
+ },
31074
+ decode: function({ node }, context) {
31075
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
31076
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
31077
+ }
31078
+ });
31079
+ const propertyTranslators$2 = [
31080
+ translator$15,
31081
+ translator$13,
31082
+ translator$11,
31083
+ translator$10,
31084
+ translator$$,
31085
+ translator$Z,
31086
+ translator$X,
31087
+ translator$V
31088
+ ];
31089
+ const translator$d = NodeTranslator.from(
31090
+ createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$2)
31091
+ );
31092
+ const propertyTranslators$1 = [
31093
+ translator$14,
31094
+ translator$12,
31095
+ translator$_,
31096
+ translator$Y,
31097
+ translator$W,
31098
+ translator$U
31099
+ ];
31100
+ const translator$c = NodeTranslator.from(
31101
+ createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$1)
31102
+ );
31103
+ const propertyTranslators = [
31104
+ translator$p,
31105
+ translator$B,
31106
+ translator$19,
31107
+ translator$o,
31108
+ translator$A,
31109
+ translator$n,
31110
+ translator$m,
31111
+ translator$l,
31112
+ translator$k,
31113
+ translator$j,
31114
+ translator$i,
31115
+ translator$h,
31116
+ translator$g,
31117
+ translator$f,
31118
+ translator$e,
31119
+ translator$d,
31120
+ translator$c
31121
+ ];
31122
+ const translator$b = NodeTranslator.from(
31123
+ createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators)
31124
+ );
31125
+ const translator$a = NodeTranslator.from(
31126
+ createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
31127
+ );
31128
+ const DEFAULT_COLUMN_WIDTH_PX = 100;
31129
+ const normalizeTwipWidth = (value) => {
31130
+ if (value == null) return null;
31131
+ const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
31132
+ if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
31133
+ return null;
31134
+ }
31135
+ return numericValue;
31136
+ };
31137
+ const getSchemaDefaultColumnWidthPx = (params2) => {
31138
+ const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
31139
+ if (Array.isArray(defaultValue)) {
31140
+ const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
31141
+ if (numericWidth != null) return numericWidth;
31142
+ } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
31143
+ return defaultValue;
31144
+ }
31145
+ return DEFAULT_COLUMN_WIDTH_PX;
31146
+ };
31147
+ const getTableWidthPx = (params2) => {
31148
+ const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
31149
+ if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
31150
+ const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
31151
+ if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
31152
+ const { value, type: type2 } = tableWidth;
31153
+ if (!type2 || type2 === "auto" || type2 === "dxa") {
31154
+ return twipsToPixels(value);
31155
+ }
31156
+ }
31157
+ return null;
31158
+ };
31159
+ const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
31160
+ const columnCount = Math.max(totalColumns, 1);
31161
+ const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
31162
+ const tableWidthPx = getTableWidthPx(params2);
31163
+ const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
31164
+ let fallbackWidthPx = safeDefaultPx;
31165
+ if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
31166
+ fallbackWidthPx = tableWidthPx / columnCount;
31167
+ }
31168
+ const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
31169
+ if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
31170
+ const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
31171
+ return safeDefault;
31172
+ }
31173
+ return Math.max(fallbackWidthTwips, cellMinWidthTwips);
31174
+ };
31175
+ const XML_NODE_NAME$a = "w:tblGrid";
31176
+ const SD_ATTR_KEY$2 = "grid";
31177
+ const cellMinWidth = pixelsToTwips(10);
31178
+ const encode$g = (params2) => {
31179
+ const { nodes } = params2;
31180
+ const node = nodes[0];
31181
+ const attributes = encodeProperties(node, { [translator$a.xmlName]: translator$a }, true);
31182
+ return {
31183
+ xmlName: XML_NODE_NAME$a,
31184
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
31185
+ attributes
31186
+ };
31187
+ };
31188
+ const decode$i = (params2) => {
31189
+ const { grid: rawGrid } = params2.node.attrs || {};
31190
+ const grid = Array.isArray(rawGrid) ? rawGrid : [];
31191
+ const { firstRow = {} } = params2.extraParams || {};
31192
+ const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
31193
+ const columnCountFromCells = cellNodes.reduce((count, cell) => {
31194
+ const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
31195
+ return count + spanCount;
31196
+ }, 0);
31197
+ const totalColumns = Math.max(columnCountFromCells, grid.length);
31198
+ const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
31199
+ const elements = [];
31200
+ let columnIndex = 0;
31201
+ const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
31202
+ let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
31203
+ let shouldEnforceMinimum = enforceMinimum;
31204
+ if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
31205
+ numericWidth = fallbackColumnWidthTwips;
31206
+ shouldEnforceMinimum = true;
31207
+ }
31208
+ const roundedWidth = Math.round(numericWidth);
31209
+ const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
31210
+ const safeWidth = Math.max(roundedWidth, minimumWidth);
31211
+ const decoded = translator$a.decode({
31212
+ node: { type: (
31213
+ /** @type {string} */
31214
+ translator$a.sdNodeOrKeyName
31215
+ ), attrs: { col: safeWidth } }
31216
+ });
31217
+ if (decoded) elements.push(decoded);
31218
+ };
31219
+ cellNodes.forEach((cell) => {
31220
+ const { colspan = 1, colwidth } = cell?.attrs || {};
31221
+ const spanCount = Math.max(1, colspan);
31222
+ for (let span = 0; span < spanCount; span++) {
31223
+ const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
31224
+ const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
31225
+ const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
31226
+ const colGridAttrs = grid?.[columnIndex] || {};
31227
+ const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
31228
+ const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
31229
+ let cellWidthTwips;
31230
+ let enforceMinimum = false;
31231
+ if (hasCellWidth) {
31232
+ const tolerance = 0.5;
31233
+ if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
31234
+ cellWidthTwips = gridWidthTwips;
31235
+ } else {
31236
+ cellWidthTwips = pixelsToTwips(cellWidthPixels);
31237
+ }
31238
+ } else if (gridWidthTwips != null) {
31239
+ cellWidthTwips = gridWidthTwips;
31240
+ } else {
31241
+ cellWidthTwips = fallbackColumnWidthTwips;
31242
+ enforceMinimum = true;
31243
+ }
31244
+ pushColumn(cellWidthTwips, { enforceMinimum });
31245
+ columnIndex++;
31246
+ }
31247
+ });
31248
+ while (columnIndex < grid.length) {
31249
+ const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
31250
+ pushColumn(gridWidthTwips);
31251
+ columnIndex++;
31252
+ }
31253
+ const newNode = {
31254
+ name: XML_NODE_NAME$a,
31255
+ attributes: {},
31256
+ elements
31257
+ };
31258
+ return newNode;
31259
+ };
31260
+ const config$9 = {
31261
+ xmlName: XML_NODE_NAME$a,
31262
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
31263
+ encode: encode$g,
31264
+ decode: decode$i
31265
+ };
31266
+ const translator$9 = NodeTranslator.from(config$9);
31267
+ const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
31268
+ const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
31269
+ const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
31270
+ const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
31271
+ const pctToPercent = (value) => {
31272
+ if (value == null) return null;
31273
+ return value / 50;
31274
+ };
31275
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
31276
+ const resolveMeasurementWidthPx = (measurement) => {
31277
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
31278
+ const { value, type: type2 } = measurement;
31279
+ if (!type2 || type2 === "auto") return null;
31280
+ if (type2 === "dxa") return twipsToPixels(value);
31281
+ if (type2 === "pct") {
31282
+ const percent2 = pctToPercent(value);
31283
+ if (percent2 == null || percent2 <= 0) return null;
31284
+ const widthTwips = resolveContentWidthTwips() * percent2 / 100;
31285
+ return twipsToPixels(widthTwips);
31286
+ }
31287
+ return null;
31288
+ };
31289
+ const countColumnsInRow = (row) => {
31290
+ if (!row?.elements?.length) return 0;
31291
+ return row.elements.reduce((count, element) => {
31292
+ if (element.name !== "w:tc") return count;
31293
+ const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
31294
+ const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
31295
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
31296
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
31297
+ }, 0);
31298
+ };
31299
+ const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
31300
+ const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
31301
+ const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
31302
+ const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
31303
+ const columnCount = countColumnsInRow(firstRow);
31304
+ if (!columnCount) return null;
31305
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
31306
+ /** @type {any} */
31307
+ params2
31308
+ );
31309
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
31310
+ let totalWidthPx;
31311
+ if (tableWidthMeasurement) {
31312
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
31313
+ if (resolved != null) totalWidthPx = resolved;
31314
+ }
31315
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
31316
+ totalWidthPx = tableWidth.width;
31317
+ }
31318
+ if (totalWidthPx == null) {
31319
+ totalWidthPx = minimumColumnWidthPx * columnCount;
31320
+ }
31321
+ const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
31322
+ const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
31323
+ const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
31324
+ return {
31325
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
31326
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
31370
31327
  };
31371
- }
31372
- function translateFieldAttrsToMarks(attrs = {}) {
31373
- const { fontFamily: fontFamily2, fontSize: fontSize2, bold, underline, italic, textColor, textHighlight } = attrs;
31374
- const marks = [];
31375
- if (fontFamily2) marks.push({ type: "fontFamily", attrs: { fontFamily: fontFamily2 } });
31376
- if (fontSize2) marks.push({ type: "fontSize", attrs: { fontSize: fontSize2 } });
31377
- if (bold) marks.push({ type: "bold", attrs: {} });
31378
- if (underline) marks.push({ type: "underline", attrs: {} });
31379
- if (italic) marks.push({ type: "italic", attrs: {} });
31380
- if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
31381
- if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
31382
- return marks;
31383
- }
31384
- function applyMarksToHtmlAnnotation(state2, marks) {
31385
- const { tr, doc: doc2, schema } = state2;
31386
- const allowedMarks = ["fontFamily", "fontSize", "highlight"];
31387
- if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
31388
- return state2;
31328
+ };
31329
+ const XML_NODE_NAME$9 = "w:tbl";
31330
+ const SD_NODE_NAME$7 = "table";
31331
+ const encode$f = (params2, encodedAttrs) => {
31332
+ const { nodes } = params2;
31333
+ const node = nodes[0];
31334
+ const tblPr = node.elements.find((el) => el.name === "w:tblPr");
31335
+ if (tblPr) {
31336
+ const encodedProperties = translator$b.encode({ ...params2, nodes: [tblPr] });
31337
+ encodedAttrs["tableProperties"] = encodedProperties || {};
31389
31338
  }
31390
- const fontFamily2 = marks.find((m2) => m2.type === "fontFamily");
31391
- const fontSize2 = marks.find((m2) => m2.type === "fontSize");
31392
- const highlight = marks.find((m2) => m2.type === "highlight");
31393
- const textStyleType = schema.marks.textStyle;
31394
- const highlightType = schema.marks.highlight;
31395
- doc2.descendants((node, pos) => {
31396
- if (!node.isText) return;
31397
- const foundTextStyle = node.marks.find((m2) => m2.type.name === "textStyle");
31398
- const foundHighlight = node.marks.find((m2) => m2.type.name === "highlight");
31399
- if (!foundTextStyle) {
31400
- tr.addMark(
31401
- pos,
31402
- pos + node.nodeSize,
31403
- textStyleType.create({
31404
- ...fontFamily2?.attrs,
31405
- ...fontSize2?.attrs
31406
- })
31407
- );
31408
- } else if (!foundTextStyle?.attrs.fontFamily && fontFamily2) {
31409
- tr.addMark(
31410
- pos,
31411
- pos + node.nodeSize,
31412
- textStyleType.create({
31413
- ...foundTextStyle?.attrs,
31414
- ...fontFamily2.attrs
31415
- })
31416
- );
31417
- } else if (!foundTextStyle?.attrs.fontSize && fontSize2) {
31418
- tr.addMark(
31419
- pos,
31420
- pos + node.nodeSize,
31421
- textStyleType.create({
31422
- ...foundTextStyle?.attrs,
31423
- ...fontSize2.attrs
31424
- })
31425
- );
31339
+ const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
31340
+ if (tblGrid) {
31341
+ encodedAttrs["grid"] = translator$9.encode({ ...params2, nodes: [tblGrid] }).attributes;
31342
+ }
31343
+ [
31344
+ "tableStyleId",
31345
+ "justification",
31346
+ "tableLayout",
31347
+ ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
31348
+ ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
31349
+ ].forEach((prop) => {
31350
+ let key2;
31351
+ let transform;
31352
+ if (Array.isArray(prop)) {
31353
+ [key2, transform] = prop;
31354
+ } else {
31355
+ key2 = prop;
31356
+ transform = (v2) => v2;
31426
31357
  }
31427
- if (!foundHighlight) {
31428
- tr.addMark(
31429
- pos,
31430
- pos + node.nodeSize,
31431
- highlightType.create({
31432
- ...highlight?.attrs
31433
- })
31434
- );
31358
+ if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
31359
+ encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
31435
31360
  }
31436
31361
  });
31437
- return state2.apply(tr);
31438
- }
31439
- function getFieldHighlightJson(fieldsHighlightColor) {
31440
- if (!fieldsHighlightColor) return null;
31441
- let parsedColor = fieldsHighlightColor.trim();
31442
- const hexRegex2 = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
31443
- if (!hexRegex2.test(parsedColor)) {
31444
- console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
31445
- return null;
31362
+ if (encodedAttrs.tableCellSpacing) {
31363
+ encodedAttrs["borderCollapse"] = "separate";
31446
31364
  }
31447
- if (parsedColor.startsWith("#")) {
31448
- parsedColor = parsedColor.slice(1);
31365
+ if (encodedAttrs.tableProperties?.tableWidth) {
31366
+ const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
31367
+ const widthPx = twipsToPixels(tableWidthMeasurement.value);
31368
+ if (widthPx != null) {
31369
+ encodedAttrs.tableWidth = {
31370
+ width: widthPx,
31371
+ type: tableWidthMeasurement.type
31372
+ };
31373
+ } else if (tableWidthMeasurement.type === "auto") {
31374
+ encodedAttrs.tableWidth = {
31375
+ width: 0,
31376
+ type: tableWidthMeasurement.type
31377
+ };
31378
+ }
31449
31379
  }
31450
- return {
31451
- name: "w:rPr",
31452
- elements: [
31453
- {
31454
- name: "w:shd",
31455
- attributes: {
31456
- "w:fill": `#${parsedColor}`,
31457
- "w:color": "auto",
31458
- "w:val": "clear"
31380
+ const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
31381
+ const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
31382
+ if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
31383
+ encodedAttrs.tableProperties = {
31384
+ ...encodedAttrs.tableProperties || {},
31385
+ cellMargins: referencedStyles.cellMargins
31386
+ };
31387
+ }
31388
+ const rows = node.elements.filter((el) => el.name === "w:tr");
31389
+ const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
31390
+ const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
31391
+ encodedAttrs["borders"] = borderData;
31392
+ let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
31393
+ if (!columnWidths.length) {
31394
+ const fallback = buildFallbackGridForTable({
31395
+ params: params2,
31396
+ rows,
31397
+ tableWidth: encodedAttrs.tableWidth,
31398
+ tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
31399
+ });
31400
+ if (fallback) {
31401
+ encodedAttrs.grid = fallback.grid;
31402
+ columnWidths = fallback.columnWidths;
31403
+ }
31404
+ }
31405
+ const content = [];
31406
+ const totalColumns = columnWidths.length;
31407
+ const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
31408
+ rows.forEach((row, rowIndex) => {
31409
+ const result = translator$u.encode({
31410
+ ...params2,
31411
+ nodes: [row],
31412
+ extraParams: {
31413
+ row,
31414
+ table: node,
31415
+ rowBorders: borderRowData,
31416
+ columnWidths,
31417
+ activeRowSpans: activeRowSpans.slice(),
31418
+ rowIndex,
31419
+ _referencedStyles: referencedStyles
31420
+ }
31421
+ });
31422
+ if (result) {
31423
+ content.push(result);
31424
+ if (totalColumns > 0) {
31425
+ const activeRowSpansForCurrentRow = activeRowSpans.slice();
31426
+ for (let col = 0; col < totalColumns; col++) {
31427
+ if (activeRowSpans[col] > 0) {
31428
+ activeRowSpans[col] -= 1;
31429
+ }
31459
31430
  }
31431
+ let columnIndex = 0;
31432
+ const advanceColumnIndex = () => {
31433
+ while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
31434
+ columnIndex += 1;
31435
+ }
31436
+ };
31437
+ advanceColumnIndex();
31438
+ result.content?.forEach((cell) => {
31439
+ advanceColumnIndex();
31440
+ const colspan = Math.max(1, cell.attrs?.colspan || 1);
31441
+ const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
31442
+ if (rowspan > 1) {
31443
+ for (let offset2 = 0; offset2 < colspan && columnIndex + offset2 < totalColumns; offset2++) {
31444
+ const targetIndex = columnIndex + offset2;
31445
+ const remainingRows = rowspan - 1;
31446
+ if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
31447
+ activeRowSpans[targetIndex] = remainingRows;
31448
+ }
31449
+ }
31450
+ }
31451
+ columnIndex += colspan;
31452
+ advanceColumnIndex();
31453
+ });
31460
31454
  }
31461
- ]
31455
+ }
31456
+ });
31457
+ return {
31458
+ type: "table",
31459
+ content,
31460
+ attrs: encodedAttrs
31462
31461
  };
31463
- }
31464
- function translateDocumentSection(params2) {
31462
+ };
31463
+ const decode$h = (params2, decodedAttrs) => {
31464
+ params2.node = preProcessVerticalMergeCells(params2.node, params2);
31465
31465
  const { node } = params2;
31466
- const { attrs = {} } = node;
31467
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
31468
- const nodeElements = [
31469
- {
31470
- name: "w:sdtContent",
31471
- elements: childContent
31466
+ const elements = translateChildNodes(params2);
31467
+ const firstRow = node.content?.find((n) => n.type === "tableRow");
31468
+ const properties = node.attrs.grid;
31469
+ const element = translator$9.decode({
31470
+ ...params2,
31471
+ node: { ...node, attrs: { ...node.attrs, grid: properties } },
31472
+ extraParams: {
31473
+ firstRow
31472
31474
  }
31473
- ];
31474
- const exportedTag = JSON.stringify({
31475
- type: "documentSection",
31476
- description: attrs.description
31477
31475
  });
31478
- const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
31479
- const { isLocked } = attrs;
31480
- if (isLocked) {
31481
- sdtPr.elements.push({
31482
- name: "w:lock",
31483
- attributes: {
31484
- "w:val": "sdtContentLocked"
31485
- }
31476
+ if (element) elements.unshift(element);
31477
+ if (node.attrs?.tableProperties) {
31478
+ const properties2 = { ...node.attrs.tableProperties };
31479
+ const element2 = translator$b.decode({
31480
+ ...params2,
31481
+ node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
31486
31482
  });
31483
+ if (element2) elements.unshift(element2);
31487
31484
  }
31488
- nodeElements.unshift(sdtPr);
31489
- const result = {
31490
- name: "w:sdt",
31491
- elements: nodeElements
31492
- };
31493
- return result;
31494
- }
31495
- const generateSdtPrTagForDocumentSection = (id, title, tag) => {
31496
31485
  return {
31497
- name: "w:sdtPr",
31498
- elements: [
31499
- {
31500
- name: "w:id",
31501
- attributes: {
31502
- "w:val": id
31503
- }
31504
- },
31505
- {
31506
- name: "w:alias",
31507
- attributes: {
31508
- "w:val": title
31509
- }
31510
- },
31511
- {
31512
- name: "w:tag",
31513
- attributes: {
31514
- "w:val": tag
31515
- }
31516
- }
31517
- ]
31486
+ name: "w:tbl",
31487
+ attributes: decodedAttrs || {},
31488
+ elements
31518
31489
  };
31519
31490
  };
31520
- function translateDocumentPartObj(params2) {
31521
- const { node } = params2;
31522
- const { attrs = {} } = node;
31523
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
31524
- const nodeElements = [
31525
- {
31526
- name: "w:sdtPr",
31527
- elements: [
31528
- {
31529
- name: "w:id",
31530
- attributes: {
31531
- "w:val": attrs.id
31532
- }
31533
- },
31534
- {
31535
- name: "w:docPartObj",
31536
- elements: [
31537
- {
31538
- name: "w:docPartGallery",
31539
- attributes: {
31540
- "w:val": attrs.docPartGallery
31541
- }
31542
- },
31543
- ...attrs.docPartUnique ? [
31544
- {
31545
- name: "w:docPartUnique"
31546
- }
31547
- ] : []
31548
- ]
31549
- }
31550
- ]
31551
- },
31552
- {
31553
- name: "w:sdtContent",
31554
- elements: childContent
31555
- }
31556
- ];
31557
- const result = {
31558
- name: "w:sdt",
31559
- elements: nodeElements
31560
- };
31561
- return result;
31562
- }
31563
- function translateStructuredContent(params2) {
31564
- const { node } = params2;
31565
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
31566
- const sdtContent = { name: "w:sdtContent", elements: childContent };
31567
- const sdtPr = generateSdtPrTagForStructuredContent({ node });
31568
- const nodeElements = [sdtPr, sdtContent];
31569
- const result = {
31570
- name: "w:sdt",
31571
- elements: nodeElements
31491
+ function _processTableBorders(rawBorders) {
31492
+ const borders = {};
31493
+ const rowBorders = {};
31494
+ Object.entries(rawBorders).forEach(([name, attributes]) => {
31495
+ const attrs = {};
31496
+ const color = attributes.color;
31497
+ const size2 = attributes.size;
31498
+ if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
31499
+ if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
31500
+ const rowBorderNames = ["insideH", "insideV"];
31501
+ if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
31502
+ borders[name] = attrs;
31503
+ });
31504
+ return {
31505
+ borders,
31506
+ rowBorders
31572
31507
  };
31573
- return result;
31574
31508
  }
31575
- function generateSdtPrTagForStructuredContent({ node }) {
31576
- const { attrs = {} } = node;
31577
- const id = {
31578
- name: "w:id",
31579
- type: "element",
31580
- attributes: { "w:val": attrs.id }
31581
- };
31582
- const alias = {
31583
- name: "w:alias",
31584
- type: "element",
31585
- attributes: { "w:val": attrs.alias }
31586
- };
31587
- const tag = {
31588
- name: "w:tag",
31589
- type: "element",
31590
- attributes: { "w:val": attrs.tag }
31591
- };
31592
- const resultElements = [];
31593
- if (attrs.id) resultElements.push(id);
31594
- if (attrs.alias) resultElements.push(alias);
31595
- if (attrs.tag) resultElements.push(tag);
31596
- if (attrs.sdtPr) {
31597
- const elements = attrs.sdtPr.elements || [];
31598
- const elementsToExclude = ["w:id", "w:alias", "w:tag"];
31599
- const restElements = elements.filter((el) => !elementsToExclude.includes(el.name));
31600
- const result2 = {
31601
- name: "w:sdtPr",
31602
- type: "element",
31603
- elements: [...resultElements, ...restElements]
31604
- };
31605
- return result2;
31509
+ function _getReferencedTableStyles(tableStyleReference, params2) {
31510
+ if (!tableStyleReference) return null;
31511
+ const stylesToReturn = {};
31512
+ const { docx } = params2;
31513
+ const styles = docx["word/styles.xml"];
31514
+ const { elements } = styles.elements[0];
31515
+ const styleElements = elements.filter((el) => el.name === "w:style");
31516
+ const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
31517
+ if (!styleTag) return null;
31518
+ stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
31519
+ const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
31520
+ let baseTblPr;
31521
+ if (basedOn?.attributes) {
31522
+ const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
31523
+ baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
31606
31524
  }
31607
- const result = {
31608
- name: "w:sdtPr",
31609
- type: "element",
31610
- elements: resultElements
31611
- };
31612
- return result;
31613
- }
31614
- const XML_NODE_NAME$9 = "w:sdt";
31615
- const SD_NODE_NAME$7 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
31616
- const validXmlAttributes$6 = [];
31617
- function encode$f(params2) {
31618
- const nodes = params2.nodes;
31619
- const node = nodes[0];
31620
- const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
31621
- if (!handler2 || sdtType === "unknown") {
31622
- return void 0;
31525
+ const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
31526
+ if (pPr) {
31527
+ const justification = pPr.elements.find((el) => el.name === "w:jc");
31528
+ if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
31623
31529
  }
31624
- const result = handler2(params2);
31625
- return result;
31626
- }
31627
- function decode$h(params2) {
31628
- const { node } = params2;
31629
- if (!node || !node.type) {
31630
- return null;
31530
+ const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
31531
+ if (rPr) {
31532
+ const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
31533
+ if (fonts) {
31534
+ const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
31535
+ stylesToReturn.fonts = { ascii, hAnsi, cs };
31536
+ }
31537
+ const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
31538
+ if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
31631
31539
  }
31632
- const types2 = {
31633
- fieldAnnotation: () => translateFieldAnnotation(params2),
31634
- structuredContent: () => translateStructuredContent(params2),
31635
- structuredContentBlock: () => translateStructuredContent(params2),
31636
- documentSection: () => translateDocumentSection(params2),
31637
- documentPartObject: () => translateDocumentPartObj(params2),
31638
- // Handled in doc-part-obj translator
31639
- default: () => null
31640
- };
31641
- const decoder = types2[node.type] ?? types2.default;
31642
- const result = decoder();
31643
- return result;
31540
+ const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
31541
+ if (tblPr && tblPr.elements) {
31542
+ if (baseTblPr && baseTblPr.elements) {
31543
+ tblPr.elements.push(...baseTblPr.elements);
31544
+ }
31545
+ const tableProperties = translator$b.encode({ ...params2, nodes: [tblPr] });
31546
+ if (tableProperties) {
31547
+ const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
31548
+ if (borders) stylesToReturn.borders = borders;
31549
+ if (rowBorders) stylesToReturn.rowBorders = rowBorders;
31550
+ const cellMargins = {};
31551
+ Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
31552
+ if (attrs?.value != null) {
31553
+ cellMargins[key2] = {
31554
+ value: attrs.value,
31555
+ type: attrs.type || "dxa"
31556
+ };
31557
+ }
31558
+ });
31559
+ if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
31560
+ }
31561
+ }
31562
+ return stylesToReturn;
31644
31563
  }
31645
31564
  const config$8 = {
31646
31565
  xmlName: XML_NODE_NAME$9,
@@ -31648,7 +31567,7 @@ const config$8 = {
31648
31567
  type: NodeTranslator.translatorTypes.NODE,
31649
31568
  encode: encode$f,
31650
31569
  decode: decode$h,
31651
- attributes: validXmlAttributes$6
31570
+ attributes: []
31652
31571
  };
31653
31572
  const translator$8 = NodeTranslator.from(config$8);
31654
31573
  const encode$e = (attributes) => {
@@ -32163,7 +32082,7 @@ const handleDrawingNode = (params2) => {
32163
32082
  if (mainNode.name === "w:drawing") node = mainNode;
32164
32083
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
32165
32084
  if (!node) return { nodes: [], consumed: 0 };
32166
- const schemaNode = translator$9.encode(params2);
32085
+ const schemaNode = translator$r.encode(params2);
32167
32086
  const newNodes = schemaNode ? [schemaNode] : [];
32168
32087
  return { nodes: newNodes, consumed: 1 };
32169
32088
  };
@@ -32472,7 +32391,7 @@ const handleSdtNode = (params2) => {
32472
32391
  if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
32473
32392
  return { nodes: [], consumed: 0 };
32474
32393
  }
32475
- const result = translator$8.encode(params2);
32394
+ const result = translator$q.encode(params2);
32476
32395
  if (!result) {
32477
32396
  return { nodes: [], consumed: 0 };
32478
32397
  }
@@ -33100,6 +33019,11 @@ const comments_module_events = Object.freeze({
33100
33019
  CHANGE_REJECTED: "change-rejected"
33101
33020
  });
33102
33021
  const getFileObject = async (fileUrl, name, type2) => {
33022
+ if (fileUrl.startsWith("data:") && fileUrl.includes(";base64,")) {
33023
+ const binary = atob(fileUrl.split(",")[1]);
33024
+ const bytes = Uint8Array.from(binary, (c2) => c2.charCodeAt(0));
33025
+ return new File([bytes], name, { type: type2 });
33026
+ }
33103
33027
  const response = await fetch(fileUrl);
33104
33028
  const blob = await response.blob();
33105
33029
  return new File([blob], name, { type: type2 });
@@ -33261,6 +33185,7 @@ const tabNodeEntityHandler = {
33261
33185
  handlerName: "w:tabTranslator",
33262
33186
  handler: handleTabNode
33263
33187
  };
33188
+ const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$8);
33264
33189
  const tableOfContentsHandlerEntity = generateV2HandlerEntity("tableOfContentsHandler", translator$4);
33265
33190
  function preProcessPageInstruction(nodesToCombine) {
33266
33191
  const pageNumNode = {
@@ -34274,14 +34199,14 @@ function exportSchemaToJson(params2) {
34274
34199
  bulletList: translateList,
34275
34200
  orderedList: translateList,
34276
34201
  lineBreak: translator$1r,
34277
- table: translator$s,
34278
- tableRow: translator$Z,
34279
- tableCell: translator$c,
34202
+ table: translator$8,
34203
+ tableRow: translator$u,
34204
+ tableCell: translator$H,
34280
34205
  bookmarkStart: translator$7,
34281
34206
  bookmarkEnd: translator$6,
34282
- fieldAnnotation: translator$8,
34207
+ fieldAnnotation: translator$q,
34283
34208
  tab: translator$1p,
34284
- image: translator$9,
34209
+ image: translator$r,
34285
34210
  hardBreak: translator$1r,
34286
34211
  commentRangeStart: commentRangeStartTranslator,
34287
34212
  commentRangeEnd: commentRangeEndTranslator,
@@ -34290,10 +34215,10 @@ function exportSchemaToJson(params2) {
34290
34215
  shapeTextbox: translator,
34291
34216
  contentBlock: translator,
34292
34217
  vectorShape: translateVectorShape,
34293
- structuredContent: translator$8,
34294
- structuredContentBlock: translator$8,
34295
- documentPartObject: translator$8,
34296
- documentSection: translator$8,
34218
+ structuredContent: translator$q,
34219
+ structuredContentBlock: translator$q,
34220
+ documentPartObject: translator$q,
34221
+ documentSection: translator$q,
34297
34222
  "page-number": translatePageNumberNode,
34298
34223
  "total-page-number": translateTotalPageNumberNode,
34299
34224
  pageReference: translator$5,
@@ -35503,7 +35428,7 @@ const _SuperConverter = class _SuperConverter2 {
35503
35428
  static getStoredSuperdocVersion(docx) {
35504
35429
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
35505
35430
  }
35506
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "0.29.0-RC.1") {
35431
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "0.29.0-RC.2") {
35507
35432
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
35508
35433
  }
35509
35434
  /**
@@ -36027,18 +35952,19 @@ exportProcessNewRelationships_fn = function(rels = []) {
36027
35952
  });
36028
35953
  relationships.elements = [...relationships.elements, ...newRels];
36029
35954
  };
36030
- exportProcessMediaFiles_fn = async function(media, editor) {
36031
- const processedData = {};
36032
- for (const filePath in media) {
36033
- if (typeof media[filePath] !== "string") continue;
36034
- processedData[filePath] = await getArrayBufferFromUrl(media[filePath], editor.options.isHeadless);
35955
+ exportProcessMediaFiles_fn = async function(media = {}) {
35956
+ const processedData = {
35957
+ ...this.convertedXml.media || {}
35958
+ };
35959
+ for (const [filePath, value] of Object.entries(media)) {
35960
+ if (value == null) continue;
35961
+ processedData[filePath] = await getArrayBufferFromUrl(value);
36035
35962
  }
36036
- this.convertedXml.media = {
36037
- ...this.convertedXml.media,
35963
+ this.convertedXml.media = processedData;
35964
+ this.media = this.convertedXml.media;
35965
+ this.addedMedia = {
36038
35966
  ...processedData
36039
35967
  };
36040
- this.media = this.convertedXml.media;
36041
- this.addedMedia = processedData;
36042
35968
  };
36043
35969
  __publicField$1(_SuperConverter, "allowedElements", Object.freeze({
36044
35970
  "w:document": "doc",
@@ -50268,6 +50194,49 @@ const restoreSelection = () => ({ editor, state: state2, tr }) => {
50268
50194
  editor.view.dispatch(selectionTr);
50269
50195
  }
50270
50196
  };
50197
+ const clamp = (value, min2, max2) => Math.max(min2, Math.min(value, max2));
50198
+ const setTextSelection = ({ from: from2, to }) => ({ state: state2, dispatch, editor }) => {
50199
+ if (typeof from2 !== "number" && typeof to !== "number") {
50200
+ return false;
50201
+ }
50202
+ const doc2 = state2.doc;
50203
+ const docSize = doc2.content.size;
50204
+ const nextFrom = clamp(typeof from2 === "number" ? from2 : state2.selection.from, 0, docSize);
50205
+ const nextToBase = typeof to === "number" ? to : nextFrom;
50206
+ const nextTo = clamp(nextToBase, 0, docSize);
50207
+ const [head, anchor] = nextFrom <= nextTo ? [nextFrom, nextTo] : [nextTo, nextFrom];
50208
+ const selection = TextSelection$1.create(doc2, head, anchor);
50209
+ if (dispatch) {
50210
+ const transaction = state2.tr.setSelection(selection);
50211
+ dispatch(transaction);
50212
+ }
50213
+ if (editor?.view?.focus) {
50214
+ editor.view.focus();
50215
+ }
50216
+ return true;
50217
+ };
50218
+ const getSelectionMarks = () => ({ state: state2, tr }) => {
50219
+ tr.setMeta("preventDispatch", true);
50220
+ const marks = getMarksFromSelection(state2) ?? [];
50221
+ const uniqueByType = /* @__PURE__ */ new Map();
50222
+ for (const mark of marks) {
50223
+ const typeName = typeof mark?.type === "string" ? mark.type : mark?.type?.name;
50224
+ if (!typeName) continue;
50225
+ const existing = uniqueByType.get(typeName);
50226
+ if (!existing) {
50227
+ uniqueByType.set(typeName, mark);
50228
+ continue;
50229
+ }
50230
+ const existingAttrs = existing?.attrs ?? {};
50231
+ const nextAttrs = mark?.attrs ?? {};
50232
+ const existingHasValues = Object.values(existingAttrs).some((value) => value != null);
50233
+ const nextHasValues = Object.values(nextAttrs).some((value) => value != null);
50234
+ if (!existingHasValues && nextHasValues) {
50235
+ uniqueByType.set(typeName, mark);
50236
+ }
50237
+ }
50238
+ return Array.from(uniqueByType.values());
50239
+ };
50271
50240
  const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
50272
50241
  __proto__: null,
50273
50242
  atVisualParaEnd,
@@ -50283,6 +50252,7 @@ const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
50283
50252
  first,
50284
50253
  getEffectiveStyleId,
50285
50254
  getParaCtx,
50255
+ getSelectionMarks,
50286
50256
  getStyleIdFromMarks,
50287
50257
  handleBackspaceNextToList,
50288
50258
  handleDeleteNextToList,
@@ -50314,6 +50284,7 @@ const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
50314
50284
  setMark,
50315
50285
  setMeta,
50316
50286
  setNode,
50287
+ setTextSelection,
50317
50288
  sinkListItem,
50318
50289
  splitBlock: splitBlock$1,
50319
50290
  splitListItem,
@@ -50977,6 +50948,7 @@ const markInsertion = ({ tr, from: from2, to, user, date }) => {
50977
50948
  id,
50978
50949
  author: user.name,
50979
50950
  authorEmail: user.email,
50951
+ authorImage: user.image,
50980
50952
  date
50981
50953
  });
50982
50954
  tr.addMark(from2, to, insertionMark);
@@ -51013,6 +50985,7 @@ const markDeletion = ({ tr, from: from2, to, user, date, id: providedId }) => {
51013
50985
  id,
51014
50986
  author: user.name,
51015
50987
  authorEmail: user.email,
50988
+ authorImage: user.image,
51016
50989
  date
51017
50990
  });
51018
50991
  const deletionMap = new Mapping();
@@ -56823,6 +56796,9 @@ const normalizeCommentEventPayload = ({ conversation, editorOptions, fallbackCom
56823
56796
  if (!normalized.creatorEmail && user?.email) {
56824
56797
  normalized.creatorEmail = user.email;
56825
56798
  }
56799
+ if (!normalized.creatorImage && user?.image) {
56800
+ normalized.creatorImage = user.image;
56801
+ }
56826
56802
  if (!normalized.createdTime) {
56827
56803
  normalized.createdTime = Date.now();
56828
56804
  }
@@ -57281,7 +57257,7 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
57281
57257
  const trackedMark = marks.insertedMark || marks.deletionMark || marks.formatMark;
57282
57258
  const { type: type2, attrs } = trackedMark;
57283
57259
  const { name: trackedChangeType } = type2;
57284
- const { author, authorEmail, date, importedAuthor } = attrs;
57260
+ const { author, authorEmail, authorImage, date, importedAuthor } = attrs;
57285
57261
  const id = attrs.id;
57286
57262
  const node = nodes[0];
57287
57263
  const isDeletionInsertion = !!(marks.insertedMark && marks.deletionMark);
@@ -57312,6 +57288,7 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
57312
57288
  deletedText: marks.deletionMark ? deletionText : null,
57313
57289
  author,
57314
57290
  authorEmail,
57291
+ ...authorImage && { authorImage },
57315
57292
  date,
57316
57293
  ...importedAuthor && {
57317
57294
  importedAuthor: {
@@ -57456,6 +57433,7 @@ const addMarkStep = ({ state: state2, step, newTr, doc: doc2, user, date }) => {
57456
57433
  id: wid,
57457
57434
  author: user.name,
57458
57435
  authorEmail: user.email,
57436
+ authorImage: user.image,
57459
57437
  date,
57460
57438
  before,
57461
57439
  after
@@ -57521,6 +57499,7 @@ const removeMarkStep = ({ state: state2, step, newTr, doc: doc2, user, date }) =
57521
57499
  id: v4(),
57522
57500
  author: user.name,
57523
57501
  authorEmail: user.email,
57502
+ authorImage: user.image,
57524
57503
  date,
57525
57504
  before,
57526
57505
  after
@@ -60046,7 +60025,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
60046
60025
  * @returns {Object | void} Migration results
60047
60026
  */
60048
60027
  processCollaborationMigrations() {
60049
- console.debug("[checkVersionMigrations] Current editor version", "0.29.0-RC.1");
60028
+ console.debug("[checkVersionMigrations] Current editor version", "0.29.0-RC.2");
60050
60029
  if (!this.options.ydoc) return;
60051
60030
  const metaMap = this.options.ydoc.getMap("meta");
60052
60031
  let docVersion = metaMap.get("version");
@@ -76350,6 +76329,16 @@ const TrackInsert = Mark2.create({
76350
76329
  };
76351
76330
  }
76352
76331
  },
76332
+ authorImage: {
76333
+ default: "",
76334
+ parseDOM: (elem) => elem.getAttribute("data-authorimage"),
76335
+ renderDOM: (attrs) => {
76336
+ if (!attrs.authorImage) return {};
76337
+ return {
76338
+ "data-authorimage": attrs.authorImage
76339
+ };
76340
+ }
76341
+ },
76353
76342
  date: {
76354
76343
  default: "",
76355
76344
  parseDOM: (elem) => elem.getAttribute("data-date"),
@@ -76417,6 +76406,16 @@ const TrackDelete = Mark2.create({
76417
76406
  };
76418
76407
  }
76419
76408
  },
76409
+ authorImage: {
76410
+ default: "",
76411
+ parseDOM: (elem) => elem.getAttribute("data-authorimage"),
76412
+ renderDOM: (attrs) => {
76413
+ if (!attrs.authorImage) return {};
76414
+ return {
76415
+ "data-authorimage": attrs.authorImage
76416
+ };
76417
+ }
76418
+ },
76420
76419
  date: {
76421
76420
  default: "",
76422
76421
  parseDOM: (elem) => elem.getAttribute("data-date"),
@@ -76516,6 +76515,16 @@ const TrackFormat = Mark2.create({
76516
76515
  };
76517
76516
  }
76518
76517
  },
76518
+ authorImage: {
76519
+ default: "",
76520
+ parseDOM: (elem) => elem.getAttribute("data-authorimage"),
76521
+ renderDOM: (attrs) => {
76522
+ if (!attrs.authorImage) return {};
76523
+ return {
76524
+ "data-authorimage": attrs.authorImage
76525
+ };
76526
+ }
76527
+ },
76519
76528
  date: {
76520
76529
  default: "",
76521
76530
  parseDOM: (elem) => elem.getAttribute("data-date"),
@@ -95159,86 +95168,86 @@ const additionalHandlers = Object.freeze({
95159
95168
  "sd:pageReference": translator$5,
95160
95169
  "sd:tableOfContents": translator$4,
95161
95170
  "w:b": translator$1n,
95162
- "w:bidiVisual": translator$Y,
95171
+ "w:bidiVisual": translator$p,
95163
95172
  "w:bookmarkEnd": translator$6,
95164
95173
  "w:bookmarkStart": translator$7,
95165
- "w:bottom": translator$L,
95174
+ "w:bottom": translator$15,
95166
95175
  "w:br": translator$1r,
95167
- "w:cantSplit": translator$1a,
95168
- "w:cnfStyle": translator$19,
95176
+ "w:cantSplit": translator$G,
95177
+ "w:cnfStyle": translator$1a,
95169
95178
  "w:color": translator$1j,
95170
- "w:divId": translator$18,
95171
- "w:drawing": translator$9,
95172
- "w:end": translator$J,
95173
- "w:gridAfter": translator$17,
95174
- "w:gridBefore": translator$16,
95175
- "w:gridCol": translator$u,
95176
- "w:hidden": translator$15,
95179
+ "w:divId": translator$F,
95180
+ "w:drawing": translator$r,
95181
+ "w:end": translator$13,
95182
+ "w:gridAfter": translator$E,
95183
+ "w:gridBefore": translator$D,
95184
+ "w:gridCol": translator$a,
95185
+ "w:hidden": translator$C,
95177
95186
  "w:highlight": translator$1q,
95178
95187
  "w:hyperlink": translator$1c,
95179
95188
  "w:i": translator$1m,
95180
- "w:insideH": translator$H,
95181
- "w:insideV": translator$G,
95182
- "w:jc": translator$14,
95183
- "w:left": translator$F,
95189
+ "w:insideH": translator$11,
95190
+ "w:insideV": translator$10,
95191
+ "w:jc": translator$B,
95192
+ "w:left": translator$$,
95184
95193
  "w:p": translator$1o,
95185
95194
  "w:r": translator$1b,
95186
95195
  "w:rFonts": translator$1i,
95187
95196
  "w:rPr": translator$1d,
95188
95197
  "w:rStyle": translator$1h,
95189
- "w:right": translator$D,
95190
- "w:sdt": translator$8,
95191
- "w:shd": translator$X,
95192
- "w:start": translator$B,
95198
+ "w:right": translator$Z,
95199
+ "w:sdt": translator$q,
95200
+ "w:shd": translator$19,
95201
+ "w:start": translator$X,
95193
95202
  "w:strike": translator$1k,
95194
95203
  "w:sz": translator$1g,
95195
95204
  "w:szCs": translator$1f,
95196
95205
  "w:tab": translator$1p,
95197
- "w:tbl": translator$s,
95198
- "w:tblBorders": translator$x,
95199
- "w:tblCaption": translator$W,
95200
- "w:tblCellMar": translator$w,
95201
- "w:tblCellSpacing": translator$13,
95202
- "w:tblDescription": translator$V,
95203
- "w:tblGrid": translator$t,
95204
- "w:tblHeader": translator$12,
95205
- "w:tblInd": translator$U,
95206
- "w:tblLayout": translator$T,
95207
- "w:tblLook": translator$S,
95208
- "w:tblOverlap": translator$R,
95209
- "w:tblPr": translator$v,
95210
- "w:tblStyle": translator$Q,
95211
- "w:tblStyleColBandSize": translator$P,
95212
- "w:tblStyleRowBandSize": translator$O,
95213
- "w:tblW": translator$N,
95214
- "w:tblpPr": translator$M,
95215
- "w:tc": translator$c,
95216
- "w:top": translator$z,
95217
- "w:tr": translator$Z,
95218
- "w:trHeight": translator$11,
95219
- "w:trPr": translator$_,
95206
+ "w:tbl": translator$8,
95207
+ "w:tblBorders": translator$d,
95208
+ "w:tblCaption": translator$o,
95209
+ "w:tblCellMar": translator$c,
95210
+ "w:tblCellSpacing": translator$A,
95211
+ "w:tblDescription": translator$n,
95212
+ "w:tblGrid": translator$9,
95213
+ "w:tblHeader": translator$z,
95214
+ "w:tblInd": translator$m,
95215
+ "w:tblLayout": translator$l,
95216
+ "w:tblLook": translator$k,
95217
+ "w:tblOverlap": translator$j,
95218
+ "w:tblPr": translator$b,
95219
+ "w:tblStyle": translator$i,
95220
+ "w:tblStyleColBandSize": translator$h,
95221
+ "w:tblStyleRowBandSize": translator$g,
95222
+ "w:tblW": translator$f,
95223
+ "w:tblpPr": translator$e,
95224
+ "w:tc": translator$H,
95225
+ "w:top": translator$V,
95226
+ "w:tr": translator$u,
95227
+ "w:trHeight": translator$y,
95228
+ "w:trPr": translator$v,
95220
95229
  "w:u": translator$1l,
95221
- "w:wAfter": translator$10,
95222
- "w:wBefore": translator$$,
95223
- "wp:anchor": translator$b,
95224
- "wp:inline": translator$a,
95230
+ "w:wAfter": translator$x,
95231
+ "w:wBefore": translator$w,
95232
+ "wp:anchor": translator$t,
95233
+ "wp:inline": translator$s,
95225
95234
  "w:commentRangeStart": commentRangeStartTranslator,
95226
95235
  "w:commentRangeEnd": commentRangeEndTranslator,
95227
- "w:vMerge": translator$p,
95228
- "w:gridSpan": translator$q,
95229
- "w:vAlign": translator$h,
95230
- "w:noWrap": translator$l,
95231
- "w:tcFitText": translator$i,
95232
- "w:tcW": translator$r,
95233
- "w:hideMark": translator$g,
95234
- "w:textDirection": translator$j,
95235
- "w:tl2br": translator$o,
95236
- "w:tr2bl": translator$n,
95237
- "w:header": translator$f,
95238
- "w:headers": translator$e,
95239
- "w:tcBorders": translator$m,
95240
- "w:tcMar": translator$k,
95241
- "w:tcPr": translator$d
95236
+ "w:vMerge": translator$16,
95237
+ "w:gridSpan": translator$17,
95238
+ "w:vAlign": translator$M,
95239
+ "w:noWrap": translator$Q,
95240
+ "w:tcFitText": translator$N,
95241
+ "w:tcW": translator$18,
95242
+ "w:hideMark": translator$L,
95243
+ "w:textDirection": translator$O,
95244
+ "w:tl2br": translator$T,
95245
+ "w:tr2bl": translator$S,
95246
+ "w:header": translator$K,
95247
+ "w:headers": translator$J,
95248
+ "w:tcBorders": translator$R,
95249
+ "w:tcMar": translator$P,
95250
+ "w:tcPr": translator$I
95242
95251
  });
95243
95252
  const baseHandlers = {
95244
95253
  ...runPropertyTranslators,