@usememos/editor 26.10.26 → 26.10.27

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
@@ -186,19 +186,19 @@ function imageBlockOffset(block3) {
186
186
  function isImageBlock(block3) {
187
187
  return imageBlockOffset(block3) !== null;
188
188
  }
189
- function containerContent(block3, cell) {
189
+ function containerContent(block3, cell2) {
190
190
  if (block3.type === "table") {
191
- if (!cell) return null;
192
- return block3.rows[cell.row]?.[cell.col] ?? null;
191
+ if (!cell2) return null;
192
+ return block3.rows[cell2.row]?.[cell2.col] ?? null;
193
193
  }
194
194
  if (isTextless(block3)) return null;
195
195
  return block3.content;
196
196
  }
197
- function withContainerContent(block3, cell, content) {
197
+ function withContainerContent(block3, cell2, content) {
198
198
  if (block3.type === "table") {
199
- if (!cell) return block3;
199
+ if (!cell2) return block3;
200
200
  const rows = block3.rows.map(
201
- (row, r) => r === cell.row ? row.map((c, i) => i === cell.col ? normalizeInline(content) : c) : row
201
+ (row, r) => r === cell2.row ? row.map((c, i) => i === cell2.col ? normalizeInline(content) : c) : row
202
202
  );
203
203
  return { ...block3, rows };
204
204
  }
@@ -387,8 +387,8 @@ function isCollapsed(sel) {
387
387
  function orderedRange(doc, sel) {
388
388
  return comparePositions(doc, sel.anchor, sel.focus) <= 0 ? { from: sel.anchor, to: sel.focus } : { from: sel.focus, to: sel.anchor };
389
389
  }
390
- function caret(blockId, offset, cell) {
391
- const p = cell ? { blockId, offset, cell } : { blockId, offset };
390
+ function caret(blockId, offset, cell2) {
391
+ const p = cell2 ? { blockId, offset, cell: cell2 } : { blockId, offset };
392
392
  return { anchor: p, focus: p };
393
393
  }
394
394
  function startOf(block3) {
@@ -541,8 +541,8 @@ function excludedRanges(content) {
541
541
  function isExcluded(span) {
542
542
  return !!span.link || !!span.image || !!span.token || span.marks.includes("code") || span.marks.includes("html");
543
543
  }
544
- function decorationContext(block3, content, cell) {
545
- return { block: block3, cell, content, text: inlineText(content), excluded: excludedRanges(content) };
544
+ function decorationContext(block3, content, cell2) {
545
+ return { block: block3, cell: cell2, content, text: inlineText(content), excluded: excludedRanges(content) };
546
546
  }
547
547
  function overlapsAny(from, to, ranges) {
548
548
  let lo = 0;
@@ -631,8 +631,8 @@ function replaceBlock(state, block3, selection) {
631
631
  function cloneBlock(block3) {
632
632
  return { ...block3, id: createId() };
633
633
  }
634
- function contentOf(block3, cell) {
635
- return containerContent(block3, cell) ?? [];
634
+ function contentOf(block3, cell2) {
635
+ return containerContent(block3, cell2) ?? [];
636
636
  }
637
637
  function emptyLike(block3) {
638
638
  switch (block3.type) {
@@ -679,12 +679,12 @@ function deleteInTable(state, block3, from, to) {
679
679
  const ia = a.row * cols + a.col;
680
680
  const ib = b.row * cols + b.col;
681
681
  const rows = block3.rows.map(
682
- (row, r) => row.map((cell, c) => {
682
+ (row, r) => row.map((cell2, c) => {
683
683
  const i = r * cols + c;
684
- if (i < ia || i > ib) return cell;
684
+ if (i < ia || i > ib) return cell2;
685
685
  const start = i === ia ? from.offset : 0;
686
- const end = i === ib ? to.offset : inlineLength(cell);
687
- return deleteInline(cell, start, end);
686
+ const end = i === ib ? to.offset : inlineLength(cell2);
687
+ return deleteInline(cell2, start, end);
688
688
  })
689
689
  );
690
690
  return replaceBlock(state, { ...block3, rows }, caret(block3.id, from.offset, a));
@@ -726,8 +726,8 @@ function deleteBackward(state) {
726
726
  return deleteRange(state, { ...pos, offset: from }, pos);
727
727
  }
728
728
  if (block3.type === "table") {
729
- const cell = pos.cell;
730
- const prevCell = cell.col > 0 ? { row: cell.row, col: cell.col - 1 } : cell.row > 0 ? { row: cell.row - 1, col: block3.align.length - 1 } : null;
729
+ const cell2 = pos.cell;
730
+ const prevCell = cell2.col > 0 ? { row: cell2.row, col: cell2.col - 1 } : cell2.row > 0 ? { row: cell2.row - 1, col: block3.align.length - 1 } : null;
731
731
  if (!prevCell) return state;
732
732
  return { ...state, selection: caret(block3.id, inlineLength(contentOf(block3, prevCell)), prevCell) };
733
733
  }
@@ -976,10 +976,10 @@ function balanceSections(state) {
976
976
  return { ...next, selection: { anchor: move(anchor), focus: move(focus) } };
977
977
  }
978
978
  function tableEnter(state, block3, pos) {
979
- const cell = pos.cell;
979
+ const cell2 = pos.cell;
980
980
  let table2 = block3;
981
- if (cell.row === block3.rows.length - 1) table2 = addRow(block3, cell.row + 1);
982
- const below = { row: cell.row + 1, col: cell.col };
981
+ if (cell2.row === block3.rows.length - 1) table2 = addRow(block3, cell2.row + 1);
982
+ const below = { row: cell2.row + 1, col: cell2.col };
983
983
  return replaceBlock(state, table2, caret(table2.id, 0, below));
984
984
  }
985
985
  function mapTextInRange(state, from, to, fn) {
@@ -992,15 +992,15 @@ function mapTextInRange(state, from, to, fn) {
992
992
  const fromIdx = block3.id === from.blockId && from.cell ? from.cell.row * cols + from.cell.col : 0;
993
993
  const toIdx = block3.id === to.blockId && to.cell ? to.cell.row * cols + to.cell.col : Infinity;
994
994
  const rows = block3.rows.map(
995
- (row, r) => row.map((cell, c) => {
995
+ (row, r) => row.map((cell2, c) => {
996
996
  const i = r * cols + c;
997
- if (i < fromIdx || i > toIdx) return cell;
997
+ if (i < fromIdx || i > toIdx) return cell2;
998
998
  const a2 = i === fromIdx && block3.id === from.blockId ? from.offset : 0;
999
- const b2 = i === toIdx && block3.id === to.blockId ? to.offset : inlineLength(cell);
1000
- return a2 < b2 ? keepIfSame(cell, fn(cell, a2, b2)) : cell;
999
+ const b2 = i === toIdx && block3.id === to.blockId ? to.offset : inlineLength(cell2);
1000
+ return a2 < b2 ? keepIfSame(cell2, fn(cell2, a2, b2)) : cell2;
1001
1001
  })
1002
1002
  );
1003
- return rows.every((row, r) => row.every((cell, c) => cell === block3.rows[r][c])) ? block3 : { ...block3, rows };
1003
+ return rows.every((row, r) => row.every((cell2, c) => cell2 === block3.rows[r][c])) ? block3 : { ...block3, rows };
1004
1004
  }
1005
1005
  const a = block3.id === from.blockId ? from.offset : 0;
1006
1006
  const b = block3.id === to.blockId ? to.offset : inlineLength(block3.content);
@@ -1413,27 +1413,27 @@ function tableAction(state, action) {
1413
1413
  if (block3.type !== "table" || !pos.cell) return state;
1414
1414
  const { row, col } = pos.cell;
1415
1415
  let table2 = block3;
1416
- let cell = pos.cell;
1416
+ let cell2 = pos.cell;
1417
1417
  switch (action.kind) {
1418
1418
  case "addRowAbove":
1419
1419
  table2 = addRow(block3, row === 0 ? 1 : row);
1420
- cell = { row: row === 0 ? 1 : row, col };
1420
+ cell2 = { row: row === 0 ? 1 : row, col };
1421
1421
  break;
1422
1422
  case "addRowBelow":
1423
1423
  table2 = addRow(block3, row + 1);
1424
- cell = { row: row + 1, col };
1424
+ cell2 = { row: row + 1, col };
1425
1425
  break;
1426
1426
  case "addColumnLeft":
1427
1427
  table2 = addColumn(block3, col);
1428
1428
  break;
1429
1429
  case "addColumnRight":
1430
1430
  table2 = addColumn(block3, col + 1);
1431
- cell = { row, col: col + 1 };
1431
+ cell2 = { row, col: col + 1 };
1432
1432
  break;
1433
1433
  case "deleteRow":
1434
1434
  if (block3.rows.length <= 1) return deleteBlock(state, block3.id);
1435
1435
  table2 = { ...block3, rows: block3.rows.filter((_, r) => r !== row) };
1436
- cell = { row: Math.min(row, table2.rows.length - 1), col };
1436
+ cell2 = { row: Math.min(row, table2.rows.length - 1), col };
1437
1437
  break;
1438
1438
  case "deleteColumn": {
1439
1439
  if (block3.align.length <= 1) return deleteBlock(state, block3.id);
@@ -1442,15 +1442,15 @@ function tableAction(state, action) {
1442
1442
  align: block3.align.filter((_, c) => c !== col),
1443
1443
  rows: block3.rows.map((r) => r.filter((_, c) => c !== col))
1444
1444
  };
1445
- cell = { row, col: Math.min(col, table2.align.length - 1) };
1445
+ cell2 = { row, col: Math.min(col, table2.align.length - 1) };
1446
1446
  break;
1447
1447
  }
1448
1448
  case "align":
1449
1449
  table2 = { ...block3, align: block3.align.map((a, c) => c === col ? action.align : a) };
1450
1450
  break;
1451
1451
  }
1452
- const offset = Math.min(pos.offset, inlineLength(contentOf(table2, cell)));
1453
- return replaceBlock(state, table2, caret(table2.id, cell === pos.cell ? offset : 0, cell));
1452
+ const offset = Math.min(pos.offset, inlineLength(contentOf(table2, cell2)));
1453
+ return replaceBlock(state, table2, caret(table2.id, cell2 === pos.cell ? offset : 0, cell2));
1454
1454
  }
1455
1455
  function moveCell(state, delta2) {
1456
1456
  const pos = state.selection.focus;
@@ -1461,11 +1461,11 @@ function moveCell(state, delta2) {
1461
1461
  if (index < 0) return state;
1462
1462
  let table2 = block3;
1463
1463
  if (index >= block3.rows.length * cols) table2 = addRow(block3, block3.rows.length);
1464
- const cell = { row: Math.floor(index / cols), col: index % cols };
1465
- const content = contentOf(table2, cell);
1464
+ const cell2 = { row: Math.floor(index / cols), col: index % cols };
1465
+ const content = contentOf(table2, cell2);
1466
1466
  const selection = {
1467
- anchor: { blockId: block3.id, offset: 0, cell },
1468
- focus: { blockId: block3.id, offset: inlineLength(content), cell }
1467
+ anchor: { blockId: block3.id, offset: 0, cell: cell2 },
1468
+ focus: { blockId: block3.id, offset: inlineLength(content), cell: cell2 }
1469
1469
  };
1470
1470
  return table2 === block3 ? { ...state, selection } : withBlocks(state, splice(state, blockIndex(state.doc, block3.id), 1, table2), selection);
1471
1471
  }
@@ -1596,11 +1596,11 @@ function dropBrokenTokens(state, before, syntax) {
1596
1596
  if (old.has(block3) || block3.type === "divider") return;
1597
1597
  const containers2 = block3.type === "table" ? block3.rows.flatMap((row, r) => row.map((_, c) => ({ row: r, col: c }))) : [void 0];
1598
1598
  let next = block3;
1599
- for (const cell of containers2) {
1600
- const content = containerContent(next, cell);
1599
+ for (const cell2 of containers2) {
1600
+ const content = containerContent(next, cell2);
1601
1601
  if (!content?.some((s) => s.token)) continue;
1602
1602
  const fixed = untokenizeBroken(content, syntax);
1603
- if (fixed !== content) next = withContainerContent(next, cell, fixed);
1603
+ if (fixed !== content) next = withContainerContent(next, cell2, fixed);
1604
1604
  }
1605
1605
  if (next !== block3) (blocks ??= [...state.doc.blocks])[i] = next;
1606
1606
  });
@@ -1842,14 +1842,14 @@ function blockHtml(block3) {
1842
1842
  case "detailsEnd":
1843
1843
  return "</details>";
1844
1844
  case "table": {
1845
- const cell = (tag, content, c) => {
1845
+ const cell2 = (tag, content, c) => {
1846
1846
  const align = block3.align[c];
1847
1847
  return `<${tag}${align ? ` style="text-align: ${align}"` : ""}>${inlineHtml(content)}</${tag}>`;
1848
1848
  };
1849
1849
  const [head, ...body] = block3.rows;
1850
1850
  let html = "<table>";
1851
- if (head) html += `<thead><tr>${head.map((c, i) => cell("th", c, i)).join("")}</tr></thead>`;
1852
- if (body.length > 0) html += `<tbody>${body.map((row) => `<tr>${row.map((c, i) => cell("td", c, i)).join("")}</tr>`).join("")}</tbody>`;
1851
+ if (head) html += `<thead><tr>${head.map((c, i) => cell2("th", c, i)).join("")}</tr></thead>`;
1852
+ if (body.length > 0) html += `<tbody>${body.map((row) => `<tr>${row.map((c, i) => cell2("td", c, i)).join("")}</tr>`).join("")}</tbody>`;
1853
1853
  return html + "</table>";
1854
1854
  }
1855
1855
  case "listItem":
@@ -2340,8 +2340,8 @@ var Converter = class _Converter {
2340
2340
  if (width === 0) return;
2341
2341
  const align = Array.from({ length: width }, (_, c) => alignOf(cells[0]?.[c]));
2342
2342
  const content = cells.map((row) => Array.from({ length: width }, (_, c) => {
2343
- const cell = row[c];
2344
- return cell ? this.inlineOf(cell, formatOf(cell, format)) : [];
2343
+ const cell2 = row[c];
2344
+ return cell2 ? this.inlineOf(cell2, formatOf(cell2, format)) : [];
2345
2345
  }));
2346
2346
  this.out.push(table(align, content));
2347
2347
  }
@@ -2388,9 +2388,9 @@ function preText(pre) {
2388
2388
  pre.childNodes.forEach(walk);
2389
2389
  return text.replace(/\r\n?/g, "\n").replace(/\n$/, "");
2390
2390
  }
2391
- function alignOf(cell) {
2392
- if (!cell) return null;
2393
- const candidates = [cell, ...Array.from(cell.children).slice(0, 1)];
2391
+ function alignOf(cell2) {
2392
+ if (!cell2) return null;
2393
+ const candidates = [cell2, ...Array.from(cell2.children).slice(0, 1)];
2394
2394
  for (const el of candidates) {
2395
2395
  const value = (styleOf(el).get("text-align") ?? el.getAttribute("align") ?? "").toLowerCase();
2396
2396
  if (value === "left" || value === "start") return "left";
@@ -2854,7 +2854,8 @@ var SegmentBuilder = class {
2854
2854
  const k = d - line.pad;
2855
2855
  const textLength = lineEnd - lineStart - line.offset;
2856
2856
  if (k < textLength) {
2857
- const n = Math.min(textLength - k, end - o);
2857
+ const next = lines[i + 1];
2858
+ const n = Math.min(textLength - k, end - o, next ? next.at - o : Infinity);
2858
2859
  this.push({ from: m, to: m + n, srcFrom: lineStart + line.offset + k, srcTo: lineStart + line.offset + k + n, linear: true });
2859
2860
  o += n;
2860
2861
  m += n;
@@ -3092,7 +3093,7 @@ function lowerBlock(node, out, o, ctx) {
3092
3093
  out.push(mappedText(rawBlock(node.name, node.value), node.value, node.source, ctx));
3093
3094
  break;
3094
3095
  case "table":
3095
- out.push(table(node.align, node.rows.map((row) => row.map((cell) => lowerInlines(cell, o)))));
3096
+ out.push(table(node.align, node.rows.map((row) => row.map((cell2) => lowerInlines(cell2, o)))));
3096
3097
  break;
3097
3098
  }
3098
3099
  }
@@ -4423,7 +4424,7 @@ var BlockParser = class {
4423
4424
  }
4424
4425
  } else if (type === "table") {
4425
4426
  if (!this.blank && this.offset < this.line.length) {
4426
- const cells = splitRow(this.line.slice(this.offset));
4427
+ const cells = splitRow(this.line.slice(this.offset), this.lineNumber, this.offset);
4427
4428
  const filled = Math.max(0, container.align.length - cells.length);
4428
4429
  if (this.filledCells + filled <= this.maxFilledCells) {
4429
4430
  this.filledCells += filled;
@@ -4672,7 +4673,8 @@ var BlockParser = class {
4672
4673
  lines.pop();
4673
4674
  const headerLine = lines.pop();
4674
4675
  if (headerLine === void 0) return 0 /* None */;
4675
- const header = splitRow(headerLine);
4676
+ const written = container.lines[container.lines.length - 1];
4677
+ const header = splitRow(headerLine, written.line, written.offset, written.pad);
4676
4678
  if (header.length !== align.length) return 0 /* None */;
4677
4679
  this.closeUnmatchedBlocks();
4678
4680
  const parent = container.parent;
@@ -4815,7 +4817,8 @@ var BlockParser = class {
4815
4817
  {
4816
4818
  type: "table",
4817
4819
  align: node.align,
4818
- rows: node.rows.map((row) => row.map((cell) => parseInlines(cell, this.refs, this.options.inline, this.options.autolinks))),
4820
+ rows: node.rows.map((row) => row.map((cell2) => parseInlines(cell2.text, this.refs, this.options.inline, this.options.autolinks))),
4821
+ sources: node.rows.map((row) => row.map((cell2) => cell2.source)),
4819
4822
  lines: linesOf(node)
4820
4823
  }
4821
4824
  ];
@@ -4874,42 +4877,70 @@ function isTight(list) {
4874
4877
  }
4875
4878
  return true;
4876
4879
  }
4877
- function splitRow(line) {
4878
- const s = line.replace(/^[ \t]+|[ \t]+$/g, "");
4880
+ var EMPTY_CELL = { text: "", source: { lines: [], start: 0 } };
4881
+ function splitRow(text, line = 0, offset = 0, pad = 0) {
4882
+ let start = 0;
4883
+ let end = text.length;
4884
+ while (start < end && isSpaceOrTab(text[start])) start++;
4885
+ while (end > start && isSpaceOrTab(text[end - 1])) end--;
4879
4886
  const cells = [];
4880
- let cell = "";
4887
+ let value = "";
4888
+ let pieces = [];
4889
+ const piece = (i) => pieces.push({ at: value.length, line, offset: offset + i - pad, pad: 0 });
4890
+ const close = () => {
4891
+ cells.push(cell(value, pieces));
4892
+ value = "";
4893
+ pieces = [];
4894
+ };
4881
4895
  let endsWithPipe = false;
4882
- for (let i = 0; i < s.length; i++) {
4883
- const c = s[i];
4896
+ piece(start);
4897
+ for (let i = start; i < end; i++) {
4898
+ const c = text[i];
4884
4899
  endsWithPipe = false;
4885
- if (c === "\\" && i + 1 < s.length) {
4886
- cell += s[i + 1] === "|" ? "|" : c + s[i + 1];
4900
+ if (c === "\\" && i + 1 < end) {
4901
+ if (text[i + 1] === "|") {
4902
+ piece(i + 1);
4903
+ value += "|";
4904
+ } else value += c + text[i + 1];
4887
4905
  i++;
4888
4906
  } else if (c === "|") {
4889
- cells.push(cell);
4890
- cell = "";
4907
+ close();
4908
+ piece(i + 1);
4891
4909
  endsWithPipe = true;
4892
4910
  } else {
4893
- cell += c;
4911
+ value += c;
4894
4912
  }
4895
4913
  }
4896
- if (!endsWithPipe || cells.length === 0) cells.push(cell);
4897
- if (s.startsWith("|")) cells.shift();
4898
- return cells.map((c) => c.replace(/^[ \t]+|[ \t]+$/g, ""));
4914
+ if (!endsWithPipe || cells.length === 0) close();
4915
+ if (text[start] === "|") cells.shift();
4916
+ return cells;
4917
+ }
4918
+ function cell(value, pieces) {
4919
+ let lead = 0;
4920
+ let end = value.length;
4921
+ while (lead < end && isSpaceOrTab(value[lead])) lead++;
4922
+ while (end > lead && isSpaceOrTab(value[end - 1])) end--;
4923
+ const lines = [];
4924
+ pieces.forEach((p, k) => {
4925
+ if ((pieces[k + 1]?.at ?? value.length) <= lead) return;
4926
+ const cut = Math.max(0, lead - p.at);
4927
+ lines.push({ ...p, at: p.at - lead + cut, offset: p.offset + cut });
4928
+ });
4929
+ return { text: value.slice(lead, end), source: { lines, start: 0 } };
4899
4930
  }
4900
4931
  function fitRow(cells, length) {
4901
4932
  const row = cells.slice(0, length);
4902
- while (row.length < length) row.push("");
4933
+ while (row.length < length) row.push(EMPTY_CELL);
4903
4934
  return row;
4904
4935
  }
4905
4936
  function parseDelimiterRow(line) {
4906
4937
  const cells = splitRow(line);
4907
4938
  if (cells.length === 0) return null;
4908
4939
  const align = [];
4909
- for (const cell of cells) {
4910
- if (!reTableDelimiterCell.test(cell)) return null;
4911
- const left = cell.startsWith(":");
4912
- const right = cell.endsWith(":");
4940
+ for (const { text: cell2 } of cells) {
4941
+ if (!reTableDelimiterCell.test(cell2)) return null;
4942
+ const left = cell2.startsWith(":");
4943
+ const right = cell2.endsWith(":");
4913
4944
  align.push(left && right ? "center" : right ? "right" : left ? "left" : null);
4914
4945
  }
4915
4946
  return align;
@@ -5133,7 +5164,7 @@ function serializeCode(language, text) {
5133
5164
  ${text ? text + "\n" : ""}${fence}`;
5134
5165
  }
5135
5166
  function serializeTable(align, rows, ctx) {
5136
- const row = (cells) => "| " + cells.map((cell) => inlineToMarkdown(representableCell(cell), ctx).replace(/\|/g, "\\|")).join(" | ") + " |";
5167
+ const row = (cells) => "| " + cells.map((cell2) => inlineToMarkdown(representableCell(cell2), ctx).replace(/\|/g, "\\|")).join(" | ") + " |";
5137
5168
  const delimiter = "| " + align.map((a) => a === "left" ? ":--" : a === "center" ? ":-:" : a === "right" ? "--:" : "---").join(" | ") + " |";
5138
5169
  const [header, ...body] = rows;
5139
5170
  return [row(header ?? align.map(() => [])), delimiter, ...body.map(row)].join("\n");
@@ -7071,8 +7102,8 @@ var SuggestionController = class {
7071
7102
  get state() {
7072
7103
  const session = this.session;
7073
7104
  if (!session) return null;
7074
- const { entry, blockId, cell, from, to, query } = session;
7075
- const at = (offset) => cell ? { blockId, offset, cell } : { blockId, offset };
7105
+ const { entry, blockId, cell: cell2, from, to, query } = session;
7106
+ const at = (offset) => cell2 ? { blockId, offset, cell: cell2 } : { blockId, offset };
7076
7107
  const listboxId = entry.listboxId;
7077
7108
  return {
7078
7109
  name: entry.config.name,
@@ -7403,8 +7434,8 @@ ${this.message}` : "";
7403
7434
  if (this.editor.isComposing) this.host.endComposition();
7404
7435
  const session = this.session;
7405
7436
  if (!session) return;
7406
- const { entry, blockId, cell, from, to, query, text, mode } = session;
7407
- const at = (offset) => cell ? { blockId, offset, cell } : { blockId, offset };
7437
+ const { entry, blockId, cell: cell2, from, to, query, text, mode } = session;
7438
+ const at = (offset) => cell2 ? { blockId, offset, cell: cell2 } : { blockId, offset };
7408
7439
  const range = { from: at(from), to: at(to) };
7409
7440
  this.close();
7410
7441
  if (entry.config.command) {
@@ -8222,8 +8253,8 @@ var defaultResolveUrl = (url) => {
8222
8253
  return ["http", "https", "mailto", "tel"].includes(scheme[1].toLowerCase()) ? read : null;
8223
8254
  };
8224
8255
  var REVEAL_BLOCK = "block";
8225
- function tokenKey(cell, from) {
8226
- return cell ? `${cell.row}:${cell.col}@${from}` : `@${from}`;
8256
+ function tokenKey(cell2, from) {
8257
+ return cell2 ? `${cell2.row}:${cell2.col}@${from}` : `@${from}`;
8227
8258
  }
8228
8259
  function sameReveal(a, b) {
8229
8260
  if (a === b) return true;
@@ -8402,7 +8433,7 @@ function renderBlock(block3, ctx, reveal) {
8402
8433
  const tbody = el("tbody");
8403
8434
  block3.rows.forEach((row, r) => {
8404
8435
  const tr = el("tr");
8405
- row.forEach((cell, c) => {
8436
+ row.forEach((cell2, c) => {
8406
8437
  const td = el(r === 0 ? "th" : "td");
8407
8438
  td.contentEditable = "true";
8408
8439
  td.dir = "auto";
@@ -8410,7 +8441,7 @@ function renderBlock(block3, ctx, reveal) {
8410
8441
  td.dataset.col = String(c);
8411
8442
  const align = block3.align[c];
8412
8443
  if (align) td.style.textAlign = align;
8413
- fillContent(td, cell, ctx, block3, reveal, { row: r, col: c });
8444
+ fillContent(td, cell2, ctx, block3, reveal, { row: r, col: c });
8414
8445
  tr.appendChild(td);
8415
8446
  });
8416
8447
  tbody.appendChild(tr);
@@ -8523,7 +8554,7 @@ function sourceDomText(contentEl) {
8523
8554
  parts.push(current);
8524
8555
  return parts.join("\n");
8525
8556
  }
8526
- function fillContent(target, inline3, ctx, block3, reveal, cell, decorated = true) {
8557
+ function fillContent(target, inline3, ctx, block3, reveal, cell2, decorated = true) {
8527
8558
  const doc = ctx.doc;
8528
8559
  target.setAttribute(CONTENT_ATTR, "");
8529
8560
  if (inlineLength(inline3) === 0) {
@@ -8531,12 +8562,12 @@ function fillContent(target, inline3, ctx, block3, reveal, cell, decorated = tru
8531
8562
  target.appendChild(fill(doc));
8532
8563
  return;
8533
8564
  }
8534
- const decorations = block3.type === "code" ? ctx.decorateCode?.(block3) ?? [] : decorated && ctx.decorate ? ctx.decorate(block3, inline3, cell) : [];
8565
+ const decorations = block3.type === "code" ? ctx.decorateCode?.(block3) ?? [] : decorated && ctx.decorate ? ctx.decorate(block3, inline3, cell2) : [];
8535
8566
  const only = inline3.length === 1 ? inline3[0] : null;
8536
8567
  if (only && decorations.length === 0 && only.marks.length === 0 && !only.link && !only.token && !only.image) {
8537
8568
  target.appendChild(doc.createTextNode(only.text));
8538
8569
  } else {
8539
- renderInline(inline3, target, ctx, decorations, reveal, cell);
8570
+ renderInline(inline3, target, ctx, decorations, reveal, cell2);
8540
8571
  }
8541
8572
  const last = inline3[inline3.length - 1];
8542
8573
  if (last && last.text.endsWith("\n")) target.appendChild(fill(doc));
@@ -8766,12 +8797,12 @@ function htmlRuns(inline3) {
8766
8797
  }
8767
8798
  return runs;
8768
8799
  }
8769
- function renderInline(inline3, parent, ctx, decorations, reveal, cell) {
8800
+ function renderInline(inline3, parent, ctx, decorations, reveal, cell2) {
8770
8801
  const doc = ctx.doc;
8771
8802
  const views = ctx.views;
8772
- const viewed = views ? (span, from) => !!span.token && views.has(span.token) && !reveal?.has(tokenKey(cell, from)) : void 0;
8803
+ const viewed = views ? (span, from) => !!span.token && views.has(span.token) && !reveal?.has(tokenKey(cell2, from)) : void 0;
8773
8804
  if (views?.has("html")) inline3 = splitHtmlSpans(inline3);
8774
- const runs = views?.has("html") && inline3.some((s) => s.marks.includes("html")) ? htmlRuns(inline3).filter((run) => !reveal?.has(tokenKey(cell, run.from))) : [];
8805
+ const runs = views?.has("html") && inline3.some((s) => s.marks.includes("html")) ? htmlRuns(inline3).filter((run) => !reveal?.has(tokenKey(cell2, run.from))) : [];
8775
8806
  const inRun = (from) => runs.some((run) => from >= run.from && from < run.to);
8776
8807
  const isHtml = (span) => span.marks.includes("html");
8777
8808
  const atomic = viewed || runs.length > 0 ? (span, from) => !!viewed?.(span, from) || isHtml(span) && inRun(from) : void 0;
@@ -9468,8 +9499,8 @@ function blockElementOf(root, node) {
9468
9499
  while (n && n.parentNode !== root) n = n.parentNode;
9469
9500
  return n instanceof HTMLElement && n.hasAttribute(BLOCK_ATTR) ? n : null;
9470
9501
  }
9471
- function contentElement(blockEl, cell) {
9472
- if (cell) return blockEl.querySelector(`[data-row="${cell.row}"][data-col="${cell.col}"]`);
9502
+ function contentElement(blockEl, cell2) {
9503
+ if (cell2) return blockEl.querySelector(`[data-row="${cell2.row}"][data-col="${cell2.col}"]`);
9473
9504
  if (blockEl.hasAttribute(CONTENT_ATTR)) return blockEl;
9474
9505
  return blockEl.querySelector(`[${CONTENT_ATTR}]`);
9475
9506
  }
@@ -9556,8 +9587,8 @@ function domToPosition(root, node, offset) {
9556
9587
  if (blockEl.classList.contains("mbe-table")) {
9557
9588
  const cellEl = (target instanceof Element ? target : target.parentElement)?.closest("[data-row]");
9558
9589
  if (!cellEl || !blockEl.contains(cellEl)) return { blockId, offset: 0, cell: { row: 0, col: 0 } };
9559
- const cell = { row: Number(cellEl.dataset.row), col: Number(cellEl.dataset.col) };
9560
- return { blockId, offset: offsetIn(cellEl, target, off), cell };
9590
+ const cell2 = { row: Number(cellEl.dataset.row), col: Number(cellEl.dataset.col) };
9591
+ return { blockId, offset: offsetIn(cellEl, target, off), cell: cell2 };
9561
9592
  }
9562
9593
  const content = contentElement(blockEl);
9563
9594
  if (!content) return { blockId, offset: 0 };
@@ -10090,10 +10121,21 @@ function markdownMarkup(text, options) {
10090
10121
  prefixMarkers(start, start + line.offset);
10091
10122
  }
10092
10123
  };
10124
+ const rowMarkers = (from, to) => {
10125
+ for (let i = from; i < to; i++) {
10126
+ if (text[i] === "\\" && i + 1 < to) {
10127
+ if (text[i + 1] === "|") push("escape", i, i + 2);
10128
+ i++;
10129
+ } else if (text[i] === "|") push("marker", i, i + 1);
10130
+ }
10131
+ };
10093
10132
  const inline3 = (source, nodes, kind) => {
10094
10133
  if (!source) return;
10095
10134
  contentLines(source);
10096
10135
  if (kind && nodes.length > 0) pieces(source, 0, Math.max(...nodes.map((n) => n.pos?.to ?? 0)), kind);
10136
+ inlineMarkup(source, nodes);
10137
+ };
10138
+ const inlineMarkup = (source, nodes) => {
10097
10139
  const walk = (list) => {
10098
10140
  for (const node of list) {
10099
10141
  const { pos } = node;
@@ -10267,8 +10309,9 @@ function markdownMarkup(text, options) {
10267
10309
  const line = lineRange(n);
10268
10310
  const at = bareLineMarkers(line);
10269
10311
  if (n === node.lines.start + 1) push("marker", at, line.to);
10270
- else for (let i = at; i < line.to; i++) if (text[i] === "|" && text[i - 1] !== "\\") push("marker", i, i + 1);
10312
+ else rowMarkers(at, line.to);
10271
10313
  }
10314
+ node.sources?.forEach((row, r) => row.forEach((source, c) => inlineMarkup(source, node.rows[r]?.[c] ?? [])));
10272
10315
  }
10273
10316
  break;
10274
10317
  }
@@ -10623,8 +10666,8 @@ var Editor = class {
10623
10666
  }
10624
10667
  const decorators = this.extensions.flatMap((e) => e.decorations ? [e.decorations] : []);
10625
10668
  if (decorators.length > 0) {
10626
- this.renderer.decorate = (block3, content, cell) => {
10627
- const ctx = decorationContext(block3, content, cell);
10669
+ this.renderer.decorate = (block3, content, cell2) => {
10670
+ const ctx = decorationContext(block3, content, cell2);
10628
10671
  return decorators.flatMap((fn) => fn(ctx));
10629
10672
  };
10630
10673
  }
@@ -11440,8 +11483,8 @@ var Editor = class {
11440
11483
  this.root.classList.toggle("mbe-readonly", this.readOnly);
11441
11484
  this.root.classList.toggle("mbe-tasks", ticking);
11442
11485
  this.root.setAttribute("aria-readonly", String(this.readOnly));
11443
- this.root.querySelectorAll("[data-row]").forEach((cell) => {
11444
- cell.contentEditable = this.readOnly ? "false" : "true";
11486
+ this.root.querySelectorAll("[data-row]").forEach((cell2) => {
11487
+ cell2.contentEditable = this.readOnly ? "false" : "true";
11445
11488
  });
11446
11489
  this.root.querySelectorAll("input").forEach((input) => {
11447
11490
  const box = input.classList.contains("mbe-checkbox");
@@ -12136,9 +12179,9 @@ var Editor = class {
12136
12179
  const el = this.renderer.elementFor(block3.id);
12137
12180
  if (!el || !el.isConnected) continue;
12138
12181
  const containers2 = block3.type === "table" ? block3.rows.flatMap((row, r) => row.map((_, c) => ({ cell: { row: r, col: c } }))) : isTextless(block3) ? [] : [{}];
12139
- for (const { cell } of containers2) {
12140
- const contentEl = contentElement(el, cell);
12141
- const content = containerContent(getBlock(state.doc, block3.id), cell);
12182
+ for (const { cell: cell2 } of containers2) {
12183
+ const contentEl = contentElement(el, cell2);
12184
+ const content = containerContent(getBlock(state.doc, block3.id), cell2);
12142
12185
  if (!contentEl || !content) continue;
12143
12186
  const oldText = inlineText(content);
12144
12187
  const newText = domText(contentEl);
@@ -12152,7 +12195,7 @@ var Editor = class {
12152
12195
  endNew--;
12153
12196
  }
12154
12197
  const inserted = newText.slice(start, endNew);
12155
- const at = cell ? { blockId: block3.id, offset: start, cell } : { blockId: block3.id, offset: start };
12198
+ const at = cell2 ? { blockId: block3.id, offset: start, cell: cell2 } : { blockId: block3.id, offset: start };
12156
12199
  state = deleteRange(state, at, { ...at, offset: endOld });
12157
12200
  if (inserted) state = insertText({ ...state, storedMarks: marks }, inserted);
12158
12201
  changed = true;
@@ -12265,10 +12308,10 @@ var Editor = class {
12265
12308
  return;
12266
12309
  }
12267
12310
  const vertical = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0;
12268
- const cell = vertical ? this.tableCellPast(vertical) : null;
12269
- if (cell) {
12311
+ const cell2 = vertical ? this.tableCellPast(vertical) : null;
12312
+ if (cell2) {
12270
12313
  e.preventDefault();
12271
- this.setSelection({ anchor: cell, focus: cell });
12314
+ this.setSelection({ anchor: cell2, focus: cell2 });
12272
12315
  return;
12273
12316
  }
12274
12317
  const next = vertical ? exitBlock(this.state, vertical) : this.state;
@@ -12326,10 +12369,10 @@ var Editor = class {
12326
12369
  if (!blockEl || !this.root.contains(blockEl)) return false;
12327
12370
  const block3 = getBlock(this.state.doc, blockEl.getAttribute(BLOCK_ATTR));
12328
12371
  const cellEl = target.closest("[data-row]");
12329
- const cell = block3.type === "table" && cellEl ? { row: Number(cellEl.dataset.row), col: Number(cellEl.dataset.col) } : void 0;
12330
- const content = containerContent(block3, cell);
12372
+ const cell2 = block3.type === "table" && cellEl ? { row: Number(cellEl.dataset.row), col: Number(cellEl.dataset.col) } : void 0;
12373
+ const content = containerContent(block3, cell2);
12331
12374
  if (!content || blockEl.classList.contains("mbe-view-block")) return false;
12332
- const at = (offset) => cell ? { blockId: block3.id, offset, cell } : { blockId: block3.id, offset };
12375
+ const at = (offset) => cell2 ? { blockId: block3.id, offset, cell: cell2 } : { blockId: block3.id, offset };
12333
12376
  this.setSelection({ anchor: at(0), focus: at(inlineLength(content)) });
12334
12377
  return true;
12335
12378
  }
@@ -12833,15 +12876,15 @@ var Editor = class {
12833
12876
  blockMenuSections(blockId) {
12834
12877
  const block3 = getBlock(this.state.doc, blockId);
12835
12878
  const sections2 = [];
12836
- const cell = this.state.selection.focus.cell;
12837
- if (block3.type === "table" && this.state.selection.focus.blockId === blockId && cell) {
12879
+ const cell2 = this.state.selection.focus.cell;
12880
+ if (block3.type === "table" && this.state.selection.focus.blockId === blockId && cell2) {
12838
12881
  const items = TABLE_ACTIONS.map(({ id, action }) => ({
12839
12882
  id,
12840
12883
  label: this.labels[id],
12841
12884
  icon: this.icon(id),
12842
12885
  run: () => this.run((s) => tableAction(s, action))
12843
12886
  }));
12844
- const current = block3.align[cell.col] ?? "left";
12887
+ const current = block3.align[cell2.col] ?? "left";
12845
12888
  items.splice(4, 0, this.alignMenuItem("align", current, (align) => ({
12846
12889
  icon: this.icon(align.id),
12847
12890
  run: () => this.run((s) => tableAction(s, { kind: "align", align: align.align }))
@@ -13321,13 +13364,13 @@ function isSelection(value) {
13321
13364
  function selectionFromJSON(doc, value) {
13322
13365
  const read = (p) => {
13323
13366
  if (!p || typeof p !== "object") return null;
13324
- const { block: block3, offset, cell } = p;
13367
+ const { block: block3, offset, cell: cell2 } = p;
13325
13368
  if (!Number.isInteger(block3) || !Number.isInteger(offset)) return null;
13326
13369
  const index = Math.max(0, Math.min(block3, doc.blocks.length - 1));
13327
13370
  const target = doc.blocks[index];
13328
13371
  if (block3 >= doc.blocks.length) return endOf(target);
13329
13372
  if (target.type === "table") {
13330
- const c = cell && typeof cell === "object" ? cell : {};
13373
+ const c = cell2 && typeof cell2 === "object" ? cell2 : {};
13331
13374
  const row = Number.isInteger(c.row) ? Math.max(0, Math.min(c.row, target.rows.length - 1)) : 0;
13332
13375
  const col = Number.isInteger(c.col) ? Math.max(0, Math.min(c.col, target.rows[0].length - 1)) : 0;
13333
13376
  return { blockId: target.id, offset: Math.max(0, offset), cell: { row, col } };