@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/api-reference.json
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -25913,42 +25913,77 @@ function extractClipboardHtmlFragment(html) {
|
|
|
25913
25913
|
}
|
|
25914
25914
|
return html;
|
|
25915
25915
|
}
|
|
25916
|
-
|
|
25917
|
-
|
|
25918
|
-
var TABLE_BLOCK_SELECTOR = "p,ul,ol,blockquote,pre,h1,h2,h3,h4,h5,h6,hr,table";
|
|
25919
|
-
function hasMeaningfulTableCellText(value) {
|
|
25920
|
-
return Boolean(value?.replace(/\u00a0/g, " ").trim());
|
|
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();
|
|
25921
25918
|
}
|
|
25922
|
-
function
|
|
25923
|
-
|
|
25924
|
-
|
|
25925
|
-
const hasMediaContent = Boolean(cell.querySelector(TABLE_MEDIA_SELECTOR));
|
|
25926
|
-
if (!hasText && !hasBlockContent && !hasMediaContent) {
|
|
25927
|
-
cell.innerHTML = EMPTY_TABLE_CELL_HTML;
|
|
25919
|
+
function getClipboardCellText(node) {
|
|
25920
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
25921
|
+
return node.textContent ?? "";
|
|
25928
25922
|
}
|
|
25929
|
-
|
|
25930
|
-
|
|
25931
|
-
|
|
25932
|
-
|
|
25933
|
-
|
|
25923
|
+
if (!(node instanceof HTMLElement)) {
|
|
25924
|
+
return "";
|
|
25925
|
+
}
|
|
25926
|
+
if (node.tagName === "BR") {
|
|
25927
|
+
return "\n";
|
|
25934
25928
|
}
|
|
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" };
|
|
25950
|
+
}
|
|
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
|
+
};
|
|
25935
25958
|
}
|
|
25936
|
-
function
|
|
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
|
+
};
|
|
25977
|
+
}
|
|
25978
|
+
function getClipboardTableContent(dataTransfer) {
|
|
25937
25979
|
const html = getClipboardData(dataTransfer, "text/html");
|
|
25938
|
-
if (!/<table(?:\s|>)/i.test(html)) return
|
|
25980
|
+
if (!/<table(?:\s|>)/i.test(html)) return null;
|
|
25981
|
+
if (typeof DOMParser === "undefined") return null;
|
|
25939
25982
|
const fragment = extractClipboardHtmlFragment(html);
|
|
25940
|
-
|
|
25941
|
-
|
|
25942
|
-
|
|
25943
|
-
|
|
25944
|
-
normalizeClipboardTable(table);
|
|
25945
|
-
return table.outerHTML;
|
|
25946
|
-
}
|
|
25947
|
-
}
|
|
25948
|
-
return fragment;
|
|
25949
|
-
}
|
|
25950
|
-
function escapeHtml(value) {
|
|
25951
|
-
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
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));
|
|
25952
25987
|
}
|
|
25953
25988
|
function parseClipboardTsvRows(text) {
|
|
25954
25989
|
const rows = [];
|
|
@@ -26000,22 +26035,14 @@ function parseClipboardTsvRows(text) {
|
|
|
26000
26035
|
}
|
|
26001
26036
|
return rows;
|
|
26002
26037
|
}
|
|
26003
|
-
function
|
|
26004
|
-
const lines = value.split("\n");
|
|
26005
|
-
const paragraphs = lines.length > 0 ? lines : [""];
|
|
26006
|
-
return paragraphs.map((line) => `<p>${escapeHtml(line)}</p>`).join("");
|
|
26007
|
-
}
|
|
26008
|
-
function getClipboardTsvTableHtml(dataTransfer) {
|
|
26038
|
+
function getClipboardTsvTableContent(dataTransfer) {
|
|
26009
26039
|
const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
26010
|
-
if (!text.includes(" ")) return
|
|
26040
|
+
if (!text.includes(" ")) return null;
|
|
26011
26041
|
const rows = parseClipboardTsvRows(text);
|
|
26012
|
-
|
|
26013
|
-
|
|
26014
|
-
|
|
26015
|
-
|
|
26016
|
-
return `<tr>${normalizedRow.map((cell) => `<td>${renderClipboardTableCellHtml(cell)}</td>`).join("")}</tr>`;
|
|
26017
|
-
}).join("");
|
|
26018
|
-
return `<table><tbody>${body}</tbody></table>`;
|
|
26042
|
+
return createTableContent(
|
|
26043
|
+
rows.map((row) => row.map((cell) => ({ text: normalizeClipboardCellText(cell), isHeader: false }))),
|
|
26044
|
+
2
|
|
26045
|
+
);
|
|
26019
26046
|
}
|
|
26020
26047
|
function fileToDataUrl(file) {
|
|
26021
26048
|
return new Promise((resolve, reject) => {
|
|
@@ -26071,16 +26098,16 @@ var ClipboardImages = import_core5.Extension.create({
|
|
|
26071
26098
|
props: {
|
|
26072
26099
|
handlePaste: (_view, event) => {
|
|
26073
26100
|
if (!event || !event.clipboardData) return false;
|
|
26074
|
-
const
|
|
26075
|
-
if (
|
|
26101
|
+
const tableContent = getClipboardTableContent(event.clipboardData);
|
|
26102
|
+
if (tableContent) {
|
|
26076
26103
|
event.preventDefault();
|
|
26077
|
-
editor.chain().focus().insertContent(
|
|
26104
|
+
editor.chain().focus().insertContent(tableContent).run();
|
|
26078
26105
|
return true;
|
|
26079
26106
|
}
|
|
26080
|
-
const
|
|
26081
|
-
if (
|
|
26107
|
+
const tsvTableContent = getClipboardTsvTableContent(event.clipboardData);
|
|
26108
|
+
if (tsvTableContent) {
|
|
26082
26109
|
event.preventDefault();
|
|
26083
|
-
editor.chain().focus().insertContent(
|
|
26110
|
+
editor.chain().focus().insertContent(tsvTableContent).run();
|
|
26084
26111
|
return true;
|
|
26085
26112
|
}
|
|
26086
26113
|
const files = getImageFiles(event.clipboardData);
|