@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.
- package/api-reference.json +1 -1
- package/dist/index.cjs +85 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +85 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/api-reference.json
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -25913,25 +25913,79 @@ function extractClipboardHtmlFragment(html) {
|
|
|
25913
25913
|
}
|
|
25914
25914
|
return html;
|
|
25915
25915
|
}
|
|
25916
|
-
function
|
|
25917
|
-
|
|
25918
|
-
|
|
25919
|
-
|
|
25920
|
-
if (
|
|
25921
|
-
|
|
25922
|
-
|
|
25923
|
-
|
|
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
|
-
|
|
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
|
|
25928
|
-
|
|
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
|
|
25931
|
-
const
|
|
25932
|
-
|
|
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
|
|
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
|
|
26004
|
+
const nextChar = text[index + 1];
|
|
25951
26005
|
if (inQuotes) {
|
|
25952
|
-
if (char === '"' &&
|
|
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
|
|
25985
|
-
const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n")
|
|
25986
|
-
if (!text.includes(" ")) return
|
|
25987
|
-
const rows =
|
|
25988
|
-
|
|
25989
|
-
|
|
25990
|
-
|
|
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
|
|
26047
|
-
if (
|
|
26101
|
+
const tableContent = getClipboardTableContent(event.clipboardData);
|
|
26102
|
+
if (tableContent) {
|
|
26048
26103
|
event.preventDefault();
|
|
26049
|
-
editor.chain().focus().insertContent(
|
|
26104
|
+
editor.chain().focus().insertContent(tableContent).run();
|
|
26050
26105
|
return true;
|
|
26051
26106
|
}
|
|
26052
|
-
const
|
|
26053
|
-
if (
|
|
26107
|
+
const tsvTableContent = getClipboardTsvTableContent(event.clipboardData);
|
|
26108
|
+
if (tsvTableContent) {
|
|
26054
26109
|
event.preventDefault();
|
|
26055
|
-
editor.chain().focus().insertContent(
|
|
26110
|
+
editor.chain().focus().insertContent(tsvTableContent).run();
|
|
26056
26111
|
return true;
|
|
26057
26112
|
}
|
|
26058
26113
|
const files = getImageFiles(event.clipboardData);
|