@underverse-ui/underverse 1.0.145 → 1.0.146
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 +39 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/api-reference.json
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -25913,6 +25913,26 @@ function extractClipboardHtmlFragment(html) {
|
|
|
25913
25913
|
}
|
|
25914
25914
|
return html;
|
|
25915
25915
|
}
|
|
25916
|
+
var EMPTY_TABLE_CELL_HTML = "<p></p>";
|
|
25917
|
+
var TABLE_MEDIA_SELECTOR = "img,video,audio,iframe,svg,canvas,embed,object";
|
|
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());
|
|
25921
|
+
}
|
|
25922
|
+
function normalizeClipboardTableCell(cell) {
|
|
25923
|
+
const hasText = hasMeaningfulTableCellText(cell.textContent);
|
|
25924
|
+
const hasBlockContent = Boolean(cell.querySelector(TABLE_BLOCK_SELECTOR));
|
|
25925
|
+
const hasMediaContent = Boolean(cell.querySelector(TABLE_MEDIA_SELECTOR));
|
|
25926
|
+
if (!hasText && !hasBlockContent && !hasMediaContent) {
|
|
25927
|
+
cell.innerHTML = EMPTY_TABLE_CELL_HTML;
|
|
25928
|
+
}
|
|
25929
|
+
}
|
|
25930
|
+
function normalizeClipboardTable(table) {
|
|
25931
|
+
for (const cell of Array.from(table.querySelectorAll("td,th"))) {
|
|
25932
|
+
if (!(cell instanceof HTMLTableCellElement)) continue;
|
|
25933
|
+
normalizeClipboardTableCell(cell);
|
|
25934
|
+
}
|
|
25935
|
+
}
|
|
25916
25936
|
function getClipboardTableHtml(dataTransfer) {
|
|
25917
25937
|
const html = getClipboardData(dataTransfer, "text/html");
|
|
25918
25938
|
if (!/<table(?:\s|>)/i.test(html)) return "";
|
|
@@ -25920,18 +25940,17 @@ function getClipboardTableHtml(dataTransfer) {
|
|
|
25920
25940
|
if (typeof DOMParser !== "undefined") {
|
|
25921
25941
|
const doc = new DOMParser().parseFromString(fragment, "text/html");
|
|
25922
25942
|
const table = doc.querySelector("table");
|
|
25923
|
-
if (table)
|
|
25943
|
+
if (table instanceof HTMLTableElement) {
|
|
25944
|
+
normalizeClipboardTable(table);
|
|
25945
|
+
return table.outerHTML;
|
|
25946
|
+
}
|
|
25924
25947
|
}
|
|
25925
25948
|
return fragment;
|
|
25926
25949
|
}
|
|
25927
25950
|
function escapeHtml(value) {
|
|
25928
25951
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
25929
25952
|
}
|
|
25930
|
-
function
|
|
25931
|
-
const lines = value.split("\n");
|
|
25932
|
-
return lines.map((line) => `<p>${escapeHtml(line)}</p>`).join("");
|
|
25933
|
-
}
|
|
25934
|
-
function parseTsvRows(text) {
|
|
25953
|
+
function parseClipboardTsvRows(text) {
|
|
25935
25954
|
const rows = [];
|
|
25936
25955
|
let row = [];
|
|
25937
25956
|
let field = "";
|
|
@@ -25947,9 +25966,9 @@ function parseTsvRows(text) {
|
|
|
25947
25966
|
};
|
|
25948
25967
|
for (let index = 0; index < text.length; index += 1) {
|
|
25949
25968
|
const char = text[index];
|
|
25950
|
-
const
|
|
25969
|
+
const nextChar = text[index + 1];
|
|
25951
25970
|
if (inQuotes) {
|
|
25952
|
-
if (char === '"' &&
|
|
25971
|
+
if (char === '"' && nextChar === '"') {
|
|
25953
25972
|
field += '"';
|
|
25954
25973
|
index += 1;
|
|
25955
25974
|
continue;
|
|
@@ -25981,12 +26000,21 @@ function parseTsvRows(text) {
|
|
|
25981
26000
|
}
|
|
25982
26001
|
return rows;
|
|
25983
26002
|
}
|
|
26003
|
+
function renderClipboardTableCellHtml(value) {
|
|
26004
|
+
const lines = value.split("\n");
|
|
26005
|
+
const paragraphs = lines.length > 0 ? lines : [""];
|
|
26006
|
+
return paragraphs.map((line) => `<p>${escapeHtml(line)}</p>`).join("");
|
|
26007
|
+
}
|
|
25984
26008
|
function getClipboardTsvTableHtml(dataTransfer) {
|
|
25985
|
-
const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n")
|
|
26009
|
+
const text = getClipboardData(dataTransfer, "text/plain").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
25986
26010
|
if (!text.includes(" ")) return "";
|
|
25987
|
-
const rows =
|
|
26011
|
+
const rows = parseClipboardTsvRows(text);
|
|
25988
26012
|
if (rows.length === 0 || rows.every((row) => row.length < 2)) return "";
|
|
25989
|
-
const
|
|
26013
|
+
const columnCount = rows.reduce((max, row) => Math.max(max, row.length), 0);
|
|
26014
|
+
const body = rows.map((row) => {
|
|
26015
|
+
const normalizedRow = Array.from({ length: columnCount }, (_, index) => row[index] ?? "");
|
|
26016
|
+
return `<tr>${normalizedRow.map((cell) => `<td>${renderClipboardTableCellHtml(cell)}</td>`).join("")}</tr>`;
|
|
26017
|
+
}).join("");
|
|
25990
26018
|
return `<table><tbody>${body}</tbody></table>`;
|
|
25991
26019
|
}
|
|
25992
26020
|
function fileToDataUrl(file) {
|