@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/dist/index.js
CHANGED
|
@@ -25758,25 +25758,79 @@ function extractClipboardHtmlFragment(html) {
|
|
|
25758
25758
|
}
|
|
25759
25759
|
return html;
|
|
25760
25760
|
}
|
|
25761
|
-
function
|
|
25762
|
-
|
|
25763
|
-
|
|
25764
|
-
|
|
25765
|
-
if (
|
|
25766
|
-
|
|
25767
|
-
|
|
25768
|
-
|
|
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();
|
|
25763
|
+
}
|
|
25764
|
+
function getClipboardCellText(node) {
|
|
25765
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
25766
|
+
return node.textContent ?? "";
|
|
25767
|
+
}
|
|
25768
|
+
if (!(node instanceof HTMLElement)) {
|
|
25769
|
+
return "";
|
|
25770
|
+
}
|
|
25771
|
+
if (node.tagName === "BR") {
|
|
25772
|
+
return "\n";
|
|
25769
25773
|
}
|
|
25770
|
-
|
|
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" };
|
|
25771
25795
|
}
|
|
25772
|
-
function
|
|
25773
|
-
|
|
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
|
+
};
|
|
25803
|
+
}
|
|
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
|
+
};
|
|
25774
25822
|
}
|
|
25775
|
-
function
|
|
25776
|
-
const
|
|
25777
|
-
|
|
25823
|
+
function getClipboardTableContent(dataTransfer) {
|
|
25824
|
+
const html = getClipboardData(dataTransfer, "text/html");
|
|
25825
|
+
if (!/<table(?:\s|>)/i.test(html)) return null;
|
|
25826
|
+
if (typeof DOMParser === "undefined") return null;
|
|
25827
|
+
const fragment = extractClipboardHtmlFragment(html);
|
|
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));
|
|
25778
25832
|
}
|
|
25779
|
-
function
|
|
25833
|
+
function parseClipboardTsvRows(text) {
|
|
25780
25834
|
const rows = [];
|
|
25781
25835
|
let row = [];
|
|
25782
25836
|
let field = "";
|
|
@@ -25792,9 +25846,9 @@ function parseTsvRows(text) {
|
|
|
25792
25846
|
};
|
|
25793
25847
|
for (let index = 0; index < text.length; index += 1) {
|
|
25794
25848
|
const char = text[index];
|
|
25795
|
-
const
|
|
25849
|
+
const nextChar = text[index + 1];
|
|
25796
25850
|
if (inQuotes) {
|
|
25797
|
-
if (char === '"' &&
|
|
25851
|
+
if (char === '"' && nextChar === '"') {
|
|
25798
25852
|
field += '"';
|
|
25799
25853
|
index += 1;
|
|
25800
25854
|
continue;
|
|
@@ -25826,13 +25880,14 @@ function parseTsvRows(text) {
|
|
|
25826
25880
|
}
|
|
25827
25881
|
return rows;
|
|
25828
25882
|
}
|
|
25829
|
-
function
|
|
25830
|
-
const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n")
|
|
25831
|
-
if (!text.includes(" ")) return
|
|
25832
|
-
const rows =
|
|
25833
|
-
|
|
25834
|
-
|
|
25835
|
-
|
|
25883
|
+
function getClipboardTsvTableContent(dataTransfer) {
|
|
25884
|
+
const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
25885
|
+
if (!text.includes(" ")) return null;
|
|
25886
|
+
const rows = parseClipboardTsvRows(text);
|
|
25887
|
+
return createTableContent(
|
|
25888
|
+
rows.map((row) => row.map((cell) => ({ text: normalizeClipboardCellText(cell), isHeader: false }))),
|
|
25889
|
+
2
|
|
25890
|
+
);
|
|
25836
25891
|
}
|
|
25837
25892
|
function fileToDataUrl(file) {
|
|
25838
25893
|
return new Promise((resolve, reject) => {
|
|
@@ -25888,16 +25943,16 @@ var ClipboardImages = Extension2.create({
|
|
|
25888
25943
|
props: {
|
|
25889
25944
|
handlePaste: (_view, event) => {
|
|
25890
25945
|
if (!event || !event.clipboardData) return false;
|
|
25891
|
-
const
|
|
25892
|
-
if (
|
|
25946
|
+
const tableContent = getClipboardTableContent(event.clipboardData);
|
|
25947
|
+
if (tableContent) {
|
|
25893
25948
|
event.preventDefault();
|
|
25894
|
-
editor.chain().focus().insertContent(
|
|
25949
|
+
editor.chain().focus().insertContent(tableContent).run();
|
|
25895
25950
|
return true;
|
|
25896
25951
|
}
|
|
25897
|
-
const
|
|
25898
|
-
if (
|
|
25952
|
+
const tsvTableContent = getClipboardTsvTableContent(event.clipboardData);
|
|
25953
|
+
if (tsvTableContent) {
|
|
25899
25954
|
event.preventDefault();
|
|
25900
|
-
editor.chain().focus().insertContent(
|
|
25955
|
+
editor.chain().focus().insertContent(tsvTableContent).run();
|
|
25901
25956
|
return true;
|
|
25902
25957
|
}
|
|
25903
25958
|
const files = getImageFiles(event.clipboardData);
|