@harbour-enterprises/superdoc 1.5.0-next.5 → 1.5.0-next.6

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.
@@ -15124,6 +15124,11 @@
15124
15124
  const validXmlAttributes$9 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
15125
15125
  (xmlName) => createAttributeHandler(xmlName)
15126
15126
  );
15127
+ const getColspan$1 = (cell2) => {
15128
+ const rawColspan = cell2?.attrs?.colspan;
15129
+ const numericColspan = typeof rawColspan === "string" ? parseInt(rawColspan, 10) : rawColspan;
15130
+ return Number.isFinite(numericColspan) && numericColspan > 0 ? numericColspan : 1;
15131
+ };
15127
15132
  const encode$w = (params2, encodedAttrs) => {
15128
15133
  const { row: row2 } = params2.extraParams;
15129
15134
  let tableRowProperties = {};
@@ -15256,7 +15261,27 @@
15256
15261
  }
15257
15262
  return cell2;
15258
15263
  });
15259
- const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
15264
+ let trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
15265
+ const preferTableGrid = params2.extraParams?.preferTableGrid === true;
15266
+ const totalColumns = params2.extraParams?.totalColumns;
15267
+ if (preferTableGrid && typeof totalColumns === "number" && Number.isFinite(totalColumns) && totalColumns > 0) {
15268
+ const rawGridBefore = node2.attrs?.tableRowProperties?.gridBefore;
15269
+ const numericGridBefore = typeof rawGridBefore === "string" ? parseInt(rawGridBefore, 10) : rawGridBefore;
15270
+ const safeGridBefore = Number.isFinite(numericGridBefore) && numericGridBefore > 0 ? numericGridBefore : 0;
15271
+ const effectiveGridBefore = leadingPlaceholders > 0 ? leadingPlaceholders : safeGridBefore;
15272
+ const availableColumns = Math.max(totalColumns - effectiveGridBefore, 0);
15273
+ let usedColumns = 0;
15274
+ const constrainedCells = [];
15275
+ for (const cell2 of trimmedContent) {
15276
+ const colspan = getColspan$1(cell2);
15277
+ if (usedColumns + colspan > availableColumns) {
15278
+ break;
15279
+ }
15280
+ constrainedCells.push(cell2);
15281
+ usedColumns += colspan;
15282
+ }
15283
+ trimmedContent = constrainedCells;
15284
+ }
15260
15285
  const translateParams = {
15261
15286
  ...params2,
15262
15287
  node: { ...node2, content: trimmedContent }
@@ -31536,6 +31561,53 @@ Please report this to https://github.com/markedjs/marked.`, e) {
31536
31561
  attributes: validXmlAttributes$5
31537
31562
  };
31538
31563
  const translator$s = NodeTranslator.from(config$d);
