@underverse-ui/underverse 1.0.146 → 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.
- package/api-reference.json +1 -1
- package/dist/index.cjs +77 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +77 -50
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25758,42 +25758,77 @@ function extractClipboardHtmlFragment(html) {
|
|
|
25758
25758
|
}
|
|
25759
25759
|
return html;
|
|
25760
25760
|
}
|
|
25761
|
-
|
|
25762
|
-
|
|
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());
|
|
25761
|
+
function normalizeClipboardCellText(value) {
|
|
25762
|
+
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();
|
|
25766
25763
|
}
|
|
25767
|
-
function
|
|
25768
|
-
|
|
25769
|
-
|
|
25770
|
-
const hasMediaContent = Boolean(cell.querySelector(TABLE_MEDIA_SELECTOR));
|
|
25771
|
-
if (!hasText && !hasBlockContent && !hasMediaContent) {
|
|
25772
|
-
cell.innerHTML = EMPTY_TABLE_CELL_HTML;
|
|
25764
|
+
function getClipboardCellText(node) {
|
|
25765
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
25766
|
+
return node.textContent ?? "";
|
|
25773
25767
|
}
|
|
25774
|
-
|
|
25775
|
-
|
|
25776
|
-
|
|
25777
|
-
|
|
25778
|
-
|
|
25768
|
+
if (!(node instanceof HTMLElement)) {
|
|
25769
|
+
return "";
|
|
25770
|
+
}
|
|
25771
|
+
if (node.tagName === "BR") {
|
|
25772
|
+
return "\n";
|
|
25779
25773
|
}
|
|
25774
|
+
const childText = Array.from(node.childNodes).map(getClipboardCellText).join("");
|
|
25775
|
+
if ((node.tagName === "P" || node.tagName === "DIV" || node.tagName === "LI") && childText && !childText.endsWith("\n")) {
|
|
25776
|
+
return `${childText}
|
|
25777
|
+
`;
|
|
25778
|
+
}
|
|
25779
|
+
return childText;
|
|
25780
|
+
}
|
|
25781
|
+
function getHtmlTableRows(table) {
|
|
25782
|
+
const rows = Array.from(table.querySelectorAll("tr")).map(
|
|
25783
|
+
(row) => Array.from(row.children).filter((cell) => cell instanceof HTMLTableCellElement).map((cell) => ({
|
|
25784
|
+
text: normalizeClipboardCellText(getClipboardCellText(cell)),
|
|
25785
|
+
isHeader: cell.tagName === "TH"
|
|
25786
|
+
}))
|
|
25787
|
+
);
|
|
25788
|
+
return rows.filter((row) => row.length > 0);
|
|
25789
|
+
}
|
|
25790
|
+
function createParagraphContent(text) {
|
|
25791
|
+
return text ? {
|
|
25792
|
+
type: "paragraph",
|
|
25793
|
+
content: [{ type: "text", text }]
|
|
25794
|
+
} : { type: "paragraph" };
|
|
25795
|
+
}
|
|
25796
|
+
function createTableCellContent(cell) {
|
|
25797
|
+
const lines = cell.text.split("\n");
|
|
25798
|
+
const paragraphs = (lines.length > 0 ? lines : [""]).map(createParagraphContent);
|
|
25799
|
+
return {
|
|
25800
|
+
type: cell.isHeader ? "tableHeader" : "tableCell",
|
|
25801
|
+
content: paragraphs.length > 0 ? paragraphs : [{ type: "paragraph" }]
|
|
25802
|
+
};
|
|
25780
25803
|
}
|
|
25781
|
-
function
|
|
25804
|
+
function createTableContent(rows, minColumnCount = 1) {
|
|
25805
|
+
const tableRows = rows.filter((row) => row.length > 0);
|
|
25806
|
+
if (tableRows.length === 0) return null;
|
|
25807
|
+
const columnCount = tableRows.reduce((max, row) => Math.max(max, row.length), 0);
|
|
25808
|
+
if (columnCount < minColumnCount) return null;
|
|
25809
|
+
return {
|
|
25810
|
+
type: "table",
|
|
25811
|
+
content: tableRows.map((row) => {
|
|
25812
|
+
const normalizedRow = Array.from(
|
|
25813
|
+
{ length: columnCount },
|
|
25814
|
+
(_, index) => row[index] ?? { text: "", isHeader: false }
|
|
25815
|
+
);
|
|
25816
|
+
return {
|
|
25817
|
+
type: "tableRow",
|
|
25818
|
+
content: normalizedRow.map(createTableCellContent)
|
|
25819
|
+
};
|
|
25820
|
+
})
|
|
25821
|
+
};
|
|
25822
|
+
}
|
|
25823
|
+
function getClipboardTableContent(dataTransfer) {
|
|
25782
25824
|
const html = getClipboardData(dataTransfer, "text/html");
|
|
25783
|
-
if (!/<table(?:\s|>)/i.test(html)) return
|
|
25825
|
+
if (!/<table(?:\s|>)/i.test(html)) return null;
|
|
25826
|
+
if (typeof DOMParser === "undefined") return null;
|
|
25784
25827
|
const fragment = extractClipboardHtmlFragment(html);
|
|
25785
|
-
|
|
25786
|
-
|
|
25787
|
-
|
|
25788
|
-
|
|
25789
|
-
normalizeClipboardTable(table);
|
|
25790
|
-
return table.outerHTML;
|
|
25791
|
-
}
|
|
25792
|
-
}
|
|
25793
|
-
return fragment;
|
|
25794
|
-
}
|
|
25795
|
-
function escapeHtml(value) {
|
|
25796
|
-
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
25828
|
+
const doc = new DOMParser().parseFromString(fragment, "text/html");
|
|
25829
|
+
const table = doc.querySelector("table");
|
|
25830
|
+
if (!(table instanceof HTMLTableElement)) return null;
|
|
25831
|
+
return createTableContent(getHtmlTableRows(table));
|
|
25797
25832
|
}
|
|
25798
25833
|
function parseClipboardTsvRows(text) {
|
|
25799
25834
|
const rows = [];
|
|
@@ -25845,22 +25880,14 @@ function parseClipboardTsvRows(text) {
|
|
|
25845
25880
|
}
|
|
25846
25881
|
return rows;
|
|
25847
25882
|
}
|
|
25848
|
-
function
|
|
25849
|
-
const lines = value.split("\n");
|
|
25850
|
-
const paragraphs = lines.length > 0 ? lines : [""];
|
|
25851
|
-
return paragraphs.map((line) => `<p>${escapeHtml(line)}</p>`).join("");
|
|
25852
|
-
}
|
|
25853
|
-
function getClipboardTsvTableHtml(dataTransfer) {
|
|
25883
|
+
function getClipboardTsvTableContent(dataTransfer) {
|
|
25854
25884
|
const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
25855
|
-
if (!text.includes(" ")) return
|
|
25885
|
+
if (!text.includes(" ")) return null;
|
|
25856
25886
|
const rows = parseClipboardTsvRows(text);
|
|
25857
|
-
|
|
25858
|
-
|
|
25859
|
-
|
|
25860
|
-
|
|
25861
|
-
return `<tr>${normalizedRow.map((cell) => `<td>${renderClipboardTableCellHtml(cell)}</td>`).join("")}</tr>`;
|
|
25862
|
-
}).join("");
|
|
25863
|
-
return `<table><tbody>${body}</tbody></table>`;
|
|
25887
|
+
return createTableContent(
|
|
25888
|
+
rows.map((row) => row.map((cell) => ({ text: normalizeClipboardCellText(cell), isHeader: false }))),
|
|
25889
|
+
2
|
|
25890
|
+
);
|
|
25864
25891
|
}
|
|
25865
25892
|
function fileToDataUrl(file) {
|
|
25866
25893
|
return new Promise((resolve, reject) => {
|
|
@@ -25916,16 +25943,16 @@ var ClipboardImages = Extension2.create({
|
|
|
25916
25943
|
props: {
|
|
25917
25944
|
handlePaste: (_view, event) => {
|
|
25918
25945
|
if (!event || !event.clipboardData) return false;
|
|
25919
|
-
const
|
|
25920
|
-
if (
|
|
25946
|
+
const tableContent = getClipboardTableContent(event.clipboardData);
|
|
25947
|
+
if (tableContent) {
|
|
25921
25948
|
event.preventDefault();
|
|
25922
|
-
editor.chain().focus().insertContent(
|
|
25949
|
+
editor.chain().focus().insertContent(tableContent).run();
|
|
25923
25950
|
return true;
|
|
25924
25951
|
}
|
|
25925
|
-
const
|
|
25926
|
-
if (
|
|
25952
|
+
const tsvTableContent = getClipboardTsvTableContent(event.clipboardData);
|
|
25953
|
+
if (tsvTableContent) {
|
|
25927
25954
|
event.preventDefault();
|
|
25928
|
-
editor.chain().focus().insertContent(
|
|
25955
|
+
editor.chain().focus().insertContent(tsvTableContent).run();
|
|
25929
25956
|
return true;
|
|
25930
25957
|
}
|
|
25931
25958
|
const files = getImageFiles(event.clipboardData);
|