@fileverse-dev/fortune-core 1.3.13-create-1 → 1.3.13-create-2
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/es/events/paste.js +80 -17
- package/es/modules/cell.d.ts +1 -0
- package/es/modules/cell.js +62 -27
- package/es/modules/inline-string.js +40 -4
- package/lib/events/paste.js +80 -17
- package/lib/modules/cell.d.ts +1 -0
- package/lib/modules/cell.js +61 -26
- package/lib/modules/inline-string.js +40 -4
- package/package.json +1 -1
package/es/events/paste.js
CHANGED
|
@@ -1446,28 +1446,91 @@ function shouldHandleNonTableHtml(html) {
|
|
|
1446
1446
|
if (!html || /<table[\s/>]/i.test(html)) return false;
|
|
1447
1447
|
return /<[a-z]/i.test(html);
|
|
1448
1448
|
}
|
|
1449
|
-
function
|
|
1449
|
+
function convertAnyHtmlToTable(html) {
|
|
1450
1450
|
var container = document.createElement("div");
|
|
1451
1451
|
container.innerHTML = html;
|
|
1452
1452
|
var rows = [];
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1453
|
+
var currentParts = [];
|
|
1454
|
+
var BLOCK_TAGS = new Set(["P", "DIV", "SECTION", "ARTICLE", "ASIDE", "HEADER", "FOOTER", "MAIN", "NAV", "BLOCKQUOTE", "PRE", "H1", "H2", "H3", "H4", "H5", "H6", "UL", "OL", "LI", "DL", "DT", "DD", "TABLE", "THEAD", "TBODY", "TFOOT", "TR", "TD", "TH", "HR"]);
|
|
1455
|
+
var SKIP_TAGS = new Set(["SCRIPT", "STYLE", "NOSCRIPT", "META", "LINK", "HEAD", "SVG", "CANVAS", "IFRAME", "OBJECT"]);
|
|
1456
|
+
var escapeHtml = function escapeHtml(text) {
|
|
1457
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1458
|
+
};
|
|
1459
|
+
var normalizeText = function normalizeText(text) {
|
|
1460
|
+
return text.replace(/\u00A0/g, " ").replace(/\s+/g, " ");
|
|
1461
|
+
};
|
|
1462
|
+
var flushRow = function flushRow() {
|
|
1463
|
+
var htmlContent = currentParts.join("").trim();
|
|
1464
|
+
var textOnly = htmlContent.replace(/<br\s*\/?>/gi, "").replace(/ /gi, " ").replace(/\s+/g, " ").trim();
|
|
1465
|
+
if (textOnly) {
|
|
1466
|
+
rows.push("<tr><td>".concat(htmlContent, "</td></tr>"));
|
|
1457
1467
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1468
|
+
currentParts = [];
|
|
1469
|
+
};
|
|
1470
|
+
var appendText = function appendText(text) {
|
|
1471
|
+
var normalized = normalizeText(text);
|
|
1472
|
+
if (!normalized.trim()) return;
|
|
1473
|
+
var prev = currentParts[currentParts.length - 1] || "";
|
|
1474
|
+
var needsSpace = prev && !prev.endsWith(" ") && !prev.endsWith("<br>") && !/>\s*$/.test(prev);
|
|
1475
|
+
currentParts.push((needsSpace ? " " : "") + escapeHtml(normalized.trim()));
|
|
1476
|
+
};
|
|
1477
|
+
var isBlock = function isBlock(node) {
|
|
1478
|
+
return node.nodeType === Node.ELEMENT_NODE && BLOCK_TAGS.has(node.tagName);
|
|
1479
|
+
};
|
|
1480
|
+
var _walk = function walk(node) {
|
|
1481
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
1482
|
+
appendText(node.textContent || "");
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
1486
|
+
var el = node;
|
|
1487
|
+
var tag = el.tagName;
|
|
1488
|
+
if (SKIP_TAGS.has(tag)) return;
|
|
1489
|
+
if (tag === "BR" || tag === "HR") {
|
|
1490
|
+
flushRow();
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
1493
|
+
if (tag === "TABLE") {
|
|
1494
|
+
flushRow();
|
|
1495
|
+
var trs = el.querySelectorAll(":scope > tbody > tr, :scope > thead > tr, :scope > tfoot > tr, :scope > tr");
|
|
1496
|
+
if (trs.length > 0) {
|
|
1497
|
+
trs.forEach(function (tr) {
|
|
1498
|
+
var cells = Array.from(tr.children).filter(function (child) {
|
|
1499
|
+
return /^(TD|TH)$/.test(child.tagName);
|
|
1500
|
+
});
|
|
1501
|
+
if (!cells.length) return;
|
|
1502
|
+
var rowHtml = cells.map(function (cell) {
|
|
1503
|
+
return "<td>".concat(escapeHtml((cell.textContent || "").replace(/\s+/g, " ").trim()), "</td>");
|
|
1504
|
+
}).join("");
|
|
1505
|
+
if (rowHtml.replace(/<[^>]+>/g, "").trim()) {
|
|
1506
|
+
rows.push("<tr>".concat(rowHtml, "</tr>"));
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
} else {
|
|
1510
|
+
var text = (el.textContent || "").replace(/\s+/g, " ").trim();
|
|
1511
|
+
if (text) rows.push("<tr><td>".concat(escapeHtml(text), "</td></tr>"));
|
|
1464
1512
|
}
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
var block = isBlock(el);
|
|
1516
|
+
if (block && currentParts.length > 0 && tag !== "LI") {
|
|
1517
|
+
flushRow();
|
|
1518
|
+
}
|
|
1519
|
+
if (tag === "LI") {
|
|
1520
|
+
flushRow();
|
|
1521
|
+
}
|
|
1522
|
+
Array.from(el.childNodes).forEach(_walk);
|
|
1523
|
+
if (block) {
|
|
1524
|
+
flushRow();
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
Array.from(container.childNodes).forEach(_walk);
|
|
1528
|
+
flushRow();
|
|
1529
|
+
if (!rows.length) {
|
|
1530
|
+
var text = (container.textContent || "").replace(/\s+/g, " ").trim();
|
|
1531
|
+
return "<table><tr><td>".concat(escapeHtml(text), "</td></tr></table>");
|
|
1469
1532
|
}
|
|
1470
|
-
return "<table
|
|
1533
|
+
return "<table>".concat(rows.join(""), "</table>");
|
|
1471
1534
|
}
|
|
1472
1535
|
export function handlePaste(ctx, e) {
|
|
1473
1536
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
|
|
@@ -1579,7 +1642,7 @@ export function handlePaste(ctx, e) {
|
|
|
1579
1642
|
var shouldHandleAsHtml = /<table[\s/>]/i.test(txtdata) || shouldHandleNonTableHtml(txtdata);
|
|
1580
1643
|
if (shouldHandleAsHtml) {
|
|
1581
1644
|
var hasNativeTable = /<table[\s/>]/i.test(txtdata);
|
|
1582
|
-
var converted = hasNativeTable ? txtdata :
|
|
1645
|
+
var converted = hasNativeTable ? txtdata : convertAnyHtmlToTable(txtdata);
|
|
1583
1646
|
handlePastedTable(ctx, converted, pasteHandler);
|
|
1584
1647
|
if (hasNativeTable) {
|
|
1585
1648
|
resizePastedCellsToContent(ctx);
|
package/es/modules/cell.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare function getFontStyleByCell(cell: Cell | null | undefined, checks
|
|
|
27
27
|
export declare function getStyleByCell(ctx: Context, d: CellMatrix, r: number, c: number): any;
|
|
28
28
|
export declare function getInlineStringHTML(r: number, c: number, data: CellMatrix, options?: {
|
|
29
29
|
useSemanticMarkup?: boolean;
|
|
30
|
+
isRangeCopy?: boolean;
|
|
30
31
|
inheritedStyle?: Record<string, string>;
|
|
31
32
|
}): string;
|
|
32
33
|
export declare function getQKBorder(width: string, type: string, color: string): (string | number)[];
|
package/es/modules/cell.js
CHANGED
|
@@ -17,7 +17,7 @@ import { getFailureText, validateCellData } from "./dataVerification";
|
|
|
17
17
|
import { genarate, update } from "./format";
|
|
18
18
|
import { clearCellError, getRowHeight } from "../api";
|
|
19
19
|
import { delFunctionGroup, execfunction, execFunctionGroup, functionHTMLGenerate, getcellrange, iscelldata, suppressFormulaRangeSelectionForInitialEdit } from "./formula";
|
|
20
|
-
import {
|
|
20
|
+
import { convertSpanToShareString, isInlineStringCell, isInlineStringCT } from "./inline-string";
|
|
21
21
|
import { isRealNull, isRealNum, valueIsError } from "./validation";
|
|
22
22
|
import { getCellTextInfo } from "./text";
|
|
23
23
|
import { locale } from "../locale";
|
|
@@ -1009,37 +1009,68 @@ export function getRangeByTxt(ctx, txt) {
|
|
|
1009
1009
|
return range;
|
|
1010
1010
|
}
|
|
1011
1011
|
export function isAllSelectedCellsInStatus(ctx, attr, status) {
|
|
1012
|
-
var _a, _b
|
|
1012
|
+
var _a, _b;
|
|
1013
1013
|
if (!_.isEmpty(ctx.luckysheetCellUpdate)) {
|
|
1014
1014
|
var w = window.getSelection();
|
|
1015
1015
|
if (!w) return false;
|
|
1016
1016
|
if (w.rangeCount === 0) return false;
|
|
1017
|
-
var
|
|
1018
|
-
if (
|
|
1017
|
+
var range_1 = w.getRangeAt(0);
|
|
1018
|
+
if (range_1.collapsed === true) {
|
|
1019
1019
|
return false;
|
|
1020
1020
|
}
|
|
1021
|
-
var endContainer =
|
|
1022
|
-
var startContainer =
|
|
1023
|
-
var
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1021
|
+
var endContainer = range_1.endContainer;
|
|
1022
|
+
var startContainer = range_1.startContainer;
|
|
1023
|
+
var toElement = function toElement(n) {
|
|
1024
|
+
if (!n) return null;
|
|
1025
|
+
if (n.nodeType === Node.ELEMENT_NODE) return n;
|
|
1026
|
+
return n.parentElement;
|
|
1027
|
+
};
|
|
1028
|
+
var startEl = toElement(startContainer);
|
|
1029
|
+
var endEl = toElement(endContainer);
|
|
1030
|
+
var editorRoot = (_b = (_a = startEl === null || startEl === void 0 ? void 0 : startEl.closest("#luckysheet-rich-text-editor")) !== null && _a !== void 0 ? _a : endEl === null || endEl === void 0 ? void 0 : endEl.closest("#luckysheet-rich-text-editor")) !== null && _b !== void 0 ? _b : toElement(range_1.commonAncestorContainer);
|
|
1031
|
+
var isStyleActive_1 = function isStyleActive_1(element) {
|
|
1032
|
+
var computed = window.getComputedStyle(element);
|
|
1033
|
+
var fontWeight = (computed.fontWeight || "").toLowerCase();
|
|
1034
|
+
var fontStyle = (computed.fontStyle || "").toLowerCase();
|
|
1035
|
+
var textDecorationLine = (computed.textDecorationLine || computed.textDecoration || "").toLowerCase();
|
|
1036
|
+
var borderBottomWidth = (computed.borderBottomWidth || "").toLowerCase();
|
|
1037
|
+
if (status === 1) {
|
|
1038
|
+
if (attr === "bl") {
|
|
1039
|
+
if (fontWeight === "bold") return true;
|
|
1040
|
+
var n = Number(fontWeight);
|
|
1041
|
+
return !Number.isNaN(n) && n >= 600;
|
|
1042
|
+
}
|
|
1043
|
+
if (attr === "it") {
|
|
1044
|
+
return fontStyle === "italic" || fontStyle === "oblique";
|
|
1045
|
+
}
|
|
1046
|
+
if (attr === "cl") {
|
|
1047
|
+
return textDecorationLine.includes("line-through");
|
|
1048
|
+
}
|
|
1049
|
+
if (attr === "un") {
|
|
1050
|
+
return textDecorationLine.includes("underline") || borderBottomWidth !== "" && borderBottomWidth !== "0px" && borderBottomWidth !== "0";
|
|
1037
1051
|
}
|
|
1038
|
-
return _.every(rangeSpans, function (s) {
|
|
1039
|
-
return !_.isEmpty(s.style[cssField_1]);
|
|
1040
|
-
});
|
|
1041
1052
|
}
|
|
1053
|
+
return false;
|
|
1054
|
+
};
|
|
1055
|
+
var selectedElements_1 = [];
|
|
1056
|
+
if (editorRoot) {
|
|
1057
|
+
var spans = editorRoot.querySelectorAll("span");
|
|
1058
|
+
spans.forEach(function (span) {
|
|
1059
|
+
if (span.textContent && span.textContent.length > 0 && range_1.intersectsNode(span)) {
|
|
1060
|
+
selectedElements_1.push(span);
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
if (selectedElements_1.length === 0) {
|
|
1065
|
+
if (startEl) selectedElements_1.push(startEl);
|
|
1066
|
+
if (endEl && endEl !== startEl) selectedElements_1.push(endEl);
|
|
1067
|
+
}
|
|
1068
|
+
if (selectedElements_1.length === 0) {
|
|
1069
|
+
return false;
|
|
1042
1070
|
}
|
|
1071
|
+
return _.every(selectedElements_1, function (el) {
|
|
1072
|
+
return isStyleActive_1(el);
|
|
1073
|
+
});
|
|
1043
1074
|
}
|
|
1044
1075
|
var cells = getFlattenedRange(ctx);
|
|
1045
1076
|
var flowdata = getFlowdata(ctx);
|
|
@@ -1234,11 +1265,15 @@ export function getInlineStringHTML(r, c, data, options) {
|
|
|
1234
1265
|
return "".concat(_.kebabCase(key), ":").concat(_.isNumber(v) ? "".concat(v, "px") : v, ";");
|
|
1235
1266
|
}).join(" ");
|
|
1236
1267
|
var dataAttrs = !(options === null || options === void 0 ? void 0 : options.useSemanticMarkup) && (link === null || link === void 0 ? void 0 : link.linkType) && (link === null || link === void 0 ? void 0 : link.linkAddress) ? " data-link-type='".concat(String(link.linkType).replace(/'/g, "'"), "' data-link-address='").concat(String(link.linkAddress).replace(/'/g, "'"), "'") : "";
|
|
1237
|
-
if (options === null || options === void 0 ? void 0 : options.
|
|
1238
|
-
|
|
1268
|
+
if (options === null || options === void 0 ? void 0 : options.isRangeCopy) {
|
|
1269
|
+
if (options === null || options === void 0 ? void 0 : options.useSemanticMarkup) {
|
|
1270
|
+
value += buildClipboardCompatibleInlineRuns(strObj.v, styleStr);
|
|
1271
|
+
} else {
|
|
1272
|
+
var segmentText = strObj.v.replace(/\r\n/g, "<br>").replace(/\n/g, "<br>");
|
|
1273
|
+
value += "<span class=\"luckysheet-input-span\" index='".concat(i, "' style='").concat(styleStr, "'").concat(dataAttrs, ">").concat(segmentText, "</span>");
|
|
1274
|
+
}
|
|
1239
1275
|
} else {
|
|
1240
|
-
|
|
1241
|
-
value += "<span class=\"luckysheet-input-span\" index='".concat(i, "' style='").concat(styleStr, "'").concat(dataAttrs, ">").concat(segmentText, "</span>");
|
|
1276
|
+
value += "<span class=\"luckysheet-input-span\" index='".concat(i, "' style='").concat(styleStr, "'").concat(dataAttrs, ">").concat(strObj.v, "</span>");
|
|
1242
1277
|
}
|
|
1243
1278
|
}
|
|
1244
1279
|
}
|
|
@@ -236,9 +236,12 @@ function getCssText(cssText, attr, value) {
|
|
|
236
236
|
styleObj._color = fontColor;
|
|
237
237
|
}
|
|
238
238
|
var s = getFontStyleByCell(styleObj, undefined, undefined, false);
|
|
239
|
+
cssText = removeClassWidthCss(cssText, attr);
|
|
240
|
+
if (_.isEmpty(s)) {
|
|
241
|
+
return cssText;
|
|
242
|
+
}
|
|
239
243
|
var ukey = _.kebabCase(Object.keys(s)[0]);
|
|
240
244
|
var uvalue = Object.values(s)[0];
|
|
241
|
-
cssText = removeClassWidthCss(cssText, attr);
|
|
242
245
|
cssText = upsetClassWithCss(cssText, ukey, uvalue);
|
|
243
246
|
return cssText;
|
|
244
247
|
}
|
|
@@ -300,16 +303,31 @@ function escapeHtmlAttr(s) {
|
|
|
300
303
|
return s.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
301
304
|
}
|
|
302
305
|
export function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
303
|
-
var _a, _b, _c;
|
|
306
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
304
307
|
var w = window.getSelection();
|
|
305
308
|
if (!w) return;
|
|
306
309
|
if (w.rangeCount === 0) return;
|
|
307
310
|
var range = w.getRangeAt(0);
|
|
308
311
|
var $textEditor = cellInput;
|
|
312
|
+
var editorText = ((_b = (_a = $textEditor.innerText) !== null && _a !== void 0 ? _a : $textEditor.textContent) !== null && _b !== void 0 ? _b : "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
313
|
+
var selectedText = ((_c = range.toString()) !== null && _c !== void 0 ? _c : "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
314
|
+
if (range.collapsed === false && editorText.length > 0 && selectedText === editorText) {
|
|
315
|
+
$textEditor.innerHTML = "";
|
|
316
|
+
var wrapper = document.createElement("span");
|
|
317
|
+
wrapper.setAttribute("style", getCssText("", attr, value));
|
|
318
|
+
wrapper.textContent = editorText;
|
|
319
|
+
$textEditor.appendChild(wrapper);
|
|
320
|
+
var newRange = document.createRange();
|
|
321
|
+
newRange.selectNodeContents($textEditor);
|
|
322
|
+
w.removeAllRanges();
|
|
323
|
+
w.addRange(newRange);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
309
326
|
if (range.startContainer === $textEditor && range.endContainer === $textEditor && range.collapsed === false) {
|
|
310
327
|
var start = range.startOffset;
|
|
311
328
|
var end = range.endOffset;
|
|
312
329
|
var children = Array.from($textEditor.childNodes).slice(start, end);
|
|
330
|
+
var hasUnsupportedElementSelection_1 = false;
|
|
313
331
|
children.forEach(function (node) {
|
|
314
332
|
var _a, _b;
|
|
315
333
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
@@ -317,6 +335,16 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
|
317
335
|
if (el.tagName === "SPAN") {
|
|
318
336
|
var cssText = getCssText(el.style.cssText, attr, value);
|
|
319
337
|
el.setAttribute("style", cssText);
|
|
338
|
+
} else {
|
|
339
|
+
var nestedSpans = el.querySelectorAll("span");
|
|
340
|
+
if (nestedSpans.length > 0) {
|
|
341
|
+
nestedSpans.forEach(function (nestedSpan) {
|
|
342
|
+
var cssText = getCssText(nestedSpan.style.cssText, attr, value);
|
|
343
|
+
nestedSpan.setAttribute("style", cssText);
|
|
344
|
+
});
|
|
345
|
+
} else {
|
|
346
|
+
hasUnsupportedElementSelection_1 = true;
|
|
347
|
+
}
|
|
320
348
|
}
|
|
321
349
|
} else if (node.nodeType === Node.TEXT_NODE) {
|
|
322
350
|
var text = (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
|
|
@@ -328,6 +356,14 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
|
328
356
|
(_b = node.parentNode) === null || _b === void 0 ? void 0 : _b.replaceChild(wrapper, node);
|
|
329
357
|
}
|
|
330
358
|
});
|
|
359
|
+
if (hasUnsupportedElementSelection_1) {
|
|
360
|
+
var fullText = (_e = (_d = $textEditor.innerText) !== null && _d !== void 0 ? _d : $textEditor.textContent) !== null && _e !== void 0 ? _e : "";
|
|
361
|
+
$textEditor.innerHTML = "";
|
|
362
|
+
var wrapper = document.createElement("span");
|
|
363
|
+
wrapper.setAttribute("style", getCssText("", attr, value));
|
|
364
|
+
wrapper.textContent = fullText;
|
|
365
|
+
$textEditor.appendChild(wrapper);
|
|
366
|
+
}
|
|
331
367
|
var newRange = document.createRange();
|
|
332
368
|
newRange.selectNodeContents($textEditor);
|
|
333
369
|
w.removeAllRanges();
|
|
@@ -405,7 +441,7 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
|
405
441
|
}
|
|
406
442
|
cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(right, "</span>");
|
|
407
443
|
}
|
|
408
|
-
if (((
|
|
444
|
+
if (((_f = startContainer.parentElement) === null || _f === void 0 ? void 0 : _f.tagName) === "SPAN") {
|
|
409
445
|
spanIndex = _.indexOf($textEditor.querySelectorAll("span"), span);
|
|
410
446
|
span.outerHTML = cont;
|
|
411
447
|
} else {
|
|
@@ -421,7 +457,7 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
|
421
457
|
selectTextContent($textEditor.querySelectorAll("span")[seletedNodeIndex]);
|
|
422
458
|
}
|
|
423
459
|
} else {
|
|
424
|
-
if (((
|
|
460
|
+
if (((_g = startContainer.parentElement) === null || _g === void 0 ? void 0 : _g.tagName) === "SPAN" && ((_h = endContainer.parentElement) === null || _h === void 0 ? void 0 : _h.tagName) === "SPAN") {
|
|
425
461
|
var startSpan = startContainer.parentNode;
|
|
426
462
|
var endSpan = endContainer.parentNode;
|
|
427
463
|
var allSpans = $textEditor.querySelectorAll("span");
|
package/lib/events/paste.js
CHANGED
|
@@ -1459,28 +1459,91 @@ function shouldHandleNonTableHtml(html) {
|
|
|
1459
1459
|
if (!html || /<table[\s/>]/i.test(html)) return false;
|
|
1460
1460
|
return /<[a-z]/i.test(html);
|
|
1461
1461
|
}
|
|
1462
|
-
function
|
|
1462
|
+
function convertAnyHtmlToTable(html) {
|
|
1463
1463
|
var container = document.createElement("div");
|
|
1464
1464
|
container.innerHTML = html;
|
|
1465
1465
|
var rows = [];
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1466
|
+
var currentParts = [];
|
|
1467
|
+
var BLOCK_TAGS = new Set(["P", "DIV", "SECTION", "ARTICLE", "ASIDE", "HEADER", "FOOTER", "MAIN", "NAV", "BLOCKQUOTE", "PRE", "H1", "H2", "H3", "H4", "H5", "H6", "UL", "OL", "LI", "DL", "DT", "DD", "TABLE", "THEAD", "TBODY", "TFOOT", "TR", "TD", "TH", "HR"]);
|
|
1468
|
+
var SKIP_TAGS = new Set(["SCRIPT", "STYLE", "NOSCRIPT", "META", "LINK", "HEAD", "SVG", "CANVAS", "IFRAME", "OBJECT"]);
|
|
1469
|
+
var escapeHtml = function escapeHtml(text) {
|
|
1470
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1471
|
+
};
|
|
1472
|
+
var normalizeText = function normalizeText(text) {
|
|
1473
|
+
return text.replace(/\u00A0/g, " ").replace(/\s+/g, " ");
|
|
1474
|
+
};
|
|
1475
|
+
var flushRow = function flushRow() {
|
|
1476
|
+
var htmlContent = currentParts.join("").trim();
|
|
1477
|
+
var textOnly = htmlContent.replace(/<br\s*\/?>/gi, "").replace(/ /gi, " ").replace(/\s+/g, " ").trim();
|
|
1478
|
+
if (textOnly) {
|
|
1479
|
+
rows.push("<tr><td>".concat(htmlContent, "</td></tr>"));
|
|
1470
1480
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1481
|
+
currentParts = [];
|
|
1482
|
+
};
|
|
1483
|
+
var appendText = function appendText(text) {
|
|
1484
|
+
var normalized = normalizeText(text);
|
|
1485
|
+
if (!normalized.trim()) return;
|
|
1486
|
+
var prev = currentParts[currentParts.length - 1] || "";
|
|
1487
|
+
var needsSpace = prev && !prev.endsWith(" ") && !prev.endsWith("<br>") && !/>\s*$/.test(prev);
|
|
1488
|
+
currentParts.push((needsSpace ? " " : "") + escapeHtml(normalized.trim()));
|
|
1489
|
+
};
|
|
1490
|
+
var isBlock = function isBlock(node) {
|
|
1491
|
+
return node.nodeType === Node.ELEMENT_NODE && BLOCK_TAGS.has(node.tagName);
|
|
1492
|
+
};
|
|
1493
|
+
var _walk = function walk(node) {
|
|
1494
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
1495
|
+
appendText(node.textContent || "");
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
1499
|
+
var el = node;
|
|
1500
|
+
var tag = el.tagName;
|
|
1501
|
+
if (SKIP_TAGS.has(tag)) return;
|
|
1502
|
+
if (tag === "BR" || tag === "HR") {
|
|
1503
|
+
flushRow();
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
if (tag === "TABLE") {
|
|
1507
|
+
flushRow();
|
|
1508
|
+
var trs = el.querySelectorAll(":scope > tbody > tr, :scope > thead > tr, :scope > tfoot > tr, :scope > tr");
|
|
1509
|
+
if (trs.length > 0) {
|
|
1510
|
+
trs.forEach(function (tr) {
|
|
1511
|
+
var cells = Array.from(tr.children).filter(function (child) {
|
|
1512
|
+
return /^(TD|TH)$/.test(child.tagName);
|
|
1513
|
+
});
|
|
1514
|
+
if (!cells.length) return;
|
|
1515
|
+
var rowHtml = cells.map(function (cell) {
|
|
1516
|
+
return "<td>".concat(escapeHtml((cell.textContent || "").replace(/\s+/g, " ").trim()), "</td>");
|
|
1517
|
+
}).join("");
|
|
1518
|
+
if (rowHtml.replace(/<[^>]+>/g, "").trim()) {
|
|
1519
|
+
rows.push("<tr>".concat(rowHtml, "</tr>"));
|
|
1520
|
+
}
|
|
1521
|
+
});
|
|
1522
|
+
} else {
|
|
1523
|
+
var text = (el.textContent || "").replace(/\s+/g, " ").trim();
|
|
1524
|
+
if (text) rows.push("<tr><td>".concat(escapeHtml(text), "</td></tr>"));
|
|
1477
1525
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
var block = isBlock(el);
|
|
1529
|
+
if (block && currentParts.length > 0 && tag !== "LI") {
|
|
1530
|
+
flushRow();
|
|
1531
|
+
}
|
|
1532
|
+
if (tag === "LI") {
|
|
1533
|
+
flushRow();
|
|
1534
|
+
}
|
|
1535
|
+
Array.from(el.childNodes).forEach(_walk);
|
|
1536
|
+
if (block) {
|
|
1537
|
+
flushRow();
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
Array.from(container.childNodes).forEach(_walk);
|
|
1541
|
+
flushRow();
|
|
1542
|
+
if (!rows.length) {
|
|
1543
|
+
var text = (container.textContent || "").replace(/\s+/g, " ").trim();
|
|
1544
|
+
return "<table><tr><td>".concat(escapeHtml(text), "</td></tr></table>");
|
|
1482
1545
|
}
|
|
1483
|
-
return "<table
|
|
1546
|
+
return "<table>".concat(rows.join(""), "</table>");
|
|
1484
1547
|
}
|
|
1485
1548
|
function handlePaste(ctx, e) {
|
|
1486
1549
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
|
|
@@ -1592,7 +1655,7 @@ function handlePaste(ctx, e) {
|
|
|
1592
1655
|
var shouldHandleAsHtml = /<table[\s/>]/i.test(txtdata) || shouldHandleNonTableHtml(txtdata);
|
|
1593
1656
|
if (shouldHandleAsHtml) {
|
|
1594
1657
|
var hasNativeTable = /<table[\s/>]/i.test(txtdata);
|
|
1595
|
-
var converted = hasNativeTable ? txtdata :
|
|
1658
|
+
var converted = hasNativeTable ? txtdata : convertAnyHtmlToTable(txtdata);
|
|
1596
1659
|
(0, _pasteTableHelpers.handlePastedTable)(ctx, converted, pasteHandler);
|
|
1597
1660
|
if (hasNativeTable) {
|
|
1598
1661
|
resizePastedCellsToContent(ctx);
|
package/lib/modules/cell.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare function getFontStyleByCell(cell: Cell | null | undefined, checks
|
|
|
27
27
|
export declare function getStyleByCell(ctx: Context, d: CellMatrix, r: number, c: number): any;
|
|
28
28
|
export declare function getInlineStringHTML(r: number, c: number, data: CellMatrix, options?: {
|
|
29
29
|
useSemanticMarkup?: boolean;
|
|
30
|
+
isRangeCopy?: boolean;
|
|
30
31
|
inheritedStyle?: Record<string, string>;
|
|
31
32
|
}): string;
|
|
32
33
|
export declare function getQKBorder(width: string, type: string, color: string): (string | number)[];
|
package/lib/modules/cell.js
CHANGED
|
@@ -1042,37 +1042,68 @@ function getRangeByTxt(ctx, txt) {
|
|
|
1042
1042
|
return range;
|
|
1043
1043
|
}
|
|
1044
1044
|
function isAllSelectedCellsInStatus(ctx, attr, status) {
|
|
1045
|
-
var _a, _b
|
|
1045
|
+
var _a, _b;
|
|
1046
1046
|
if (!_lodash.default.isEmpty(ctx.luckysheetCellUpdate)) {
|
|
1047
1047
|
var w = window.getSelection();
|
|
1048
1048
|
if (!w) return false;
|
|
1049
1049
|
if (w.rangeCount === 0) return false;
|
|
1050
|
-
var
|
|
1051
|
-
if (
|
|
1050
|
+
var range_1 = w.getRangeAt(0);
|
|
1051
|
+
if (range_1.collapsed === true) {
|
|
1052
1052
|
return false;
|
|
1053
1053
|
}
|
|
1054
|
-
var endContainer =
|
|
1055
|
-
var startContainer =
|
|
1056
|
-
var
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1054
|
+
var endContainer = range_1.endContainer;
|
|
1055
|
+
var startContainer = range_1.startContainer;
|
|
1056
|
+
var toElement = function toElement(n) {
|
|
1057
|
+
if (!n) return null;
|
|
1058
|
+
if (n.nodeType === Node.ELEMENT_NODE) return n;
|
|
1059
|
+
return n.parentElement;
|
|
1060
|
+
};
|
|
1061
|
+
var startEl = toElement(startContainer);
|
|
1062
|
+
var endEl = toElement(endContainer);
|
|
1063
|
+
var editorRoot = (_b = (_a = startEl === null || startEl === void 0 ? void 0 : startEl.closest("#luckysheet-rich-text-editor")) !== null && _a !== void 0 ? _a : endEl === null || endEl === void 0 ? void 0 : endEl.closest("#luckysheet-rich-text-editor")) !== null && _b !== void 0 ? _b : toElement(range_1.commonAncestorContainer);
|
|
1064
|
+
var isStyleActive_1 = function isStyleActive_1(element) {
|
|
1065
|
+
var computed = window.getComputedStyle(element);
|
|
1066
|
+
var fontWeight = (computed.fontWeight || "").toLowerCase();
|
|
1067
|
+
var fontStyle = (computed.fontStyle || "").toLowerCase();
|
|
1068
|
+
var textDecorationLine = (computed.textDecorationLine || computed.textDecoration || "").toLowerCase();
|
|
1069
|
+
var borderBottomWidth = (computed.borderBottomWidth || "").toLowerCase();
|
|
1070
|
+
if (status === 1) {
|
|
1071
|
+
if (attr === "bl") {
|
|
1072
|
+
if (fontWeight === "bold") return true;
|
|
1073
|
+
var n = Number(fontWeight);
|
|
1074
|
+
return !Number.isNaN(n) && n >= 600;
|
|
1075
|
+
}
|
|
1076
|
+
if (attr === "it") {
|
|
1077
|
+
return fontStyle === "italic" || fontStyle === "oblique";
|
|
1078
|
+
}
|
|
1079
|
+
if (attr === "cl") {
|
|
1080
|
+
return textDecorationLine.includes("line-through");
|
|
1081
|
+
}
|
|
1082
|
+
if (attr === "un") {
|
|
1083
|
+
return textDecorationLine.includes("underline") || borderBottomWidth !== "" && borderBottomWidth !== "0px" && borderBottomWidth !== "0";
|
|
1070
1084
|
}
|
|
1071
|
-
return _lodash.default.every(rangeSpans, function (s) {
|
|
1072
|
-
return !_lodash.default.isEmpty(s.style[cssField_1]);
|
|
1073
|
-
});
|
|
1074
1085
|
}
|
|
1086
|
+
return false;
|
|
1087
|
+
};
|
|
1088
|
+
var selectedElements_1 = [];
|
|
1089
|
+
if (editorRoot) {
|
|
1090
|
+
var spans = editorRoot.querySelectorAll("span");
|
|
1091
|
+
spans.forEach(function (span) {
|
|
1092
|
+
if (span.textContent && span.textContent.length > 0 && range_1.intersectsNode(span)) {
|
|
1093
|
+
selectedElements_1.push(span);
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
if (selectedElements_1.length === 0) {
|
|
1098
|
+
if (startEl) selectedElements_1.push(startEl);
|
|
1099
|
+
if (endEl && endEl !== startEl) selectedElements_1.push(endEl);
|
|
1100
|
+
}
|
|
1101
|
+
if (selectedElements_1.length === 0) {
|
|
1102
|
+
return false;
|
|
1075
1103
|
}
|
|
1104
|
+
return _lodash.default.every(selectedElements_1, function (el) {
|
|
1105
|
+
return isStyleActive_1(el);
|
|
1106
|
+
});
|
|
1076
1107
|
}
|
|
1077
1108
|
var cells = getFlattenedRange(ctx);
|
|
1078
1109
|
var flowdata = (0, _context.getFlowdata)(ctx);
|
|
@@ -1267,11 +1298,15 @@ function getInlineStringHTML(r, c, data, options) {
|
|
|
1267
1298
|
return "".concat(_lodash.default.kebabCase(key), ":").concat(_lodash.default.isNumber(v) ? "".concat(v, "px") : v, ";");
|
|
1268
1299
|
}).join(" ");
|
|
1269
1300
|
var dataAttrs = !(options === null || options === void 0 ? void 0 : options.useSemanticMarkup) && (link === null || link === void 0 ? void 0 : link.linkType) && (link === null || link === void 0 ? void 0 : link.linkAddress) ? " data-link-type='".concat(String(link.linkType).replace(/'/g, "'"), "' data-link-address='").concat(String(link.linkAddress).replace(/'/g, "'"), "'") : "";
|
|
1270
|
-
if (options === null || options === void 0 ? void 0 : options.
|
|
1271
|
-
|
|
1301
|
+
if (options === null || options === void 0 ? void 0 : options.isRangeCopy) {
|
|
1302
|
+
if (options === null || options === void 0 ? void 0 : options.useSemanticMarkup) {
|
|
1303
|
+
value += buildClipboardCompatibleInlineRuns(strObj.v, styleStr);
|
|
1304
|
+
} else {
|
|
1305
|
+
var segmentText = strObj.v.replace(/\r\n/g, "<br>").replace(/\n/g, "<br>");
|
|
1306
|
+
value += "<span class=\"luckysheet-input-span\" index='".concat(i, "' style='").concat(styleStr, "'").concat(dataAttrs, ">").concat(segmentText, "</span>");
|
|
1307
|
+
}
|
|
1272
1308
|
} else {
|
|
1273
|
-
|
|
1274
|
-
value += "<span class=\"luckysheet-input-span\" index='".concat(i, "' style='").concat(styleStr, "'").concat(dataAttrs, ">").concat(segmentText, "</span>");
|
|
1309
|
+
value += "<span class=\"luckysheet-input-span\" index='".concat(i, "' style='").concat(styleStr, "'").concat(dataAttrs, ">").concat(strObj.v, "</span>");
|
|
1275
1310
|
}
|
|
1276
1311
|
}
|
|
1277
1312
|
}
|
|
@@ -252,9 +252,12 @@ function getCssText(cssText, attr, value) {
|
|
|
252
252
|
styleObj._color = fontColor;
|
|
253
253
|
}
|
|
254
254
|
var s = (0, _cell.getFontStyleByCell)(styleObj, undefined, undefined, false);
|
|
255
|
+
cssText = removeClassWidthCss(cssText, attr);
|
|
256
|
+
if (_lodash.default.isEmpty(s)) {
|
|
257
|
+
return cssText;
|
|
258
|
+
}
|
|
255
259
|
var ukey = _lodash.default.kebabCase(Object.keys(s)[0]);
|
|
256
260
|
var uvalue = Object.values(s)[0];
|
|
257
|
-
cssText = removeClassWidthCss(cssText, attr);
|
|
258
261
|
cssText = upsetClassWithCss(cssText, ukey, uvalue);
|
|
259
262
|
return cssText;
|
|
260
263
|
}
|
|
@@ -316,16 +319,31 @@ function escapeHtmlAttr(s) {
|
|
|
316
319
|
return s.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
317
320
|
}
|
|
318
321
|
function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
319
|
-
var _a, _b, _c;
|
|
322
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
320
323
|
var w = window.getSelection();
|
|
321
324
|
if (!w) return;
|
|
322
325
|
if (w.rangeCount === 0) return;
|
|
323
326
|
var range = w.getRangeAt(0);
|
|
324
327
|
var $textEditor = cellInput;
|
|
328
|
+
var editorText = ((_b = (_a = $textEditor.innerText) !== null && _a !== void 0 ? _a : $textEditor.textContent) !== null && _b !== void 0 ? _b : "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
329
|
+
var selectedText = ((_c = range.toString()) !== null && _c !== void 0 ? _c : "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
330
|
+
if (range.collapsed === false && editorText.length > 0 && selectedText === editorText) {
|
|
331
|
+
$textEditor.innerHTML = "";
|
|
332
|
+
var wrapper = document.createElement("span");
|
|
333
|
+
wrapper.setAttribute("style", getCssText("", attr, value));
|
|
334
|
+
wrapper.textContent = editorText;
|
|
335
|
+
$textEditor.appendChild(wrapper);
|
|
336
|
+
var newRange = document.createRange();
|
|
337
|
+
newRange.selectNodeContents($textEditor);
|
|
338
|
+
w.removeAllRanges();
|
|
339
|
+
w.addRange(newRange);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
325
342
|
if (range.startContainer === $textEditor && range.endContainer === $textEditor && range.collapsed === false) {
|
|
326
343
|
var start = range.startOffset;
|
|
327
344
|
var end = range.endOffset;
|
|
328
345
|
var children = Array.from($textEditor.childNodes).slice(start, end);
|
|
346
|
+
var hasUnsupportedElementSelection_1 = false;
|
|
329
347
|
children.forEach(function (node) {
|
|
330
348
|
var _a, _b;
|
|
331
349
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
@@ -333,6 +351,16 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
|
333
351
|
if (el.tagName === "SPAN") {
|
|
334
352
|
var cssText = getCssText(el.style.cssText, attr, value);
|
|
335
353
|
el.setAttribute("style", cssText);
|
|
354
|
+
} else {
|
|
355
|
+
var nestedSpans = el.querySelectorAll("span");
|
|
356
|
+
if (nestedSpans.length > 0) {
|
|
357
|
+
nestedSpans.forEach(function (nestedSpan) {
|
|
358
|
+
var cssText = getCssText(nestedSpan.style.cssText, attr, value);
|
|
359
|
+
nestedSpan.setAttribute("style", cssText);
|
|
360
|
+
});
|
|
361
|
+
} else {
|
|
362
|
+
hasUnsupportedElementSelection_1 = true;
|
|
363
|
+
}
|
|
336
364
|
}
|
|
337
365
|
} else if (node.nodeType === Node.TEXT_NODE) {
|
|
338
366
|
var text = (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
|
|
@@ -344,6 +372,14 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
|
344
372
|
(_b = node.parentNode) === null || _b === void 0 ? void 0 : _b.replaceChild(wrapper, node);
|
|
345
373
|
}
|
|
346
374
|
});
|
|
375
|
+
if (hasUnsupportedElementSelection_1) {
|
|
376
|
+
var fullText = (_e = (_d = $textEditor.innerText) !== null && _d !== void 0 ? _d : $textEditor.textContent) !== null && _e !== void 0 ? _e : "";
|
|
377
|
+
$textEditor.innerHTML = "";
|
|
378
|
+
var wrapper = document.createElement("span");
|
|
379
|
+
wrapper.setAttribute("style", getCssText("", attr, value));
|
|
380
|
+
wrapper.textContent = fullText;
|
|
381
|
+
$textEditor.appendChild(wrapper);
|
|
382
|
+
}
|
|
347
383
|
var newRange = document.createRange();
|
|
348
384
|
newRange.selectNodeContents($textEditor);
|
|
349
385
|
w.removeAllRanges();
|
|
@@ -421,7 +457,7 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
|
421
457
|
}
|
|
422
458
|
cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(right, "</span>");
|
|
423
459
|
}
|
|
424
|
-
if (((
|
|
460
|
+
if (((_f = startContainer.parentElement) === null || _f === void 0 ? void 0 : _f.tagName) === "SPAN") {
|
|
425
461
|
spanIndex = _lodash.default.indexOf($textEditor.querySelectorAll("span"), span);
|
|
426
462
|
span.outerHTML = cont;
|
|
427
463
|
} else {
|
|
@@ -437,7 +473,7 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
|
437
473
|
(0, _cursor.selectTextContent)($textEditor.querySelectorAll("span")[seletedNodeIndex]);
|
|
438
474
|
}
|
|
439
475
|
} else {
|
|
440
|
-
if (((
|
|
476
|
+
if (((_g = startContainer.parentElement) === null || _g === void 0 ? void 0 : _g.tagName) === "SPAN" && ((_h = endContainer.parentElement) === null || _h === void 0 ? void 0 : _h.tagName) === "SPAN") {
|
|
441
477
|
var startSpan = startContainer.parentNode;
|
|
442
478
|
var endSpan = endContainer.parentNode;
|
|
443
479
|
var allSpans = $textEditor.querySelectorAll("span");
|