31564
+ const getColspan = (cell2) => {
31565
+ const rawColspan = cell2?.attrs?.colspan;
31566
+ const numericColspan = typeof rawColspan === "string" ? parseInt(rawColspan, 10) : rawColspan;
31567
+ return Number.isFinite(numericColspan) && numericColspan > 0 ? numericColspan : 1;
31568
+ };
31569
+ const resolveGridBefore = (row2) => {
31570
+ const rawGridBefore = row2?.attrs?.tableRowProperties?.gridBefore ?? row2?.attrs?.gridBefore;
31571
+ const numericGridBefore = typeof rawGridBefore === "string" ? parseInt(rawGridBefore, 10) : rawGridBefore;
31572
+ if (!Number.isFinite(numericGridBefore) || numericGridBefore <= 0) return 0;
31573
+ const cells = Array.isArray(row2.content) ? row2.content : [];
31574
+ let leadingGridBefore = 0;
31575
+ while (leadingGridBefore < cells.length && cells[leadingGridBefore]?.attrs?.__placeholder === "gridBefore") {
31576
+ leadingGridBefore += 1;
31577
+ }
31578
+ return leadingGridBefore > 0 ? 0 : numericGridBefore;
31579
+ };
31580
+ const advanceColumnsForCell = (columnIndex, cell2) => columnIndex + getColspan(cell2);
31581
+ const getCellStartColumn = (row2, targetCell) => {
31582
+ const cells = Array.isArray(row2.content) ? row2.content : [];
31583
+ let columnIndex = resolveGridBefore(row2);
31584
+ for (const cell2 of cells) {
31585
+ if (cell2 === targetCell) return columnIndex;
31586
+ columnIndex = advanceColumnsForCell(columnIndex, cell2);
31587
+ }
31588
+ return columnIndex;
31589
+ };
31590
+ const findCellCoveringColumn = (row2, targetColumn) => {
31591
+ const cells = Array.isArray(row2.content) ? row2.content : [];
31592
+ let columnIndex = resolveGridBefore(row2);
31593
+ for (const cell2 of cells) {
31594
+ const colspan = getColspan(cell2);
31595
+ if (targetColumn >= columnIndex && targetColumn < columnIndex + colspan) {
31596
+ return cell2;
31597
+ }
31598
+ columnIndex = advanceColumnsForCell(columnIndex, cell2);
31599
+ }
31600
+ return null;
31601
+ };
31602
+ const findInsertionIndexForColumn = (row2, targetColumn) => {
31603
+ const cells = Array.isArray(row2.content) ? row2.content : [];
31604
+ let columnIndex = resolveGridBefore(row2);
31605
+ for (let index2 = 0; index2 < cells.length; index2++) {
31606
+ if (columnIndex >= targetColumn) return index2;
31607
+ columnIndex = advanceColumnsForCell(columnIndex, cells[index2]);
31608
+ }
31609
+ return cells.length;
31610
+ };
31539
31611
  function preProcessVerticalMergeCells(table2, { editorSchema }) {
31540
31612
  if (!table2 || !Array.isArray(table2.content)) {
31541
31613
  return table2;
@@ -31551,15 +31623,17 @@ Please report this to https://github.com/markedjs/marked.`, e) {
31551
31623
  const cell2 = row2.content[cellIndex];
31552
31624
  if (!cell2) continue;
31553
31625
  const attrs = cell2.attrs || {};
31554
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
31555
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
31626
+ const rawRowspan = typeof attrs.rowspan === "string" ? parseInt(attrs.rowspan, 10) : attrs.rowspan;
31627
+ if (!Number.isFinite(rawRowspan) || rawRowspan <= 1) continue;
31628
+ const maxRowspan = Math.min(rawRowspan, rows.length - rowIndex);
31629
+ const startColumn = getCellStartColumn(row2, cell2);
31556
31630
  for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
31557
31631
  const rowToChange = rows[rowIndex + offset2];
31558
31632
  if (!rowToChange) continue;
31559
31633
  if (!Array.isArray(rowToChange.content)) {
31560
31634
  rowToChange.content = [];
31561
31635
  }
31562
- const existingCell = rowToChange.content[cellIndex];
31636
+ const existingCell = findCellCoveringColumn(rowToChange, startColumn);
31563
31637
  if (existingCell?.attrs?.continueMerge) continue;
31564
31638
  const mergedCell = {
31565
31639
  type: cell2.type,
@@ -31570,7 +31644,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
31570
31644
  continueMerge: true
31571
31645
  }
31572
31646
  };
31573
- rowToChange.content.splice(cellIndex, 0, mergedCell);
31647
+ const insertionIndex = findInsertionIndexForColumn(rowToChange, startColumn);
31648
+ rowToChange.content.splice(insertionIndex, 0, mergedCell);
31574
31649
  }
31575
31650
  }
31576
31651
  }
