@claritylabs/cl-sdk 3.1.10 → 3.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11291,6 +11291,42 @@ function columnLabelStartIndex(rows) {
11291
11291
  );
11292
11292
  return headerIndex >= 0 ? headerIndex : 0;
11293
11293
  }
11294
+ function startsNewVisualTableItem(cells) {
11295
+ const firstText = tableCellText(cells[0]);
11296
+ return /^(?:item\s+\d+\b|[A-Z][.)]\s+|coverage\s+part\b|endorsement\s+(?:no\.?|number|#|\d+)\b)/i.test(firstText);
11297
+ }
11298
+ function rowMatchesColumnLabels(cells, columnLabels) {
11299
+ if (columnLabels.size === 0 || cells.length < columnLabels.size) return false;
11300
+ return cells.every((cell, index) => {
11301
+ const label = columnLabels.get(tableCellColumnIndex(cell, index));
11302
+ return !label || tableCellText(cell).toLowerCase() === label.toLowerCase();
11303
+ });
11304
+ }
11305
+ function implicitContinuationRows(rows, columnLabels, firstLabelRowIndex) {
11306
+ const continuations = [];
11307
+ let targetRowId;
11308
+ const targetColumnLabel = columnLabels.get(1);
11309
+ for (const [rowIndex, { row, cells }] of rows.entries()) {
11310
+ if (rowIndex < firstLabelRowIndex) continue;
11311
+ if (rowIndex === firstLabelRowIndex && rowMatchesColumnLabels(cells, columnLabels)) continue;
11312
+ if (startsNewVisualTableItem(cells)) {
11313
+ targetRowId = row.id;
11314
+ continue;
11315
+ }
11316
+ if (!targetRowId || cells.length === 0) continue;
11317
+ const isSpuriousHeader = isSourceTreeHeaderRow(row) && !rowMatchesColumnLabels(cells, columnLabels);
11318
+ const isShortContinuation = !isSourceTreeHeaderRow(row) && cells.length < Math.max(2, columnLabels.size);
11319
+ if (!isSpuriousHeader && !isShortContinuation) continue;
11320
+ continuations.push({
11321
+ sourceRowNodeId: row.id,
11322
+ targetRowNodeId: targetRowId,
11323
+ targetColumnIndex: 1,
11324
+ targetColumnLabel,
11325
+ reason: "Continuation row inferred from repaired table header."
11326
+ });
11327
+ }
11328
+ return continuations;
11329
+ }
11294
11330
  function metadataWithColumnLabel(metadata, label) {
11295
11331
  const next = {
11296
11332
  ...metadata ?? {},
@@ -11331,8 +11367,8 @@ function applyVisualTableRepair(sourceTree, repair) {
11331
11367
  const normalized = normalizedRepairLabel(label.label);
11332
11368
  if (normalized) columnLabels.set(label.columnIndex, normalized);
11333
11369
  }
11370
+ const firstLabelRowIndex = columnLabelStartIndex(rows);
11334
11371
  if (columnLabels.size > 0) {
11335
- const firstLabelRowIndex = columnLabelStartIndex(rows);
11336
11372
  const normalizedLabels = new Set([...columnLabels.values()].map((label) => label.toLowerCase()));
11337
11373
  for (const [rowIndex, { row, cells }] of rows.entries()) {
11338
11374
  if (removeIds.has(row.id)) continue;
@@ -11367,9 +11403,18 @@ function applyVisualTableRepair(sourceTree, repair) {
11367
11403
  });
11368
11404
  rowsToRebuildText.add(row.id);
11369
11405
  }
11406
+ if (cells.length > 0) rowsToRebuildText.add(row.id);
11370
11407
  }
11371
11408
  }
11372
- for (const continuation of tableRepair.continuationRows) {
11409
+ const continuationRows = [
11410
+ ...tableRepair.continuationRows,
11411
+ ...implicitContinuationRows(rows, columnLabels, firstLabelRowIndex)
11412
+ ];
11413
+ const seenContinuationRows = /* @__PURE__ */ new Set();
11414
+ for (const continuation of continuationRows) {
11415
+ const continuationKey = `${continuation.sourceRowNodeId}:${continuation.targetRowNodeId}`;
11416
+ if (seenContinuationRows.has(continuationKey)) continue;
11417
+ seenContinuationRows.add(continuationKey);
11373
11418
  if (!rowIds.has(continuation.sourceRowNodeId) || !rowIds.has(continuation.targetRowNodeId)) continue;
11374
11419
  if (continuation.sourceRowNodeId === continuation.targetRowNodeId) continue;
11375
11420
  const sourceIndex = rowOrder.get(continuation.sourceRowNodeId);