@underverse-ui/underverse 1.0.145 → 1.0.146

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
@@ -25758,6 +25758,26 @@ function extractClipboardHtmlFragment(html) {
25758
25758
  }
25759
25759
  return html;
25760
25760
  }
25761
+ var EMPTY_TABLE_CELL_HTML = "<p></p>";
25762
+ var TABLE_MEDIA_SELECTOR = "img,video,audio,iframe,svg,canvas,embed,object";
25763
+ var TABLE_BLOCK_SELECTOR = "p,ul,ol,blockquote,pre,h1,h2,h3,h4,h5,h6,hr,table";
25764
+ function hasMeaningfulTableCellText(value) {
25765
+ return Boolean(value?.replace(/\u00a0/g, " ").trim());
25766
+ }
25767
+ function normalizeClipboardTableCell(cell) {
25768
+ const hasText = hasMeaningfulTableCellText(cell.textContent);
25769
+ const hasBlockContent = Boolean(cell.querySelector(TABLE_BLOCK_SELECTOR));
25770
+ const hasMediaContent = Boolean(cell.querySelector(TABLE_MEDIA_SELECTOR));
25771
+ if (!hasText && !hasBlockContent && !hasMediaContent) {
25772
+ cell.innerHTML = EMPTY_TABLE_CELL_HTML;
25773
+ }
25774
+ }
25775
+ function normalizeClipboardTable(table) {
25776
+ for (const cell of Array.from(table.querySelectorAll("td,th"))) {
25777
+ if (!(cell instanceof HTMLTableCellElement)) continue;
25778
+ normalizeClipboardTableCell(cell);
25779
+ }
25780
+ }
25761
25781
  function getClipboardTableHtml(dataTransfer) {
25762
25782
  const html = getClipboardData(dataTransfer, "text/html");
25763
25783
  if (!/<table(?:\s|>)/i.test(html)) return "";
@@ -25765,18 +25785,17 @@ function getClipboardTableHtml(dataTransfer) {
25765
25785
  if (typeof DOMParser !== "undefined") {
25766
25786
  const doc = new DOMParser().parseFromString(fragment, "text/html");
25767
25787
  const table = doc.querySelector("table");
25768
- if (table) return table.outerHTML;
25788
+ if (table instanceof HTMLTableElement) {
25789
+ normalizeClipboardTable(table);
25790
+ return table.outerHTML;
25791
+ }
25769
25792
  }
25770
25793
  return fragment;
25771
25794
  }
25772
25795
  function escapeHtml(value) {
25773
25796
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
25774
25797
  }
25775
- function renderCellHtml(value) {
25776
- const lines = value.split("\n");
25777
- return lines.map((line) => `<p>${escapeHtml(line)}</p>`).join("");
25778
- }
25779
- function parseTsvRows(text) {
25798
+ function parseClipboardTsvRows(text) {
25780
25799
  const rows = [];
25781
25800
  let row = [];
25782
25801
  let field = "";
@@ -25792,9 +25811,9 @@ function parseTsvRows(text) {
25792
25811
  };
25793
25812
  for (let index = 0; index < text.length; index += 1) {
25794
25813
  const char = text[index];
25795
- const next = text[index + 1];
25814
+ const nextChar = text[index + 1];
25796
25815
  if (inQuotes) {
25797
- if (char === '"' && next === '"') {
25816
+ if (char === '"' && nextChar === '"') {
25798
25817
  field += '"';
25799
25818
  index += 1;
25800
25819
  continue;
@@ -25826,12 +25845,21 @@ function parseTsvRows(text) {
25826
25845
  }
25827
25846
  return rows;
25828
25847
  }
25848
+ function renderClipboardTableCellHtml(value) {
25849
+ const lines = value.split("\n");
25850
+ const paragraphs = lines.length > 0 ? lines : [""];
25851
+ return paragraphs.map((line) => `<p>${escapeHtml(line)}</p>`).join("");
25852
+ }
25829
25853
  function getClipboardTsvTableHtml(dataTransfer) {
25830
- const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\n+$/, "");
25854
+ const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
25831
25855
  if (!text.includes(" ")) return "";
25832
- const rows = parseTsvRows(text);
25856
+ const rows = parseClipboardTsvRows(text);
25833
25857
  if (rows.length === 0 || rows.every((row) => row.length < 2)) return "";
25834
- const body = rows.map((row) => `<tr>${row.map((cell) => `<td>${renderCellHtml(cell)}</td>`).join("")}</tr>`).join("");
25858
+ const columnCount = rows.reduce((max, row) => Math.max(max, row.length), 0);
25859
+ const body = rows.map((row) => {
25860
+ const normalizedRow = Array.from({ length: columnCount }, (_, index) => row[index] ?? "");
25861
+ return `<tr>${normalizedRow.map((cell) => `<td>${renderClipboardTableCellHtml(cell)}</td>`).join("")}</tr>`;
25862
+ }).join("");
25835
25863
  return `<table><tbody>${body}</tbody></table>`;
25836
25864
  }
25837
25865
  function fileToDataUrl(file) {