@@ -31722,15 +31797,24 @@ Please report this to https://github.com/markedjs/marked.`, e) {
31722
31797
  const decode$t = (params2) => {
31723
31798
  const { grid: rawGrid } = params2.node.attrs || {};
31724
31799
  const grid = Array.isArray(rawGrid) ? rawGrid : [];
31725
- const { firstRow = {} } = params2.extraParams || {};
31800
+ const { firstRow = {}, preferTableGrid = false, totalColumns: requestedColumns } = params2.extraParams || {};
31726
31801
  const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
31727
- const colWidthsFromCellNodes = cellNodes.flatMap((cell2) => {
31802
+ let colWidthsFromCellNodes = cellNodes.flatMap((cell2) => {
31728
31803
  const spanCount = Math.max(1, cell2?.attrs?.colspan ?? 1);
31729
31804
  const colwidth = cell2.attrs?.colwidth;
31730
31805
  return Array.from({ length: spanCount }).map((_2, span) => Array.isArray(colwidth) ? colwidth[span] : void 0);
31731
31806
  });
31732
31807
  const columnCountFromCells = colWidthsFromCellNodes.length;
31733
- const totalColumns = Math.max(columnCountFromCells, grid.length);
31808
+ const gridColumnCount = grid.length;
31809
+ let totalColumns = Math.max(columnCountFromCells, gridColumnCount);
31810
+ if (typeof requestedColumns === "number" && Number.isFinite(requestedColumns) && requestedColumns > 0) {
31811
+ totalColumns = requestedColumns;
31812
+ } else if (preferTableGrid && gridColumnCount > 0) {
31813
+ totalColumns = gridColumnCount;
31814
+ }
31815
+ if (colWidthsFromCellNodes.length > totalColumns) {
31816
+ colWidthsFromCellNodes = colWidthsFromCellNodes.slice(0, totalColumns);
31817
+ }
31734
31818
  const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
31735
31819
  const elements = [];
31736
31820
  const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
@@ -31990,22 +32074,31 @@ Please report this to https://github.com/markedjs/marked.`, e) {
31990
32074
  const decode$s = (params2, decodedAttrs) => {
31991
32075
  params2.node = preProcessVerticalMergeCells(params2.node, params2);
31992
32076
  const { node: node2 } = params2;
31993
- const elements = translateChildNodes(params2);
32077
+ const rawGrid = node2.attrs?.grid;
32078
+ const grid = Array.isArray(rawGrid) ? rawGrid : [];
32079
+ const preferTableGrid = node2.attrs?.userEdited !== true && grid.length > 0;
32080
+ const totalColumns = preferTableGrid ? grid.length : void 0;
32081
+ const extraParams = {
32082
+ ...params2.extraParams || {},
32083
+ preferTableGrid,
32084
+ totalColumns
32085
+ };
32086
+ const elements = translateChildNodes({ ...params2, extraParams });
31994
32087
  const firstRow = node2.content?.find((n) => n.type === "tableRow");
31995
- const properties = node2.attrs.grid;
31996
32088
  const element2 = translator$c.decode({
31997
32089
  ...params2,
31998
- node: { ...node2, attrs: { ...node2.attrs, grid: properties } },
32090
+ node: { ...node2, attrs: { ...node2.attrs, grid } },
31999
32091
  extraParams: {
32092
+ ...extraParams,
32000
32093
  firstRow
32001
32094
  }
32002
32095
  });
32003
32096
  if (element2) elements.unshift(element2);
32004
32097
  if (node2.attrs?.tableProperties) {
32005
- const properties2 = { ...node2.attrs.tableProperties };
32098
+ const properties = { ...node2.attrs.tableProperties };
32006
32099
  const element22 = translator$e.decode({
32007
32100
  ...params2,
32008
- node: { ...node2, attrs: { ...node2.attrs, tableProperties: properties2 } }
32101
+ node: { ...node2, attrs: { ...node2.attrs, tableProperties: properties } }
32009
32102
  });
32010
32103
  if (element22) elements.unshift(element22);
32011
32104
  }
@@ -36992,7 +37085,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36992
37085
  static getStoredSuperdocVersion(docx) {
36993
37086
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
36994
37087
  }
36995
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.5.0-next.5") {
37088
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.5.0-next.6") {
36996
37089
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
36997
37090
  }
36998
37091
  /**
@@ -62875,7 +62968,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62875
62968
  return false;
62876
62969
  }
62877
62970
  };
62878
- const summaryVersion = "1.5.0-next.5";
62971
+ const summaryVersion = "1.5.0-next.6";
62879
62972
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
62880
62973
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
62881
62974
  function mapAttributes(attrs) {
@@ -65533,7 +65626,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65533
65626
  * Process collaboration migrations
65534
65627
  */
65535
65628
  processCollaborationMigrations() {
65536
- console.debug("[checkVersionMigrations] Current editor version", "1.5.0-next.5");
65629
+ console.debug("[checkVersionMigrations] Current editor version", "1.5.0-next.6");
65537
65630
  if (!this.options.ydoc) return;
65538
65631
  const metaMap = this.options.ydoc.getMap("meta");
65539
65632
  let docVersion = metaMap.get("version");
@@ -146937,7 +147030,7 @@ ${reason}`);
146937
147030
  this.config.colors = shuffleArray(this.config.colors);
146938
147031
  this.userColorMap = /* @__PURE__ */ new Map();
146939
147032
  this.colorIndex = 0;
146940
- this.version = "1.5.0-next.5";
147033
+ this.version = "1.5.0-next.6";
146941
147034
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
146942
147035
  this.superdocId = config2.superdocId || v4();
146943
147036
  this.colors = this.config.colors;