@underverse-ui/underverse 1.0.145 → 1.0.147

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "package": "@underverse-ui/underverse",
3
- "version": "1.0.145",
3
+ "version": "1.0.147",
4
4
  "sourceEntry": "src/index.ts",
5
5
  "totalExports": 232,
6
6
  "exports": [
package/dist/index.cjs CHANGED
@@ -25913,25 +25913,79 @@ function extractClipboardHtmlFragment(html) {
25913
25913
  }
25914
25914
  return html;
25915
25915
  }
25916
- function getClipboardTableHtml(dataTransfer) {
25917
- const html = getClipboardData(dataTransfer, "text/html");
25918
- if (!/<table(?:\s|>)/i.test(html)) return "";
25919
- const fragment = extractClipboardHtmlFragment(html);
25920
- if (typeof DOMParser !== "undefined") {
25921
- const doc = new DOMParser().parseFromString(fragment, "text/html");
25922
- const table = doc.querySelector("table");
25923
- if (table) return table.outerHTML;
25916
+ function normalizeClipboardCellText(value) {
25917
+ return value.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\u00a0/g, " ").replace(/[ \t]+\n/g, "\n").replace(/\n[ \t]+/g, "\n").replace(/\n+$/g, "").replace(/^\n+/g, "").trim();
25918
+ }
25919
+ function getClipboardCellText(node) {
25920
+ if (node.nodeType === Node.TEXT_NODE) {
25921
+ return node.textContent ?? "";
25922
+ }
25923
+ if (!(node instanceof HTMLElement)) {
25924
+ return "";
25925
+ }
25926
+ if (node.tagName === "BR") {
25927
+ return "\n";
25924
25928
  }
25925
- return fragment;
25929
+ const childText = Array.from(node.childNodes).map(getClipboardCellText).join("");
25930
+ if ((node.tagName === "P" || node.tagName === "DIV" || node.tagName === "LI") && childText && !childText.endsWith("\n")) {
25931
+ return `${childText}
25932
+ `;
25933
+ }
25934
+ return childText;
25935
+ }
25936
+ function getHtmlTableRows(table) {
25937
+ const rows = Array.from(table.querySelectorAll("tr")).map(
25938
+ (row) => Array.from(row.children).filter((cell) => cell instanceof HTMLTableCellElement).map((cell) => ({
25939
+ text: normalizeClipboardCellText(getClipboardCellText(cell)),
25940
+ isHeader: cell.tagName === "TH"
25941
+ }))
25942
+ );
25943
+ return rows.filter((row) => row.length > 0);
25944
+ }
25945
+ function createParagraphContent(text) {
25946
+ return text ? {
25947
+ type: "paragraph",
25948
+ content: [{ type: "text", text }]
25949
+ } : { type: "paragraph" };
25926
25950
  }
25927
- function escapeHtml(value) {
25928
- return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
25951
+ function createTableCellContent(cell) {
25952
+ const lines = cell.text.split("\n");
25953
+ const paragraphs = (lines.length > 0 ? lines : [""]).map(createParagraphContent);
25954
+ return {
25955
+ type: cell.isHeader ? "tableHeader" : "tableCell",
25956
+ content: paragraphs.length > 0 ? paragraphs : [{ type: "paragraph" }]
25957
+ };
25958
+ }
25959
+ function createTableContent(rows, minColumnCount = 1) {
25960
+ const tableRows = rows.filter((row) => row.length > 0);
25961
+ if (tableRows.length === 0) return null;
25962
+ const columnCount = tableRows.reduce((max, row) => Math.max(max, row.length), 0);
25963
+ if (columnCount < minColumnCount) return null;
25964
+ return {
25965
+ type: "table",
25966
+ content: tableRows.map((row) => {
25967
+ const normalizedRow = Array.from(
25968
+ { length: columnCount },
25969
+ (_, index) => row[index] ?? { text: "", isHeader: false }
25970
+ );
25971
+ return {
25972
+ type: "tableRow",
25973
+ content: normalizedRow.map(createTableCellContent)
25974
+ };
25975
+ })
25976
+ };
25929
25977
  }
25930
- function renderCellHtml(value) {
25931
- const lines = value.split("\n");
25932
- return lines.map((line) => `<p>${escapeHtml(line)}</p>`).join("");
25978
+ function getClipboardTableContent(dataTransfer) {
25979
+ const html = getClipboardData(dataTransfer, "text/html");
25980
+ if (!/<table(?:\s|>)/i.test(html)) return null;
25981
+ if (typeof DOMParser === "undefined") return null;
25982
+ const fragment = extractClipboardHtmlFragment(html);
25983
+ const doc = new DOMParser().parseFromString(fragment, "text/html");
25984
+ const table = doc.querySelector("table");
25985
+ if (!(table instanceof HTMLTableElement)) return null;
25986
+ return createTableContent(getHtmlTableRows(table));
25933
25987
  }
25934
- function parseTsvRows(text) {
25988
+ function parseClipboardTsvRows(text) {
25935
25989
  const rows = [];
25936
25990
  let row = [];
25937
25991
  let field = "";
@@ -25947,9 +26001,9 @@ function parseTsvRows(text) {
25947
26001
  };
25948
26002
  for (let index = 0; index < text.length; index += 1) {
25949
26003
  const char = text[index];
25950
- const next = text[index + 1];
26004
+ const nextChar = text[index + 1];
25951
26005
  if (inQuotes) {
25952
- if (char === '"' && next === '"') {
26006
+ if (char === '"' && nextChar === '"') {
25953
26007
  field += '"';
25954
26008
  index += 1;
25955
26009
  continue;
@@ -25981,13 +26035,14 @@ function parseTsvRows(text) {
25981
26035
  }
25982
26036
  return rows;
25983
26037
  }
25984
- function getClipboardTsvTableHtml(dataTransfer) {
25985
- const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\n+$/, "");
25986
- if (!text.includes(" ")) return "";
25987
- const rows = parseTsvRows(text);
25988
- if (rows.length === 0 || rows.every((row) => row.length < 2)) return "";
25989
- const body = rows.map((row) => `<tr>${row.map((cell) => `<td>${renderCellHtml(cell)}</td>`).join("")}</tr>`).join("");
25990
- return `<table><tbody>${body}</tbody></table>`;
26038
+ function getClipboardTsvTableContent(dataTransfer) {
26039
+ const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
26040
+ if (!text.includes(" ")) return null;
26041
+ const rows = parseClipboardTsvRows(text);
26042
+ return createTableContent(
26043
+ rows.map((row) => row.map((cell) => ({ text: normalizeClipboardCellText(cell), isHeader: false }))),
26044
+ 2
26045
+ );
25991
26046
  }
25992
26047
  function fileToDataUrl(file) {
25993
26048
  return new Promise((resolve, reject) => {
@@ -26043,16 +26098,16 @@ var ClipboardImages = import_core5.Extension.create({
26043
26098
  props: {
26044
26099
  handlePaste: (_view, event) => {
26045
26100
  if (!event || !event.clipboardData) return false;
26046
- const tableHtml = getClipboardTableHtml(event.clipboardData);
26047
- if (tableHtml) {
26101
+ const tableContent = getClipboardTableContent(event.clipboardData);
26102
+ if (tableContent) {
26048
26103
  event.preventDefault();
26049
- editor.chain().focus().insertContent(tableHtml).run();
26104
+ editor.chain().focus().insertContent(tableContent).run();
26050
26105
  return true;
26051
26106
  }
26052
- const tsvTableHtml = getClipboardTsvTableHtml(event.clipboardData);
26053
- if (tsvTableHtml) {
26107
+ const tsvTableContent = getClipboardTsvTableContent(event.clipboardData);
26108
+ if (tsvTableContent) {
26054
26109
  event.preventDefault();
26055
- editor.chain().focus().insertContent(tsvTableHtml).run();
26110
+ editor.chain().focus().insertContent(tsvTableContent).run();
26056
26111
  return true;
26057
26112
  }
26058
26113
  const files = getImageFiles(event.clipboardData);